Skip to content
KCKingdoms Connected Scripting APIScripting guides and API
Runtime classServer APIGenerated

Npc

Defined in: server/api.d.ts:4440

A server-owned NPC: spawned by a resource, simulated by whichever client is nearest.

new Npc(id): Npc

Defined in: server/api.d.ts:4445

Creates a script wrapper for an existing NPC with this ID; use Npc.create() to spawn one.

number

Network entity identifier.

Npc

Entity.constructor

attack(target, options?): boolean

Defined in: server/api.d.ts:4651

Orders native combat against a live player or NPC in the same visible world within 128 metres. Another order stops it. The order fails when its target dies, disappears or leaves that range. It waits while dormant; no offline damage is simulated. Bow attacks stop within 18 metres and use native projectiles. Equipped NPC arrows are replenished while shooting.

number | Player | Npc

The combatant to pursue and attack.

Defaults to melee. Bow requires an equipped bow and compatible arrows.

"melee" | "bow"

boolean

True when accepted. Invalid targets leave the previous order unchanged.


damage(amount, attacker?): void

Defined in: server/api.d.ts:4754

Takes health off the ledger, raising npcDamage and, if it is the last of it, npcDeath. Refused for an invulnerable or already-dead body.

number

Health to take off.

number | Player

Who did it, for the events this raises.

void


flee(from, options?): boolean

Defined in: server/api.d.ts:4667

Sends the NPC straight away from a place until the requested distance separates them. If the body reports blocked, a loaded mesh lets the server try a route to a point past that distance, on the ground at the NPC’s own height, before reporting it.

Vector3 | Partial<Vector3>

What to run away from.

radius is how far away is far enough; speed is the pace, run by default.

number

"walk" | "jog" | "run"

boolean

True when the order went out.


follow(target, options?): boolean

Defined in: server/api.d.ts:4659

Keeps the NPC near somebody as they move, steering straight at them. npcIntentDone reports reached the first time it catches up, and the follow carries on. If the body reports blocked, a loaded mesh lets the server route to the target’s current position before reporting it. After recovery it resumes following the moving target.

number | Player | Npc

Who to follow, as a handle or a network ID.

radius is how close it tries to stay, in metres; speed is the pace.

number

"walk" | "jog" | "run"

boolean

True when the order went out.


getAnimalLoot(): AnimalLootItem[] | null

Defined in: server/api.d.ts:4604

Returns game-data loot candidates for this animal. Does not roll or populate stock. The gamemode chooses chances and writes Inventory.set at spawn. Null for non-animals, excluded souls or unresolved adopted bodies; an empty array is a known empty preset.

AnimalLootItem[] | null


getInventory(): InventoryState | null

Defined in: server/api.d.ts:4609

Reads server-owned stock and worn row counts. Inventory.get/add/remove/setProperties/set/transfer also accept Npc handles. Default native stock becomes ready at npcInventoryReady; Inventory.set may provide it before a body exists.

InventoryState | null


getNametagColor(): number

Defined in: server/api.d.ts:4593

Reads this NPC’s nametag color.

number

Packed 0xAARRGGBB color; opaque white when untinted.


getNametagText(): string

Defined in: server/api.d.ts:4581

Reads this NPC’s nametag text override.

string

The override, or an empty string when the NPC’s name is drawn.


hold(): void

Defined in: server/api.d.ts:4619

Cancels whatever it was doing and leaves it standing where it is.

void


isNametagHealthVisible(): boolean

Defined in: server/api.d.ts:4569

Checks whether the health bar under this NPC’s nametag is shown.

boolean

True unless the health bar was hidden.


isNametagVisible(): boolean

Defined in: server/api.d.ts:4557

Checks whether this NPC’s nametag is drawn; the same switch as the nametag property.

boolean

True while the nametag is shown.


kill(attacker?): void

Defined in: server/api.d.ts:4760

Kills it outright, through the same path damage takes – including an invulnerable one, which is the difference between this and damage.

number | Player

Who to credit with it.

void


lookAt(target): boolean

Defined in: server/api.d.ts:4674

Turns the NPC’s head, and its body when it has to, without moving it.

number | Player | Npc | Vector3 | Partial<Vector3>

Who or what to look at.

boolean

True when the order went out.


moveTo(position, options?): boolean

Defined in: server/api.d.ts:4633

