Garry's Mod Wiki

NPC:GetNPCState

  number NPC:GetNPCState()

Description

Returns the NPC's state.

Returns

1 number
The NPC's current state, see NPC_STATE enum.

Example

Function which prints out a list of idle NPCs to the server console.

function ReportIdleNPCs() for i, npc in ipairs( ents.FindByClass( "npc_*" ) ) do if IsValid( npc ) and npc:IsNPC() and npc:GetNPCState() == NPC_STATE_IDLE then print( "Ent #" .. npc:EntIndex() .. ": " .. npc:GetClass() .. " is idle." ) end end end
Output: (To server console)

Ent #111: npc_citizen is idle.

Ent #120: npc_citizen is idle.

Ent #122: npc_citizen is idle.

Ent #124: npc_citizen is idle.