- Documentation
- Client events
- onClientPedDamage
Event
onClientPedDamage
An NPC took damage in your game (e.g. from your weapon) before the hit goes to the server. cancelEvent() blocks the hit: it is not sent to the server and the NPC's health returns to the server value.
Handler
addEventHandler("onClientPedDamage", root, function(attacker, weapon, bodypart, loss) ... end)Parameters
attackerelement- The player or NPC who hit, or
false. weaponint- The weapon the attacker holds (
falsewhen unknown). bodypartint- Body part (3-9).
lossfloat- Health lost (0-100).
Source
source is the NPC that was hit.
Example
A no-combat zone for bots.
addEventHandler("onClientPedDamage", root, function(attacker, weapon, bodypart, loss)
if getElementData(source, "safe") then cancelEvent() end
end)
See also
onClientPlayerDamageYour own ped took damage: a hit from another player or game damage (fall, fire, explosion, car, drowning). Informational - the server decides about damage, socancelEvent()blocks nothing here; to block damage usecancelEvent()in the server'sonPlayerDamageandsetPedDamageProof.onPlayerDamageA player took damage: from a weapon, a fall, a vehicle or an explosion. For a grenade or rocket explosionattackeris the player who caused it.setPedDamageProofMakes a player or an NPC damage proof (or removes it). A player takes no damage from other players (shots, hits, a knife from behind) or from the game (falls, fire, explosions, cars); game damage is undone and health comes back on the player at once. An NPC takes no damage in any game, and the server rejects hits on it. Everyone sees the state (isPedDamageProofon both sides). On the client side it works only on NPCs and only for this player.