OnVehicleDamage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Added a gateway to onClientVehicleDamage so players can see a way to get the vehicle attacker.)
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 wan't to get the attacker you can use [[onClientVehicleDamage]].


==Parameters==  
==Parameters==  
Line 23: Line 23:
end
end


addEventHandler("onVehicleDamage", getRootElement(), displayVehicleLoss)
addEventHandler("onVehicleDamage", root, displayVehicleLoss)
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 23:58, 26 April 2018

This event is triggered when a vehicle is damaged. If you wan't 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