Skip to main content

CAI_BaseNPC

Base class of every NPC: troopers, neutral creeps, bosses, the Patron, hero summons and bot brains.

public class CAI_BaseNPC : CBaseEntity

Namespace: DeadworksManaged.Api
Inherits / implements: CBaseEntity
Derived types: CAI_CitadelNPC
Source: Entities/CAI_BaseNPC.cs#L13

Notes​

Hero pawns are not NPCs, even a bot's. A bot's AI is its CCitadelPlayerBotNPCBrain.

Properties​

CAI_BaseNPC.State​

Current AI state.

Signature

public NpcState State { get; }

Source: Entities/CAI_BaseNPC.cs#L65

CAI_BaseNPC.IdealState​

AI state the NPC switches to on its next think.

Signature

public NpcState IdealState { get; }

Source: Entities/CAI_BaseNPC.cs#L68

CAI_BaseNPC.IsDormant​

True for a hidden trooper the game keeps for reuse (NpcState.Inert). Skip these.

Signature

public bool IsDormant { get; }

Source: Entities/CAI_BaseNPC.cs#L71

CAI_BaseNPC.Schedule​

Running schedule, such as SCHED_TROOPER_RUN_DOWN_LANE. Null between schedules.

Signature

public string? Schedule { get; }

Source: Entities/CAI_BaseNPC.cs#L74

CAI_BaseNPC.Enemy​

Entity the NPC is fighting, or null.

Signature

public CBaseEntity? Enemy { get; }

Source: Entities/CAI_BaseNPC.cs#L83

Methods​

CAI_BaseNPC.Create()​

Spawns an NPC by VData subclass name, such as neutral_trooper_strong or npc_boss_tier1. Returns null if the name is not an NPC subclass.

Signature

public static CAI_BaseNPC? Create(string designerName, Vector3 position, int team = 0, Vector3? angles = null)

Parameters

  • designerName: Subclass name. SubclassNames in DeadworksManaged.Game lists them.
  • position: Spawn position.
  • team: Team. 0 keeps the NPC's default.
  • angles: Pitch, yaw, roll. Null faces +X.

Notes Class names such as npc_trooper_neutral return null. For lane troopers use CNPC_Trooper.Create, which also assigns a lane.

Source: Entities/CAI_BaseNPC.cs#L36

CAI_BaseNPC.MoveTo()​

Sends the NPC to a point, like npc_go.

Signature

public void MoveTo(Vector3 goal, bool run = true, float tolerance = 0f)

Parameters

  • goal: Destination. Need not be on the navmesh.
  • run: Run instead of walking.
  • tolerance: Arrival distance. 0 uses the npc_go default.

Notes The NPC ignores enemies and damage until it arrives or the path fails, then resumes its own AI. Most orders over 3000 units of path fail. Shorter ones can stop partway in SCHED_FAIL. Send long trips in legs along Nav.FindPath, and order again after a failure. To follow a moving target, call again every 0.5 s.

Source: Entities/CAI_BaseNPC.cs#L100

CAI_BaseNPC.Stop()​

Drops the current move order, like npc_stop_moving.

Signature

public void Stop(bool instant = false)

Parameters

  • instant: Stop on the spot instead of slowing down.

Source: Entities/CAI_BaseNPC.cs#L107

CAI_BaseNPC.SetEnemy()​

Sets the NPC's enemy. Null clears it.

Signature

public void SetEnemy(CBaseEntity? enemy)

Notes The AI re-picks its enemy every think and may switch to a closer one. An enemy on the NPC's own team is dropped.

Source: Entities/CAI_BaseNPC.cs#L111

CAI_BaseNPC.SetSchedule()​

Starts a schedule, such as SCHED_IDLE_STAND. Returns false if the NPC refuses it.

Signature

public bool SetSchedule(string name)

Notes Runs until it finishes or is interrupted. A schedule the NPC's class lacks runs SCHED_IDLE_STAND instead and logs "No CASE for Schedule Type". To replace the NPC's next pick, use IDeadworksPlugin.OnNpcSelectSchedule.

Source: Entities/CAI_BaseNPC.cs#L119

CAI_BaseNPC.SetState()​

Sets the AI state. NpcState.Idle also clears the enemy.

Signature

public void SetState(NpcState state)

Notes The game may turn NpcState.Idle into NpcState.Alert.

Source: Entities/CAI_BaseNPC.cs#L127