Resource:OnElementSpawn: Difference between revisions
Jump to navigation
Jump to search
Godpolice13 (talk | contribs) No edit summary |
Godpolice13 (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<pageclass class="resource" subcaption="Resource"></pageclass> | <pageclass class="resource" subcaption="Resource"></pageclass> | ||
This Serverside Script adds the function: | This Serverside Script adds the function: onElementSpawn. | ||
'''Download can be found at the''' [https://community.multitheftauto.com/index.php?p=resources&s=details&id=18374 MTA community page]'''.''' | '''Download can be found at the''' [https://community.multitheftauto.com/index.php?p=resources&s=details&id=18374 MTA community page]'''.''' | ||
Line 12: | Line 12: | ||
addEventHandler("onClientElementStreamIn", root, function() | addEventHandler("onClientElementStreamIn", root, function() | ||
if getElementType(source) == "vehicle" then | if getElementType(source) == "vehicle" then | ||
triggerServerEvent(" | triggerServerEvent("onElementSpawnCheck", localPlayer, source) | ||
end | end | ||
end) | end) | ||
Line 19: | Line 19: | ||
<section name="Serverside Script" class="server" show="true"> | <section name="Serverside Script" class="server" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addEvent(" | addEvent("onElementSpawn", true) | ||
function | function onElementSpawnCheck(element) | ||
triggerEvent(" | triggerEvent("onElementSpawn", element) | ||
end | end | ||
addEvent(" | addEvent("onElementSpawnCheck", true) | ||
addEventHandler(" | addEventHandler("onElementSpawnCheck", root, onElementSpawnCheck) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
Line 34: | Line 34: | ||
local Vehicle = createVehicle(411, 100, 100, 100) | local Vehicle = createVehicle(411, 100, 100, 100) | ||
addEventHandler(" | addEventHandler("onElementSpawn", root, function() | ||
setElementPosition(source, 0, 0, 3) | if getElementType(source) == "vehicle" then | ||
setElementPosition(source, 0, 0, 3) | |||
end | |||
end) | end) | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 16:38, 9 January 2021
This Serverside Script adds the function: onElementSpawn.
Download can be found at the MTA community page.
Source
The source of this event is the vehicle that spawned.
Code
Click to collapse [-]
Clientside ScriptaddEventHandler("onClientElementStreamIn", root, function() if getElementType(source) == "vehicle" then triggerServerEvent("onElementSpawnCheck", localPlayer, source) end end)
Click to collapse [-]
Serverside ScriptaddEvent("onElementSpawn", true) function onElementSpawnCheck(element) triggerEvent("onElementSpawn", element) end addEvent("onElementSpawnCheck", true) addEventHandler("onElementSpawnCheck", root, onElementSpawnCheck)
Example Code
Click to collapse [-]
Serverside Examplelocal Vehicle = createVehicle(411, 100, 100, 100) addEventHandler("onElementSpawn", root, function() if getElementType(source) == "vehicle" then setElementPosition(source, 0, 0, 3) end end)
Author: Godpolice13
See Also
Vehicle events
- onTrailerAttach
- onTrailerDetach
- onVehicleDamage
- onVehicleEnter
- onVehicleExit
- onVehicleExplode
- onVehicleRespawn
- onVehicleStartEnter
- onVehicleStartExit
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled