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

Area

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

Handle for one area: one of the level’s own gameplay areas, or one a script or the World Builder drew. The server tests who is inside itself, by the game’s own rule for that kind of area.

new Area(handle): Area

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

Wraps an area handle the server already holds; use Area.create, Area.getById or the lookups to get one.

number

Internal area handle.

Area

contains(position): boolean

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

Tests a position the way the game tests its own areas, whether or not the area is enabled and in whatever world.

Vector3

The world position to test.

boolean

True when the position is inside.


containsPlayer(player): boolean

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

Tests where a body stands right now, and in which world: an area bound to another virtual world does not contain it. This is containment only – whether the game considers the player to be trespassing is decided by its own crime system on the player’s client.

Player | Npc | Horse | Cart

The body to test; a player who has not reported a pose yet is never inside.

boolean

True when the body is inside.


destroy(): boolean

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

Removes a script area. Every body still inside gets its areaExit first, while the handle still resolves.

boolean

False for a level area or one already gone.


setShape(definition): boolean

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

Moves, turns or reshapes a script area. Bodies standing where it now is, or was, get their areaEnter and areaExit on the next tick. A level area cannot be reshaped.

Partial<AreaDefinition>

The shape fields to change; any left out keep their value. id, labels, metadata and the rest are ignored here.

boolean

False for a level area, a gone one, or a shape the engine could not build.


toJSON(): AreaDefinition | null

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

The definition Area.create takes to build this area again, which is what a script saves: the server keeps nothing past a restart. It is the format the World Builder exports too.

AreaDefinition | null

Null for a level area, which the level always builds.


toString(): string

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

Formats this area for logging and debugging.

string

Its id, kind, type and name.


static all(kind?): Area[]

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

Every area the server knows.

"script" | "level"

Optional: only the level’s areas, or only script ones.

Area[]

The areas, level ones first.


static create(definition): Area

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

Builds a script area. Bodies already standing in it get areaEnter on the next tick. Kept in memory only: save area.toJSON() wherever the resource keeps its data, and create it again on boot.

AreaDefinition

The area to build, in the format area.toJSON() and the World Builder export write.

Area

The new area. Throws for an id already taken or a shape the engine could not build.


static getAt(position, virtualWorld?): Area[]

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

Every enabled area containing a position, level and script alike.

Vector3

The world position to test.

number

Optional world; when given, a script area bound to another world is left out.

Area[]

The areas, in no particular order.


static getAtPlayer(player): Area[]

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

Every enabled area the body stands in right now, in its own world.

Player | Npc | Horse | Cart

The body whose position and world to test.

Area[]

The areas; empty for a player who has not reported a pose yet.


static getById(id): Area | null

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

Looks an area up by its stable identity.

string

A script area’s id, or a level area’s GUID in hex as area.definition.id prints it.

Area | null

The area, or null when there is none.


static nearby(position, radius, virtualWorld?): Area[]

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

Every area whose bounds come within a radius of a position, enabled or not.

Vector3

Where to look from.

number

How far, in metres, from the area’s bounds.

number

Optional world; when given, a script area bound to another world is left out.

Area[]

The areas, nearest first.


static withLabel(label): Area[]

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

Every area carrying a label, such as private or castle.

string

The label, compared without regard to case.

Area[]

The areas, level ones first.

readonly bounds: object

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

The world box around the area. An area with no ceiling reaches far above and below.

max: Vector3

min: Vector3


collision: boolean

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

Invisible boundary walls block both directions while enabled, leaving the interior empty. Authored areas only; invalid collision shapes throw.


readonly doors: AreaDoor[]

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

The doors the level itself links to this area as its crime_doors, which is how the game knows a house’s doors. Only native links: nothing is inferred from where a door stands.


enabled: boolean

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

Whether crossings are raised and the lookups find it. Switching it off raises areaExit for everyone inside on the next tick; switching it on, areaEnter. Works on level areas too.


readonly exists: boolean

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

False once a script area has been destroyed; every other read then returns its empty value.


readonly height: number

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

How far above its lowest point a prism reaches, in metres; 0 for a shape with no ceiling. A TriggerArea’s comes from the level’s baked prism.


readonly id: string

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

The stable identity to store an area under. A level area’s is its EntityGuid as sixteen lowercase hex digits, the same on every machine and every boot, as door.guid prints a door’s; a script area’s is the id it was created with.


readonly kind: "script" | "level"

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

Whether the level placed it or a script built it.


labels: string[]

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

The level’s own Label values – private, personal, interior, prohibited, castle and the rest the game’s AI reads – or a script area’s labels. Only a script area’s can be changed.


readonly location: string

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

For a SmartAreaShape bound to one of the game’s map locations, that location’s English name, e.g. a settlement. Empty otherwise.


readonly members: Area[]

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

For an AreaUnion, the TriggerAreas it joins; it contains whatever one of them does. Empty otherwise.


metadata: Record<string, unknown>

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

Whatever a script keeps on a script area: ownership, a type, rules. Stored as JSON, so read it, change it and assign it back. Always empty on a level area.


name: string

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

The level’s entity name, or the script area’s name. Only a script area’s can be changed.


readonly occupants: (Player | Npc | Horse | Cart)[]

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

Every body inside as of the last tick: players, horses, carts and server NPCs.


readonly players: Player[]

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

Every player inside as of the last tick, in any world.


position: Vector3

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

A script area’s origin, which its shape is placed from; assignment moves it. A level area’s is the centre of its bounds.


rotation: Quaternion

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

A script area’s orientation; assignment turns it. A level area’s shape is already in world space, so its rotation is the identity.


readonly type: "sphere" | "box" | "shape" | "TriggerArea" | "AreaUnion" | "SmartAreaShape"

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

A level area’s entity class – a TriggerArea prism, an AreaUnion of them, or a SmartAreaShape – or a script area’s shape.


virtualWorld: number | null

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

The one virtual world a script area belongs to, or null for all of them. A body in another world still crosses it, with matchingVirtualWorld false. A level area is in every world.