OnVehicleExplode: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(14 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
{{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.}}


==Syntax==  
==Parameters==
No parameters.
 
==Source==
The [[event system#Event source|source]] of this event is the [[vehicle]] that exploded.
 
==Example==
'''Example 1'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onVehicleExplode ()  
local vagosVehicle = nil
</syntaxhighlight>  
 
-- 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 )
</syntaxhighlight>


==Example==
'''Example 2:''' This will show the name of any vehicle that blew up:
This example tells the players when a vehicle explodes
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onVehicleExplode () --The function in which when a vehicle explodes
function notifyAboutExplosion()
local VagosVehicleHealth = getVehicleHealth ( VagosVehicle ) --Gets the HP of the Vagos' vehicle
    -- source is the element that triggered the event and can be used in other events as well
    outputChatBox(getVehicleName(source) .. " just blew up")
if ( VagosVehicleHealth == 0 ) then --If the vehicle's health is "0" (exploded)
showTextForAll ( 3000, 0, 10, 125, 1.5, " VAGOS' LOAD HAS EXPLODED!" ) --shows the text
end
end
addEventHandler ( "onVehicleExplode", root, onVehicleExplode ) --Event is triggered
 
-- 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/Server event|Vehicle events}}

Latest revision as of 17:17, 21 November 2023

This event is triggered when a vehicle explodes.

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

Parameters

No parameters.

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