Resource:OnElementSpawn: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 2: Line 2:
This Serverside Script adds the function: onElementSpawn.
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=18375 MTA community page]'''.'''


==Source==
==Source==
The source of this event is the vehicle that spawned.
The source of this event is the element that spawned.


==Code==
==Code==
Line 42: Line 42:
</section>
</section>


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


{{See also/Server event|Vehicle events}}
{{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 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)

Author: David13Systems

See Also

Element events


Event functions