OnVehicleExplode: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (See Also for server events)
Line 30: Line 30:
--Add the resource start event
--Add the resource start event
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), onThisResourceStart )
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), onThisResourceStart )
</syntaxhighlight>
==Example 2==
This will show 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))
end
-- by using getRootElement() as root, it works for any vehicle
addEventHandler("onVehicleExplode", getRootElement(), notifyAboutExplosion)
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 08:40, 22 November 2009

This event is triggered when a vehicle explodes.

Parameters

No arguments

Source

The source of this event is the vehicle that exploded.

Example

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", getResourceRootElement ( getThisResource () ), onThisResourceStart )

Example 2

This will show 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))
end

-- by using getRootElement() as root, it works for any vehicle
addEventHandler("onVehicleExplode", getRootElement(), notifyAboutExplosion)

See Also

Vehicle events


Event functions