build Constructors 1

data_object Properties 20

ActiveSchedule
BaseSchedule
The current running schedule for this NPC.
Animation
AnimationLayer
Animation layer - handles look-at and animation state
DisplayName
string
The name games show for this NPC, such as when it is killed.
EyeHeight
float
How far above its origin this NPC sees from.
EyePosition
Vector3
Where this NPC sees from, Sandbox.Npcs.BaseNpc.EyeHeight above its origin.
Faction
string
The faction this NPC belongs to -- its identity to others: one of Sandbox.Npcs.Factions or a game's own. Its default relationships follow from it, see Sandbox.Npcs.BaseNpc.SetupRelationships. Set it on the host: the NPC then works out afresh who it likes and hates and what to do. An NPC type can override it to compute it.
FatalImpactSpeed
float
Hitting something at or above this speed is fatal.
GroundObject
GameObject
The object we're standing on. Null if we're standing on nothing.
GroundSurface
Surface
If we're stnding on a surface this is it
Health
float
Current health, never negative. Below 1 starts death handling: assigning it on the host follows the same cancellable death path as damage, with no attacker. Not a number is ignored.
IsAirborne
bool
Off our feet - thrown, dropped, or carried. Only NPCs whose mover keeps them on the ground (Sandbox.Npcs.Layers.MovementLayer.UsesGround); ones that fly or roll around on physics are never "airborne".
IsOnGround
bool
Are we on the ground?
MaxHealth
float
The most health this NPC has. Raised to Sandbox.Npcs.BaseNpc.Health when the NPC starts if it's lower.
MaxSafeImpactSpeed
float
Hitting something at or below this speed while airborne doesn't hurt - landing from a throw or a fall, or being slammed into a wall.
Movement
MovementLayer
Movement layer - walks the navmesh, flies or otherwise moves the NPC. Null if the NPC has none. An NPC can carry several, such as one to walk and one to fly: this is the enabled one, and Sandbox.Npcs.BaseNpc.SetMovement(Sandbox.Npcs.Layers.MovementLayer) switches between them.
PhysicsCarrier
GameObject
The entity carrying this NPC through physics, such as something that grabbed it. See Sandbox.Npcs.BaseNpc.StartCarry(Sandbox.GameObject).
Renderer
SkinnedModelRenderer
The model the NPC is drawn with, which its animator drives and its ragdoll copies.
Senses
SensesLayer
Senses layer - handles environmental awareness and target detection. Null if the NPC has none.
ShowDebugOverlay
bool
Draws this NPC's schedule, awareness and layer state as text above it.
Speech
SpeechLayer
Speech layer - handles talking, lipsync, etc. Null if the NPC has none.

functions Methods 28

