Resource:OnElementSpawn: Difference between revisions
Jump to navigation
Jump to search
Godpolice13 (talk | contribs) (Godpolice13 moved page Category:OnVehicleSpawn to OnVehicleSpawn) Tag: New redirect |
Godpolice13 (talk | contribs) |
||
| (16 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
<pageclass class="resource" subcaption="Resource"></pageclass> | |||
This Serverside Script adds the function: onElementSpawn. | |||
'''Download can be found at the''' [https://community.multitheftauto.com/index.php?p=resources&s=details&id=18375 MTA community page]'''.''' | |||
==Source== | |||
The source of this event is the element that spawned. | |||
==Code== | |||
<section name="Clientside Script" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
addEventHandler("onClientElementStreamIn", root, function() | |||
if getElementType(source) == "vehicle" then | |||
triggerServerEvent("onElementSpawnCheck", localPlayer, source) | |||
end | |||
end) | |||
</syntaxhighlight> | |||
</section> | |||
<section name="Serverside Script" class="server" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
addEvent("onElementSpawn", true) | |||
function onElementSpawnCheck(element) | |||
triggerEvent("onElementSpawn", element) | |||
end | |||
addEvent("onElementSpawnCheck", true) | |||
addEventHandler("onElementSpawnCheck", root, onElementSpawnCheck) | |||
</syntaxhighlight> | |||
</section> | |||
==Example Code== | |||
<section name="Serverside Example" class="server" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
local Vehicle = createVehicle(411, 100, 100, 100) | |||
addEventHandler("onElementSpawn", root, function() | |||
if getElementType(source) == "vehicle" then | |||
setElementPosition(source, 0, 0, 3) | |||
end | |||
end) | |||
</syntaxhighlight> | |||
</section> | |||
'''Author: David13Systems''' | |||
{{See also/Server event|Element events}} | |||
Latest revision as of 22:44, 25 November 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 element 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: David13Systems
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