ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. setPedDamageProof

Function

setPedDamageProof

Server and clientPedsTrilogy Hub only

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).
enabledbool
true = 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