Skip to content

setPedOnlyDamagedByPlayer

Client-side

Make a script-created NPC ignore GTA damage events whose attacker is not a player, while still allowing attacks attributed to a player. This matches the story-script rule used for actors who should be hurt by the player but not by other NPCs.

Syntax

bool setPedOnlyDamagedByPlayer(ped thePed, bool onlyDamagedByPlayer)

GTA task mapping

NATIVE GTA BEHAVIOR 02A9
No CTask is created

SCM equivalent: SET_CHAR_ONLY_DAMAGED_BY_PLAYER

This creates no CTask. It persists GTA's bInvulnerable-backed story flag; GTA's damage event path rejects non-player attackers while retaining player-attributed damage.

Arguments

thePedped

Script-created ped; players are rejected.

onlyDamagedByPlayerbool

Whether GTA should reject damage events not attributed to a player.

Returns

true when the client-local policy was stored; false for a player or invalid element.

Ownership and lifecycle

Low-level ped task calls require the client that simulates the living, streamed ped. Driving tasks also require control of the streamed vehicle. They do not create lifecycle handles; the optional native-task-runtime adds server-owned route epochs and reconstruction for drive_to routes. Gang-tag ownership is resource-exclusive, survives object streaming and recreation, and is released automatically when the owner stops.

Important behavior
  • The value may be set while the native ped is streamed out and is reapplied after GTA recreates it.
  • This scalar policy takes precedence over the matching flag inside setPedStoryProtected regardless of call order.
  • This is GTA's attacker-based damage rule, not blanket protection from every damage source. Use the separate physical-proof APIs when bullets, fire, explosions, collisions, or melee need explicit protection.
  • It is client-local and last-writer-wins, not resource-owned. Synchronized resources must apply it on the relevant clients and restore the intended value during cleanup.

Example

-- Let the player damage the target without other NPCs doing so.
local previous = isPedOnlyDamagedByPlayer(target)
assert(setPedOnlyDamagedByPlayer(target, true))
-- Restore the previous rule during cleanup.
setPedOnlyDamagedByPlayer(target, previous)

Where this comes from

RELATED SA:O APIS

Continue exploring

Read the system guide →