setPedOnlyDamagedByPlayer
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
02A9 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
thePedpedScript-created ped; players are rejected.
onlyDamagedByPlayerboolWhether 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.
- 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
Continue exploring
← Back to the SA:O Lua API · How Native ped tasks and gang tags works →