codeAPI Reference
s&box CombatNpc: Combat NPC
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
- bool Friendly { get; set; } = false - When true, friendly to players and follows them
- float Health { get; set; } = 100f - NPC health
- BaseWeapon Weapon { get; set; } - Weapon for attacking
- float AttackRange { get; set; } = 1024f - Range for engaging targets
- float EngageSpeed { get; set; } = 180f - Speed when engaging
- float SearchTimeout { get; set; } = 8f - Time to search last known position
- float PatrolRadius { get; set; } = 400f - Patrol area radius
- float BurstDuration { get; set; } = 1.5f - Firing burst duration
- float BurstPause { get; set; } = 0.8f - Pause between bursts
- float FollowDistance { get; set; } = 150f - Max follow distance for friendly NPCs
IDamageable Implementation
- OnDamage(in DamageInfo damage) - Reduces health, updates last known position from attacker, interrupts schedule, plays pain/death speech
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?