OnVehicleDamage: Difference between revisions
Jump to navigation
Jump to search
King Hjwalh (talk | contribs) |
No edit summary |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server event}} | {{Server event}} | ||
This event is triggered when a vehicle is damaged. | This event is triggered when a vehicle is damaged. If you want to get the attacker you can use [[onClientVehicleDamage]]. | ||
==Parameters== | ==Parameters== | ||
Line 8: | Line 8: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
*'''loss''': | *'''loss''': a [[float]] representing the amount of health the [[vehicle]] lost. | ||
==Source== | ==Source== | ||
Line 19: | Line 19: | ||
local thePlayer = getVehicleOccupant(source) | local thePlayer = getVehicleOccupant(source) | ||
if(thePlayer) then -- Check there is a player in the vehicle | if(thePlayer) then -- Check there is a player in the vehicle | ||
outputChatBox("Your vehicle just lost " .. tonumber(loss) .. " | outputChatBox("Your vehicle just lost " .. tonumber(loss) .. " health.", thePlayer) -- Display the message | ||
end | end | ||
end | end | ||
addEventHandler("onVehicleDamage", | addEventHandler("onVehicleDamage", root, displayVehicleLoss) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{See also/Server event|Vehicle events}} | {{See also/Server event|Vehicle events}} |
Latest revision as of 03:05, 27 September 2018
This event is triggered when a vehicle is damaged. If you want to get the attacker you can use onClientVehicleDamage.
Parameters
float loss
Source
The source of this event is the vehicle that got damaged.
Example
This example displays a message with the amount of health lost when a vehicle gets damaged.
function displayVehicleLoss(loss) local thePlayer = getVehicleOccupant(source) if(thePlayer) then -- Check there is a player in the vehicle outputChatBox("Your vehicle just lost " .. tonumber(loss) .. " health.", thePlayer) -- Display the message end end addEventHandler("onVehicleDamage", root, displayVehicleLoss)
See Also
Vehicle events
- onTrailerAttach
- onTrailerDetach
- onVehicleDamage
- onVehicleEnter
- onVehicleExit
- onVehicleExplode
- onVehicleRespawn
- onVehicleStartEnter
- onVehicleStartExit
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled