OnClientElementDestroy: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(The fact that this event triggers on source's parents does not make any sense. I guess it wanted to say "children")
(Replace to predefined variables.)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Client event}}
{{Client event}}
__NOTOC__  
__NOTOC__  
This event is triggered when an element gets destroyed by [[destroyElement]] or when the creator resource is stopping. It is also triggered when a children element of this element is destroyed.
This event is triggered when an element gets destroyed by [[destroyElement]] or when the creator resource is stopping. It is also triggered when a children element of this element is destroyed. It is not triggered on a player when they quit.


==Parameters==
==Parameters==
''None''
No parameters.


==Source==
==Source==
Line 12: Line 12:
This example prints a message in the chat box when the vehicle that you are in gets destroyed.
This example prints a message in the chat box when the vehicle that you are in gets destroyed.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler("onClientElementDestroy", getRootElement(), function ()
addEventHandler("onClientElementDestroy", root, function()
if getElementType(source) == "vehicle" and getPedOccupiedVehicle(getLocalPlayer()) == source then
if getElementType(source) == "vehicle" and getPedOccupiedVehicle(localPlayer) == source then
outputChatBox("The vehicle that you were in has been destroyed by the script")
outputChatBox("The vehicle that you were in has been destroyed by the script")
end
end

Latest revision as of 08:59, 8 June 2024

This event is triggered when an element gets destroyed by destroyElement or when the creator resource is stopping. It is also triggered when a children element of this element is destroyed. It is not triggered on a player when they quit.

Parameters

No parameters.

Source

The source of this event is the element that is being destroyed.

Example

This example prints a message in the chat box when the vehicle that you are in gets destroyed.

addEventHandler("onClientElementDestroy", root, function()
	if getElementType(source) == "vehicle" and getPedOccupiedVehicle(localPlayer) == source then
		outputChatBox("The vehicle that you were in has been destroyed by the script")
	end
end)

See Also

Client element events


Client event functions