OnElementStartSync: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
Dutchman101 (talk | contribs) mNo edit summary |
||
(9 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server event}} | {{Server event}} | ||
This event is triggered when an element becomes synced by a player. | This event is triggered when an element becomes synced by a player. | ||
Line 9: | Line 8: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
*'''newSyncer''': [[player]] element representing the player who is now syncing the element | *'''newSyncer''': a [[player]] element representing the player who is now syncing the [[element]]. | ||
==Source== | ==Source== | ||
Line 15: | Line 14: | ||
==Example== | ==Example== | ||
<section name="Server" class="server" show="true"> | |||
This example matches the model of the element to the player, when an element receives a new syncer. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function elementStartSync( newSyncer ) | |||
local strElementType = getElementType( source ) | |||
local playerVehicle = getPedOccupiedVehicle( newSyncer ) | |||
if ( strElementType == 'vehicle' ) then | |||
if ( not playerVehicle ) then return false end | |||
setElementModel( source, getElementModel(playerVehicle) ) | |||
elseif ( strElementType == 'ped' ) then | |||
setElementModel( source, getElementModel(newSyncer) ) | |||
end | |||
end | |||
addEventHandler ('onElementStartSync', root, elementStartSync) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
This example will prevent vehicles from entering a certain area by destroying them upon entrance | |||
<syntaxhighlight lang="lua"> | |||
local myColShape = createColCuboid(1000, -800, 900, 1000, 1000, 1000) | |||
function checkSyncOfVehicles() | |||
if isElement(source) and getElementType (source) == "vehicle" and isElementWithinColShape(source, myColShape) then | |||
destroyElement (source) | |||
end | |||
end | |||
addEventHandler ("onElementStartSync", root, checkSyncOfVehicles) | |||
</syntaxhighlight> | |||
</section> | |||
{{See also/Server event|Element events}} | {{See also/Server event|Element events}} |
Latest revision as of 02:13, 3 December 2018
This event is triggered when an element becomes synced by a player.
Parameters
player newSyncer
Source
The source of this event is the element that got synced by a player.
Example
Click to collapse [-]
ServerThis example matches the model of the element to the player, when an element receives a new syncer.
function elementStartSync( newSyncer ) local strElementType = getElementType( source ) local playerVehicle = getPedOccupiedVehicle( newSyncer ) if ( strElementType == 'vehicle' ) then if ( not playerVehicle ) then return false end setElementModel( source, getElementModel(playerVehicle) ) elseif ( strElementType == 'ped' ) then setElementModel( source, getElementModel(newSyncer) ) end end addEventHandler ('onElementStartSync', root, elementStartSync)
This example will prevent vehicles from entering a certain area by destroying them upon entrance
local myColShape = createColCuboid(1000, -800, 900, 1000, 1000, 1000) function checkSyncOfVehicles() if isElement(source) and getElementType (source) == "vehicle" and isElementWithinColShape(source, myColShape) then destroyElement (source) end end addEventHandler ("onElementStartSync", root, checkSyncOfVehicles)
See Also
Element events
- onElementClicked
- onElementColShapeHit
- onElementColShapeLeave
- onElementDataChange
- onElementDestroy
- onElementDimensionChange
- onElementInteriorChange
- onElementModelChange
- onElementStartSync
- onElementStopSync
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled