Resource:OnElementSpawn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 41: Line 41:
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
<!DOCTYPE html>
<html>
<body>


<iframe width="420" height="345" src="https://youtube.com/y4tGcI_FUfE">
<iframe width="420" height="345" src="https://youtube.com/y4tGcI_FUfE">
</iframe/>
</iframe>
 
</body>
</html>


'''Author: Godpolice13'''
'''Author: Godpolice13'''


{{See also/Server event|Element events}}
{{See also/Server event|Element events}}

Revision as of 22:35, 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 Script
addEventHandler("onClientElementStreamIn", root, function()
	if getElementType(source) == "vehicle" then
		triggerServerEvent("onElementSpawnCheck", localPlayer, source)
	end
end)
Click to collapse [-]
Serverside Script
addEvent("onElementSpawn", true)

function onElementSpawnCheck(element)
	triggerEvent("onElementSpawn", element)
end
addEvent("onElementSpawnCheck", true)
addEventHandler("onElementSpawnCheck", root, onElementSpawnCheck)

Example Code

Click to collapse [-]
Serverside Example
local Vehicle = createVehicle(411, 100, 100, 100)

addEventHandler("onElementSpawn", root, function()
	if getElementType(source) == "vehicle" then
		setElementPosition(source, 0, 0, 3)
	end
end)

<!DOCTYPE html> <html> <body>

<iframe width="420" height="345" src="https://youtube.com/y4tGcI_FUfE"> </iframe>

</body> </html>

Author: Godpolice13

See Also

Element events


Event functions