onClientObjectDamage
ClientEventCancellable
Fired on this client before an object takes damage. Cancelling the event prevents the damage.
addEventHandler("onClientObjectDamage", root, function(float loss, element|nil attacker) … end)
Handler parameters
| Name | Type | Description |
|---|---|---|
| loss | float | The health the object will lose, already multiplied by its model's colDamageMult. It can be more than the health it has. |
| attacker | element|nil | The player, ped, vehicle or object that caused the damage, or nil if there is none (as with breakObject). |
Source
The object about to take the damage.
Only objects created by scripts have this event: the map's own objects are not elements. Any damage counts, whether a shot, a collision, an explosion or breakObject.
Each client works out the damage on its own, so cancelling applies to this client alone. In the handler, breakObject on an object that breakObject is already breaking returns false, and destroying the object with destroyElement is safe.
Example
addEventHandler("onClientObjectDamage", root, function(loss, attacker)
if attacker == localPlayer then
cancelEvent()
end
end)