Moves to position, cancels any patrol, and emits npcIntentDone once when the move ends.

The game’s own movement steers a body straight at the point it is given and finds no way around anything, so routes come from the server’s navigation mesh. The server plans the route and hands the simulating client one corner at a time, the next before the body reaches the last, so it walks through bends without stopping; a dormant NPC is walked along the same route by the server. Routes only use doorways whose door stands open.

auto (the default) routes on the server whenever a mesh is loaded. Without one, a simulating client steers straight at position and a dormant NPC moves in a straight line. game steers straight at position and waits while dormant; if the body reports blocked and a mesh is loaded, the server tries a route before emitting npcIntentDone. server always routes on the server and throws without a loaded mesh, preserving the previous order.

A missing or partial route ends with blocked, and a blocked route is not retried. Route plans are queued and spread over ticks; the move reads running meanwhile.

Vector3 | Partial<Vector3>

Where to walk to.

speed defaults to walk; radius is the arrival distance in metres (default 1.5). pathfinding defaults to auto.

"auto" | "server" | "game"

number

"walk" | "jog" | "run"

boolean

True when the order went out; false for an invalid NPC or destination.


patrol(points, options?): boolean

Defined in: server/api.d.ts:4643

Walks the waypoints in order. The server stores the route and replicates the current target. npcIntentDone fires once per leg, after its final mesh corner or a movement failure.

A leg that ends blocked or failed is skipped after at least 2 seconds. When every leg of a lap has failed in a row, the patrol is abandoned and that last leg reports failed instead.

string | PatrolRoute | (Vector3 | Partial<Vector3>)[]

Waypoints, a named route handle, or its stable id. Named routes are copied at start.

Point arrays retain their defaults: loop, walk, zero wait. Named routes use their authored defaults. Call options override route defaults; waypoint overrides take priority. Use mode for once, loop or pingPong; do not combine mode and loop. radius is the arrival distance. pathfinding uses the moveTo modes for every leg.

boolean

"once" | "loop" | "pingPong"

"auto" | "server" | "game"

number

"walk" | "jog" | "run"

number

boolean

True when the route was accepted; false for an empty route, more than 256 waypoints, a waypoint that is not finite or lies outside the world, or a waitSeconds that is not a number. Throws if server mode has no loaded mesh, leaving the previous order intact.


pin(player): void

Defined in: server/api.d.ts:4771

Pins simulation of this NPC to one player’s client, whatever the distances say. What a scripted scene wants: the actor has to be run by the machine the scene is being played to. A pinned NPC goes dormant rather than migrating when that player leaves range, and is unpinned automatically if they disconnect.

number | Player | null

Whose client should run it, or null to hand it back to the election.

void


playAnimation(fragment, options?): boolean

Defined in: server/api.d.ts:4694

Makes the NPC play one of the game’s animations – chopping wood with an axe in hand, drawing water, sitting, drinking – on every client, the one simulating it included. It is state rather than a one-off: a client that streams the NPC in, and the next one to simulate it, play it too, until stopAnimation or the next playAnimation, which both cut it at once.

Give it something to do that keeps it in place, hold or lookAt: an order to walk makes the legs fight a full-body animation. A hit or a fall can cut the animation short; loop starts it again, and keeps a one-shot going pass after pass with no gap.

npcAnimationEnd fires once when the animation this request started is over, and says how.

string | number

A Mannequin fragment, as Animations.list names it – or, as before, a row of the shipped emote catalog, which plays that gesture once and is not remembered.

clip plays a clip the server streams instead of a fragment (animations/kcdc/<resource>/wave.caf, the fragment left ""), tags pick the variant, loop repeats it until stopped, props puts up to two models in its hands. lockMovement does nothing here: an NPC standing still is its intent’s business.

string

boolean

boolean

{ hand?: "right" | "left"; item?: string; joint?: string; model?: string; position?: Vector3 | Partial<Vector3>; rotation?: Vector3 | Partial<Vector3> | Quaternion; } | object[]

string

boolean

True when the request went out; false for a dead NPC. Throws for a prop or option it cannot use.


remove(): void

Defined in: server/api.d.ts:4614

Despawns this NPC everywhere, after emitting npcDestroy.

void


revive(): void

Defined in: server/api.d.ts:4765

Brings a dead NPC back at full health. Every client makes a fresh body for it, because the one they have is a corpse.

