OnVehicleExplode: Difference between revisions
Jump to navigation
Jump to search
(8 intermediate revisions by 6 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 | No parameters. | ||
==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 31: | ||
--Add the resource start event | --Add the resource start event | ||
addEventHandler ( "onResourceStart", | addEventHandler ( "onResourceStart", resourceRoot, onThisResourceStart ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''Example 2:''' This will show the name of any vehicle that blew up: | |||
This will show name of any vehicle that blew up | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function notifyAboutExplosion() | 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 | end | ||
-- by using | -- by using root, it will work for any vehicle (even if it wasn't created via this resource) | ||
addEventHandler("onVehicleExplode", | addEventHandler("onVehicleExplode", root, notifyAboutExplosion) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{See also/Server event|Vehicle events}} | {{See also/Server event|Vehicle events}} |
Latest revision as of 17:17, 21 November 2023
This event is triggered when a vehicle explodes.
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
- onTrailerAttach
- onTrailerDetach
- onVehicleDamage
- onVehicleEnter
- onVehicleExit
- onVehicleExplode
- onVehicleRespawn
- onVehicleStartEnter
- onVehicleStartExit
Event functions
Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled