ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Server events
  3. onPlayerDamage

Event

onPlayerDamage

ServerPlayersIdentical to MTA:SA

A player took damage: from a weapon, a fall, a vehicle or an explosion. For a grenade or rocket explosion attacker is the player who caused it.

Handler

addEventHandler("onPlayerDamage", root, function(attacker, damageCauseID, bodypart, loss) ... end)

Parameters

attackerelement
The attacker (a player, a vehicle) or false.
damageCauseIDint
Weapon or damage cause.
bodypartint
Body part 3-9 (getBodyPartName).
lossfloat
Health lost.

Source

source is the player who took damage.

Example

A headshot kills instantly.

addEventHandler("onPlayerDamage", root, function(attacker, weapon, bodypart)
    if bodypart == 9 and attacker and getElementType(attacker) == "player" then
        killPed(source, attacker, weapon, bodypart)
    end
end)

Notes

Blocking. The event arrives BEFORE damage is applied: cancelEvent() blocks a hit from a player, a knife from behind and game damage (health comes back on the player). Permanent protection: setPedDamageProof.

See also