NPC/GetNPCState

From Garry's Mod
Jump to: navigation, search
 NPC:GetNPCState( )

Contents

Description

Returns the NPC's state.

Returns

number

The NPC's current state, see NPC_STATE_ Enums.

Examples

Example

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

function ReportIdleNPCs()

	for _, npc in pairs(ents.FindByClass("npc_*")) do
	
		if(IsValid(npc) && npc:IsNPC() &&
			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.
Personal tools
Navigation