void


say(text): boolean

Defined in: server/api.d.ts:4726

Puts a line of speech over the body on every client that can see it.

string

What it says, up to 256 characters.

boolean

True when the line went out.


setAppearance(appearance): boolean

Defined in: server/api.d.ts:4747

Changes the body under the clothes – face, hair, beard and skin. Unlike a player’s, this is a write rather than a request: nobody owns an NPC’s body but the server.

Partial<Appearance>

The parts to change; anything left out keeps what it is wearing.

boolean

True when the appearance was accepted.


setFacialExpression(fragment, options?): boolean

Defined in: server/api.d.ts:4711

Sets the NPC’s facial expression on every client, alongside whatever its body plays. It is state: a client that streams the NPC in, and the next one to simulate it, show it too, until the next call.

The expression is the eyes, brows and mood; it never moves the mouth, which is setTalking. A mood tag is one of the body’s own tags, so it can change the mood of its idle too.

string

A fragment on the face’s own scope: FE_Default, FE_DialogueIdle or FE_DialogueSpeaking for a held mood, or an ADLG_FA_* gesture (ADLG_FA_Smile, ADLG_FA_Wink, ADLG_FA_Laugh, ADLG_FA_Surprise…) that plays once. "" hands the face back to the game.

tags pick the variant: for the FE_* fragments the mood, happy, angry, sad, nervous, pensive, arogant or drunk, as Animations.list("FE_") spells them.

string

boolean

True when the request went out; false for a dead NPC. Throws for an argument it cannot use.


setNametagColor(color): void

Defined in: server/api.d.ts:4599

Tints the text on this NPC’s nametag.

number

Packed 0xAARRGGBB color.

void


setNametagHealthVisible(visible): void

Defined in: server/api.d.ts:4575

Shows or hides the health bar under this NPC’s nametag, leaving the name itself alone.

boolean

True to show the health bar under this NPC’s name, false to hide it.

void


setNametagText(text?): void

Defined in: server/api.d.ts:4587

Overrides the text drawn on this NPC’s nametag without renaming it: name still reaches conversation and the soul.

string

Text to show instead of the NPC’s name; empty or omitted restores the name.

void


setNametagVisible(visible): void

Defined in: server/api.d.ts:4563

Shows or hides the name over this NPC’s head for every player; the same switch as the nametag property. Each player can still hide all nametags locally.

boolean

True to draw this NPC’s nametag for every player, false to hide it.

void


setOutfit(preset): boolean

Defined in: server/api.d.ts:4740

Dresses the body in one of the game’s own outfits.

string

Clothing preset GUID from the game’s own table.

boolean

True when the preset is one this build has.


setTalking(talking, style?): boolean

Defined in: server/api.d.ts:4719

Moves the NPC’s mouth as if it were talking, on every client, until told to stop. Pair it with say for a line of text. It is a looping talk animation, not lip-sync: it follows no words, and the game’s own lip-sync wins while the NPC speaks a voice line of its own.

boolean

Whether the mouth moves.

"neutral" | "happy" | "drunk" | "chew"

How: neutral (the default), happy, drunk or chew.

boolean

True when the request went out; false for a dead NPC. Throws for a style it does not know.


setVirtualWorld(world): void

Defined in: server/api.d.ts:8797

Moves this entity into another virtual world.

number

Virtual-world identifier used to partition replication and visibility.

void

Entity.setVirtualWorld


setVisibleTo(player): void

Defined in: server/api.d.ts:8803

Restricts replication of this entity to one owning connection while preserving normal range and visibility checks.

Entity | null

Player-owned entity whose connection should exclusively receive this entity, or null to clear the restriction.

void

Entity.setVisibleTo


stopAnimation(options?): boolean

Defined in: server/api.d.ts:4701

Ends what playAnimation started at once, takes its props away and hands the body back to its intent. The stand-up standUp asks for is an animation of its own and raises its own npcAnimationEnd.

standUp plays the game’s own way back to standing when the animation held the body in a sitting or lying stance tag: StandUp or GetUp, in the variant that fits. Without it the body goes straight back to standing.

boolean

boolean

True when the request went out.


teleport(position, rotation?): boolean

Defined in: server/api.d.ts:4682