CalculateAimPoint (target)
Vector3
Where to aim at a target. Roughly chest height by default: most of the way from the feet up to the eyes, so it follows crouching.
ClearRelationship (other)
Remove a per-entity override, falling back to the faction default.
CreateRagdoll ()
GameObject
Spawns a networked ragdoll prop at the NPC's current position, copying the renderer and clothing, and returns it, or null if there's nothing to ragdoll. Host only. Override to leave something else behind.
EmitStimulus (kind, radius, lifetime)
Broadcast a stimulus from this NPC's position for nearby NPCs to sense (a gunshot when it fires, a death when it dies, and so on).
EndCurrentSchedule ()
End the current schedule: its open task ends as Sandbox.Npcs.Tasks.TaskResult.Failed, then the schedule's OnEnd runs. Can be called by subclasses to interrupt the active schedule (e.g. when damaged), also from inside a schedule or task callback. Does nothing when no schedule is running.
GetDisposition (other)
Disposition
How this NPC regards another entity.
GetFallbackRelationship (other)
Relationship
Default stance when no entity override or faction relationship exists. Called during relationship queries on the main thread; keep it cheap and free of side effects. The base returns neutral.
GetRelationship (other)
Relationship
The full relationship (disposition + priority) this NPC has toward another entity. Per-entity overrides win, then the faction relationship, then Sandbox.Npcs.BaseNpc.GetFallbackRelationship(Sandbox.GameObject). Override this for fully dynamic relationships.
GetSchedule ()
T
Get a schedule -- if it doesn't exist, one will be created. The instance is reused across selections, so set its inputs each time you return it; its runtime state is reset when it starts.
Launch (velocity)
Throw the NPC into the air with this velocity, such as a leap or a shove: the mover lets go and physics carries the body until it lands. Nothing it hits before landing, nor the landing, does impact damage. Host only.
OnAwake ()
OnCarryStarted (carrier)
Something took hold of this NPC, see Sandbox.Npcs.BaseNpc.StartCarry(Sandbox.GameObject).
OnCarryStopped (carrier)
The carrier let go of this NPC, see Sandbox.Npcs.BaseNpc.StopCarry(Sandbox.GameObject). The base keeps whichever way it was turned, rather than snapping back to whatever it was looking at or doing before.
OnDamaged (e)
Called on the host when the NPC has taken a hit, before the death check. The hit is settled: its Sandbox.Component.IDamageable.DamageEvent.Instigator and Sandbox.Component.IDamageable.DamageEvent.AcceptedDamage are what counted, and changing them now does nothing. Override to react.
OnDamaging (e)
Called on the host when the NPC is about to take a hit, before anyone else hears of it. Override to shape the NPC's own incoming damage: change Sandbox.Component.IDamageable.DamageEvent.AcceptedDamage or Sandbox.Component.IDamageable.DamageEvent.Instigator, or set Sandbox.Component.IDamageable.DamageEvent.Cancelled, which ends the hit here. A hit goes through, in order: this, Sandbox.Component.IDamageable.IEvents.OnDamaging(Sandbox.Component.IDamageable.DamageEvent), the health change, Sandbox.Npcs.BaseNpc.OnDamaged(Sandbox.Component.IDamageable.DamageEvent), Sandbox.Component.IDamageable.IEvents.OnDamaged(Sandbox.Component.IDamageable.DamageEvent).
OnDeath (e)
Called on the host, once, when the NPC dies. Spawns a ragdoll with Sandbox.Npcs.BaseNpc.CreateRagdoll, which is the place to change or leave out the corpse: listeners get it in Sandbox.Component.IDamageable.IEvents.OnDied(Sandbox.Component.IDamageable.DeathEvent), which is raised after this. The NPC is destroyed once that has run, so listeners can still look at it. Override to add NPC-specific behaviour before/after death.
OnDestroy ()
OnDisabled ()
OnStart ()
OnUpdate ()
ResetRelationships ()
Forget the faction relationships, so Sandbox.Npcs.BaseNpc.SetupRelationships runs again when they are next needed. Call it when something they are built from changes.
SelectSchedule ()
BaseSchedule
Pick the schedule the NPC most wants to run right now -- return the highest-priority applicable one. Only called when (re)selecting, so a little work is fine, but keep it free of side effects and avoid randomness that shouldn't re-roll each selection.
SetMovement (mover)
Hand the NPC to another of its movement layers, such as from walking to flying. Its other movers are disabled and let go of the body where it is, and this one is enabled and takes it from there: a ground mover drops to the floor first. A move that was under way is dropped, and a Sandbox.Npcs.Tasks.MoveToTask running across the switch fails. Host only.
SetRelationship (faction, disposition, priority)
How this NPC regards the members of a faction: hostile to attack them, fearful to flee them, friendly to treat them as allies. Among hostiles a higher priority is picked first. Call it from Sandbox.Npcs.BaseNpc.SetupRelationships.
SetupRelationships ()
Declare this NPC's relationships toward other factions with Sandbox.Npcs.BaseNpc.SetRelationship(System.String,Sandbox.Npcs.Disposition,System.Int32). Unlisted factions use Sandbox.Npcs.BaseNpc.GetFallbackRelationship(Sandbox.GameObject). The base takes the defaults of its Sandbox.Npcs.BaseNpc.Faction, described on Sandbox.Npcs.Factions. Override per NPC type, without calling the base to declare all of them yourself.
StartCarry (carrier)
Something takes hold of this NPC and carries it through physics, such as a tool that grabbed it. The NPC is off its feet and its mover lets go until Sandbox.Npcs.BaseNpc.StopCarry(Sandbox.GameObject). A new carrier takes it from the last one.
StopCarry (carrier)
The carrier lets go of this NPC. Does nothing when something else carries it by now.
Think ()
The NPC's brain, run on the host each update while it's on its feet and AI is enabled. Ticks the schedule by default; override to drive the NPC some other way.

Inheritance

people
Log in to reply
You can't reply if you're not logged in. That would be crazy.