codeAPI Reference
s&box ScheduleBase: NPC schedule base class
Abstract base class for NPC schedules. A schedule executes a sequence of tasks with cancellation support.
Properties
CSHARP
public Npc Npc { get; private set; }
protected GameObject GameObject => Npc.GameObject;Methods
CSHARP
/// Called when the schedule starts. Add tasks here.
protected virtual void OnStart() { }
/// Called every frame while schedule is running.
protected virtual void OnUpdate() { }
/// Return true to cancel the schedule.
protected virtual bool ShouldCancel() => false;
/// Called when schedule is cancelled by ShouldCancel.
protected virtual void OnCancelled() { }
/// Called when the schedule ends.
protected virtual void OnEnd() { }
/// Add a task to the sequence.
protected void AddTask( TaskBase task )
/// Debug string for overlay.
public string GetDebugString()Behavior
- Executes tasks sequentially
- Each task returns TaskStatus (Running, Success, Failed, Interrupted)
- Moves to next task on Success
- Cancels entire schedule if ShouldCancel() returns true
- Calls OnCancelled() when cancelled
- Restarts first task on Success until all complete
Usage
Inherit from ScheduleBase to create NPC behavior patterns. Override OnStart() to add tasks using AddTask(). Use ShouldCancel() to interrupt based on conditions (e.g., enemy spotted).
Example: A PatrolSchedule would add MoveTo tasks to waypoints and cancel if an enemy is seen.
Source
Used by all NPC schedules (CombatPatrol, ScientistFlee, etc.).
Was this helpful?