Moves the body outright, whoever is simulating it. Unlike a player teleport this is a write rather than a request: the server bumps the body’s epoch, so a pose the simulator had already sent cannot put it back.

Vector3 | Partial<Vector3>

Where to put it.

Vector3 | Partial<Vector3> | Quaternion

Optional facing; a Quaternion, or Euler angles in degrees.

boolean

True when the position was usable.


toString(): string

Defined in: server/api.d.ts:4551

Formats this NPC handle for logging and debugging.

string

The NPC’s ID, name, intent and last reported status.

Entity.toString


wear(itemClasses): boolean

Defined in: server/api.d.ts:4733

Dresses the body in exactly these items, replacing what it had on. Existing items are reused and missing ones are added to stock. An empty list undresses it and retains its clothes as loose inventory.

string[]

Item class GUIDs in the dashed form the game’s own tables spell them.

boolean

True when every GUID names an item class this build has. Otherwise nothing changes, and each refused GUID is logged.


static adopt(levelGuid, options?): Npc

Defined in: server/api.d.ts:4788

Takes over one of the level’s own NPCs instead of spawning a new body. Locomotion is validated as for create. A level EntityGuid is the same number on every machine, so every client finds the same body – which is how doors, gates and stashes are already addressed. Adopting the same guid twice returns the NPC that already has it without applying the options again.

number

EntityGuid of the body the level already placed.

The same options a spawn takes; soul and class are ignored, since the body already exists.

Partial<Appearance>

string

number

boolean

number

boolean

boolean

"native" | "kinematic"

boolean

number

string

boolean

string

Vector3 | Partial<Vector3>

Vector3 | Partial<Vector3> | Quaternion

string

number

string[]

Npc

The NPC handle for that body.


static all(virtualWorld?): Npc[]

Defined in: server/api.d.ts:4795

Lists every server-owned NPC.

number

Optional virtual world to list; omitted lists every one of them.

Npc[]

One handle per live NPC, in no particular order.


static animals(): object[]

Defined in: server/api.d.ts:4825

Animal souls with matching native classes. Pass a name or soul to Npc.create. Chickens use flock entities and are excluded.

object[]


static animalSpawnpoints(level?): object[]

Defined in: server/api.d.ts:4831

Level-authored animal spawners. Positions are markers and must be projected onto navigation. GUIDs are hex strings. Counts and respawn days describe the original game; scripts decide their population and respawn policy.

string

Defaults to the running server’s level. Pass * for all levels.

object[]


static create(options): Npc

Defined in: server/api.d.ts:4780

Spawns an NPC and replicates it. Omitted or undefined locomotion defaults to native; other values must be exactly native or kinematic, otherwise it throws before spawning. It exists on the server from this moment: every client near enough makes a body for it, one of them is elected to run it, and the rest draw what that one reports.

The body is not simulated until somebody is close enough to run it, which is not a failure – a guard on the other side of the map has nothing to do that anybody can see. Read simulator to tell.

soul is a role from Npc.roles(), an animal name from Npc.animals(), or a soul GUID; position is where to put it. Everything else has a default.

Partial<Appearance>

string

number

boolean

number

boolean

boolean

"native" | "kinematic"

boolean

number

string

boolean

string

Vector3 | Partial<Vector3>

Vector3 | Partial<Vector3> | Quaternion

string

number

string[]

Npc

The new NPC’s handle.


static getById(id): Npc | null

Defined in: server/api.d.ts:4802

Looks an NPC up by its network entity ID.

number

Network entity identifier.

Npc | null

The NPC’s handle, or null when no live NPC has that ID.


static placements(): object[]

Defined in: server/api.d.ts:4820

Authored human NPC placements in the configured level with matching catalog souls. These are initial placements, not current NPC schedules or proof that a quest layer is loaded. Does not spawn or adopt anything.

object[]


static removeAll(virtualWorld?): number

Defined in: server/api.d.ts:4809

Despawns NPCs, emitting npcDestroy for each.

number

Optional virtual world to clear; omitted clears every one of them.

number

How many were despawned.


static roles(): string[]

Defined in: server/api.d.ts:4815

The named kinds of NPC this build ships – guard, bandit, townswoman and the rest. Each is a real soul out of the game’s own tables, so a role spawns a body that already looks the part. Animal names are listed separately by Npc.animals(). Other values are taken as soul GUIDs.

string[]

The role names.

readonly actorClass: string

Defined in: server/api.d.ts:4455

Native entity class, including NPC, NPC_Female, or the matching animal class from Npc.animals().


readonly alive: boolean

Defined in: server/api.d.ts:4485

False once health reached zero. A dead NPC is still an entity – it is a corpse, and it can still be looted or revived.


readonly appearance: Appearance

Defined in: server/api.d.ts:4535

The body under the clothes, as the game’s own component names. Write it with setAppearance.


faction: number

Defined in: server/api.d.ts:4470

Faction row used for relationship and crime decisions; 0 is no faction.


frozen: boolean

Defined in: server/api.d.ts:4495

Whether the body holds its pose whatever its intent says.


health: number

Defined in: server/api.d.ts:4475

The server’s ledger of this body’s health, clamped to maxHealth. Combat damage arrives here after the server has agreed to it.


readonly id: number

Defined in: server/api.d.ts:8765

Immutable network entity identifier.

Entity.id


readonly intent: string

Defined in: server/api.d.ts:4520

What the NPC has been told to do: hold, moveTo, follow, flee, lookAt, playAnim, talk or attack.


interactable: boolean

Defined in: server/api.d.ts:4500

Whether clients watch the use key against this body and raise npcInteract. On by default.


invulnerable: boolean

Defined in: server/api.d.ts:4490

Whether damage is refused before it reaches the ledger.


readonly levelGuid: number

Defined in: server/api.d.ts:4460

EntityGuid of the level body this NPC adopted, or 0 for a spawned one.


locomotion: "native" | "kinematic"

Defined in: server/api.d.ts:4515

How the client simulator moves the body. native (default) uses the game’s movement controller and walk animations. kinematic moves the body directly without walk animation. Only these exact, case-sensitive strings are accepted; invalid values throw without changing the mode. Neither finds a way around anything: the game’s movement controller steers straight at the point it is given. Routes come from server pathfinding, which hands either mode mesh corners – see moveTo.


lootable: boolean

Defined in: server/api.d.ts:4510

Whether its corpse keeps its inventory for whoever searches it.


readonly maxHealth: number

Defined in: server/api.d.ts:4480

Health the body starts with and is revived to.


name: string

Defined in: server/api.d.ts:4465

What every client shows over the body and in conversation. Empty leaves the name its soul was born with.


nametag: boolean

Defined in: server/api.d.ts:4505

Whether its name is drawn over it the way a player’s is.


readonly patrolState: PatrolState | null

Defined in: server/api.d.ts:4525

Current patrol snapshot and progress, or null when not patrolling. Updating a route does not change a running patrol.


position: Vector3

Defined in: server/api.d.ts:8775

Authoritative world-space position; assignment forces replicated state.

Entity.position


rotation: Vector3 | Quaternion

Defined in: server/api.d.ts:8780

Authoritative rotation; reads return a quaternion and assignments accept a quaternion or Euler angles in degrees.

Entity.rotation


readonly simulator: Player | null

Defined in: server/api.d.ts:4545

The player whose client is currently running this NPC, or null while it is dormant. Dormant is not broken: nobody is near enough for it to matter, and the server keeps its route advancing until somebody is.


readonly soul: string

Defined in: server/api.d.ts:4450

GUID of the soul the body was spawned against, or empty for an adopted level body. Read-only: a soul decides what the body is, so a different one is a different NPC.


readonly state: StateBag

Defined in: server/api.d.ts:8785

Arbitrary key/value state carried by this entity. The server writes it and every client that can see the entity receives it; see StateBag.

Entity.state


readonly status: string

Defined in: server/api.d.ts:4530

What has become of the current order: idle, running, reached, blocked or failed. A move reads running from the moment it is given – while its route is planned and while it walks the route’s corners – until it ends, and then the outcome npcIntentDone announced, which stays until the next order. A follow reads reached while it is within its radius. Dormant moves in auto or server mode are carried out and decided by the server; dormant game moves wait for a client simulator.


readonly virtualWorld: number

Defined in: server/api.d.ts:8770

Current virtual-world identifier.

Entity.virtualWorld


readonly wearing: string[]

Defined in: server/api.d.ts:4540

Its worn item classes. Before default stock is established an empty list leaves the soul’s own outfit; afterward empty means undressed. Write it with wear, setOutfit or Inventory.set.