SetElementSyncer: Difference between revisions
m (fix oop syntax) |
m (→See Also) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
Only [[vehicle]] and [[ped]] elements can have a syncer, other element types are not currently automatically synced by MTA. | Only [[vehicle]] and [[ped]] elements can have a syncer, other element types are not currently automatically synced by MTA. | ||
Please note that using this function to change an element's syncer will only last as long as the element is within syncable range of the player. This is within 140 units for vehicles and 100 units for peds. As soon as it becomes impossible for your chosen player to sync the element, another player (or no player) will be automatically selected, and your setting will be lost. With vehicles, the last occupant to leave a vehicle will be selected as the syncer and override any setting you may have made. | Please note that using this function to change an element's syncer will only last as long as the element is within syncable range of the player unless persist is set to true. This is within 140 units for vehicles and 100 units for peds. As soon as it becomes impossible for your chosen player to sync the element, another player (or no player) will be automatically selected, and your setting will be lost. With vehicles, the last occupant to leave a vehicle will be selected as the syncer and override any setting you may have made. | ||
Using this function to remove an element's syncer, means no player will be assigned to syncing the element. That will not be changed until setElementSyncer is called again. | Using this function to remove an element's syncer, means no player will be assigned to syncing the element. That will not be changed until setElementSyncer is called again. | ||
Line 12: | Line 12: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool setElementSyncer ( element theElement, player thePlayer ) | bool setElementSyncer ( element theElement, player thePlayer[, bool persist=false ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[element]]:setSyncer||}} | {{OOP||[[element]]:setSyncer|syncer|getElementSyncer}} | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theElement:''' The [[element]] whose syncer you wish to change. | *'''theElement:''' The [[element]] whose syncer you wish to change. | ||
*'''thePlayer:''' The [[player]] who should be the new syncer of the element. If set to ''false'', this element will not have a syncer. If set to ''true'', MTA will pick automatically the nearest or most relevant player to that element. | *'''thePlayer:''' The [[player]] who should be the new syncer of the element. If set to ''false'', this element will not have a syncer. If set to ''true'', MTA will pick automatically the nearest or most relevant player to that element. | ||
===Optional Arguments=== | |||
*'''persist:''' If ''true'', the server will not automatically change the syncer. If set to ''false'', default syncer behavior resumes. | |||
===Returns=== | ===Returns=== | ||
Line 34: | Line 37: | ||
==See Also== | ==See Also== | ||
{{Element_functions}} | {{Element_functions|server}} |
Latest revision as of 22:32, 6 September 2024
This function can be used to change the syncer (player) of an element. The syncer is the player who is responsible for informing the server about the state of that element - it's position, orientation and other state information. The function can be also used to remove an element's syncer.
Only vehicle and ped elements can have a syncer, other element types are not currently automatically synced by MTA.
Please note that using this function to change an element's syncer will only last as long as the element is within syncable range of the player unless persist is set to true. This is within 140 units for vehicles and 100 units for peds. As soon as it becomes impossible for your chosen player to sync the element, another player (or no player) will be automatically selected, and your setting will be lost. With vehicles, the last occupant to leave a vehicle will be selected as the syncer and override any setting you may have made.
Using this function to remove an element's syncer, means no player will be assigned to syncing the element. That will not be changed until setElementSyncer is called again. It should also be noted that certain network changes to an element do not require a syncer. Actions such as destroying an element or explicitly setting the element's position (in a server side script), will still be updated on all clients regardless of this setting.
Syntax
bool setElementSyncer ( element theElement, player thePlayer[, bool persist=false ] )
OOP Syntax Help! I don't understand this!
- Method: element:setSyncer(...)
- Variable: .syncer
- Counterpart: getElementSyncer
Required Arguments
- theElement: The element whose syncer you wish to change.
- thePlayer: The player who should be the new syncer of the element. If set to false, this element will not have a syncer. If set to true, MTA will pick automatically the nearest or most relevant player to that element.
Optional Arguments
- persist: If true, the server will not automatically change the syncer. If set to false, default syncer behavior resumes.
Returns
Returns true if the syncer was changed successfully, false if the element passed was not a ped or vehicle.
Example
addCommandHandler ( "createMyVehicle", function ( player, command ) local x, y, z = getElementPosition ( player ) local myVehicle = createVehicle ( 411, x, y, z ) setElementSyncer ( myVehicle, player ) end )
See Also
- addElementDataSubscriber
- clearElementVisibleTo
- cloneElement
- getElementSyncer
- getElementZoneName
- hasElementDataSubscriber
- isElementVisibleTo
- removeElementData
- removeElementDataSubscriber
- setElementSyncer
- setElementVisibleTo
- Shared
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement