onVehicleDamage | Multi Theft Auto: Wiki Skip to content

onVehicleDamage

Client-side
Server-side
Shared

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

element: The source of this event is the vehicle that got damaged.

Code Examples

server

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 Functions