Garry's Mod Wiki

NPC:GetNPCState

number NPC:GetNPCState()

Description

Returns the NPC's state.

Returns

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

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.

Page Links


Special Pages


Wikis

?

Render Time: 74ms

DB GetPage 40
Generate Html 9
SaveChanges (1) 10
Render Body 0
Render Sidebar 12