OnVehicleExplode: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (player argument)
 
(13 intermediate revisions by 10 users not shown)
Line 2: Line 2:
{{Server event}}
{{Server event}}
This event is triggered when a vehicle explodes.
This event is triggered when a vehicle explodes.
{{Note|This event can not be canceled.}}


==Parameters==
==Parameters==
No arguments
<syntaxhighlight lang="lua">
bool withExplosion, player player
</syntaxhighlight>
*'''withExplosion:''' Determines whether the vehicle was blown with or without an explosion.
{{New feature/item|3.0161|1.6.0|22680|
*'''player:''' The player who sent the explosion packet.
}}


==Source==
==Source==
The [[event system#Event source|source]] of this event is the [[vehicle]] that exploded.
The [[event system#Event source|source]] of this event is the [[vehicle]] that exploded.


==Example==  
==Example==
'''Example 1'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
vagosVehicle = nil
local vagosVehicle = nil


-- This will get called when the vagos vehicle explodes
-- This will get called when the vagos vehicle explodes
Line 29: Line 37:


--Add the resource start event
--Add the resource start event
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), onThisResourceStart )
addEventHandler ( "onResourceStart", resourceRoot, onThisResourceStart )
</syntaxhighlight>
 
'''Example 2:''' This will show the name of any vehicle that blew up:
<syntaxhighlight lang="lua">
function notifyAboutExplosion()
    -- source is the element that triggered the event and can be used in other events as well
    outputChatBox(getVehicleName(source) .. " just blew up")
end
 
-- by using root, it will work for any vehicle (even if it wasn't created via this resource)
addEventHandler("onVehicleExplode", root, notifyAboutExplosion)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
{{See also/Server event|Vehicle events}}
{{Event_functions}}

Latest revision as of 19:20, 18 August 2024

This event is triggered when a vehicle explodes.

[[{{{image}}}|link=|]] Note: This event can not be canceled.

Parameters

bool withExplosion, player player
  • withExplosion: Determines whether the vehicle was blown with or without an explosion.
ADDED/UPDATED IN VERSION 1.6.0 r22680:
  • player: The player who sent the explosion packet.

Source

The source of this event is the vehicle that exploded.

Example

Example 1

local vagosVehicle = nil

-- This will get called when the vagos vehicle explodes
function onVagosVehicleExplode ()
	outputChatBox ( "VAGOS VEHICLE DESTROYED!" )
end

-- This is called when THIS resource starts
function onThisResourceStart ()

	-- Create the vagos vehicle. A van.
	vagosVehicle = createVehicle ( 522, 0, 0, 5 )

	-- Add its explode handler. When this car explodes, onVagosVehicleExplode is called
	addEventHandler ( "onVehicleExplode", vagosVehicle, onVagosVehicleExplode )
end

--Add the resource start event
addEventHandler ( "onResourceStart", resourceRoot, onThisResourceStart )

Example 2: This will show the name of any vehicle that blew up:

function notifyAboutExplosion()
    -- source is the element that triggered the event and can be used in other events as well
    outputChatBox(getVehicleName(source) .. " just blew up")
end

-- by using root, it will work for any vehicle (even if it wasn't created via this resource)
addEventHandler("onVehicleExplode", root, notifyAboutExplosion)

See Also

Vehicle events


Event functions