codeAPI Reference

s&box CombatNpc: Combat NPC

calendar_today May 12, 2026 schedule ~2 min read person PatrickJr verified 50

CombatNpc Class API Reference

CombatNpc is a combat NPC that searches for players, advances on them, fires in bursts, and repositions. When friendly, follows players and engages hostile NPCs instead. Implements IDamageable.

Type Signature

CSHARP
public class CombatNpc : Npc, Component.IDamageable
{
    [Property, ClientEditable, Sync] public bool Friendly { get; set; } = false;
    [Property, ClientEditable, Range(1, 250), Sync] public float Health { get; set; } = 100f;
    [Property] public BaseWeapon Weapon { get; set; }
    [Property, Group("Balance"), Range(512, 4096), Step(1), ClientEditable, Sync] public float AttackRange { get; set; } = 1024f;
    [Property, Group("Balance"), Range(90, 250f), Step(1), ClientEditable, Sync] public float EngageSpeed { get; set; } = 180f;
    [Property, Group("Balance")] public float SearchTimeout { get; set; } = 8f;
    [Property, Group("Balance")] public float PatrolRadius { get; set; } = 400f;
    [Property, Group("Balance")] public float BurstDuration { get; set; } = 1.5f;
    [Property, Group("Balance")] public float BurstPause { get; set; } = 0.8f;
    [Property, Group("Balance")] public float FollowDistance { get; set; } = 150f;
}

Properties

IDamageable Implementation

Usage

CSHARP
// Create a hostile combat NPC
var npc = GameObject.Components.Create<CombatNpc>();
npc.Friendly = false;
npc.Weapon = weaponPrefab;
npc.AttackRange = 1500f;

Notes

  • Friendly NPCs follow players and attack hostile NPCs
  • Hostile NPCs target players and friendly NPCs
  • Uses schedules: CombatEngageSchedule, CombatFollowSchedule, CombatPatrolSchedule
  • Speaks pain and death lines
  • Interrupts schedule on damage
Was this helpful?