- Documentation
- Shared functions
- setPedDamageProof
Function
setPedDamageProof
Makes 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 (isPedDamageProof on both sides). On the client side it works only on NPCs and only for this player.
Syntax
Server
bool setPedDamageProof(ped thePed, bool enabled)Client
bool setPedDamageProof(ped thePed, bool enabled)Arguments
thePedped- A player or an NPC (only an NPC on the client).
enabledbooltrue= damage proof.
Returns
true on success.
Example
Spawn protection for 5 seconds.
addEventHandler("onPlayerSpawn", root, function()
local player = source
setPedDamageProof(player, true)
setTimer(function()
if isElement(player) then setPedDamageProof(player, false) end
end, 5000, 1)
end)
Notes
To block single hits: cancelEvent() in onPlayerDamage (NPCs: onClientPedDamage). setElementHealth and killPed from scripts still work, also on a damage proof NPC.
See also
isPedDamageProofChecks whether a player or an NPC is damage proof (setPedDamageProof).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.setElementHealthSets an element's health.0kills a player or ped and firesonPlayerWasted/onPedWasted.