OnVehicleDamage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(13 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[[Category:Incomplete Event]]
__NOTOC__  
__NOTOC__  
This event is triggered when a vehicle encounters damage.
{{Server event}}
This event is triggered when a vehicle is damaged. If you want to get the attacker you can use [[onClientVehicleDamage]].


==Syntax==  
==Parameters==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onVehicleDamage ( float loss )
float loss
</syntaxhighlight>  
</syntaxhighlight>  
*'''loss''': a [[float]] representing the amount of health the [[vehicle]] lost.
==Source==
The [[event system#Event source|source]] of this event is the [[vehicle]] that got damaged.


==Example==  
==Example==  
This example does...
This example displays a message with the amount of health lost when a vehicle gets damaged.  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function displayVehicleLoss(loss)
blabhalbalhb --abababa
    local thePlayer = getVehicleOccupant(source)
--This line does this...
    if(thePlayer) then -- Check there is a player in the vehicle
mooo
        outputChatBox("Your vehicle just lost " .. tonumber(loss) .. " health.", thePlayer) -- Display the message
    end
end
 
addEventHandler("onVehicleDamage", root, displayVehicleLoss)
</syntaxhighlight>
</syntaxhighlight>
{{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
  • loss: a float representing the amount of health the vehicle lost.

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


Event functions