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

Area

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

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:7200

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:7323

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:7330

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:7343

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.


getHerbs(virtualWorld?): GatheringHerb[]

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

Lists available authored herbs whose source positions are inside this area’s current geometry. Works without nearby players. Picked and script-removed plants are excluded. Ignores area.enabled; an area in another world or a destroyed area returns an empty array.

number

One virtual-world bucket; defaults to the area’s world, or 0 for an area in every world. Pass player.virtualWorld for a player’s bucket. 0xffffffff selects only the global bucket. Invalid IDs throw.

GatheringHerb[]


removeHerbs(virtualWorld?): number

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

Removes authored herbs inside this area’s current geometry for one world, including plants already waiting to regrow. Gives no items or experience and raises no harvest events. Plants stay removed until an explicit respawn or server restart, even if the area’s geometry, enabled state or lifetime changes.

number

One virtual-world bucket; defaults to the area’s world, or 0 for an area in every world. Pass player.virtualWorld for a player’s bucket. 0xffffffff selects only the global bucket. Invalid IDs throw.

number

Number of sources newly marked for removal; repeated removal returns 0. Includes picked plants whose regrowth was disabled.


respawnHerbs(virtualWorld?): number

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

Restores picked and script-removed herbs inside this area’s current geometry in one world. Restores vegetation for connected players and future arrivals. Ignores area.enabled; an area in another world or a destroyed area changes nothing.

number

One virtual-world bucket; defaults to the area’s world, or 0 for an area in every world. Pass player.virtualWorld for a player’s bucket. 0xffffffff selects only the global bucket. Invalid IDs throw.

number

Number of active harvested or removed sources restored.


setShape(definition): boolean

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

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:7349

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:7316

Formats this area for logging and debugging.

string

Its id, kind, type and name.


static all(kind?): Area[]

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

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:7376

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:7391

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:7398

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:7383

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:7407

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:7414

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:7290

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:7240

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


collisionCeiling: boolean

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

Whether a box or polygon boundary also closes its top with a plate across the whole interior. False by default, for side walls only. A sphere is always one closed shell. Authored areas only.


collisionFloor: boolean

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

Whether a box or polygon boundary also closes its bottom with a plate across the whole interior. False by default, for side walls only. A sphere is always one closed shell. Authored areas only.


collisionThickness: number

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

How thick the boundary is, in metres, centred on the drawn outline: 0.2 by default, from 0.05 to 2. Throws when the shape is too small for it while collision is on. Authored areas only.


readonly doors: AreaDoor[]

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

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:7260

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:7205

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:7280

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:7210

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:7215

Whether the level placed it or a script built it.


labels: string[]

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

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:7285

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:7295

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:7235

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:7225

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:7310

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


readonly players: Player[]

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

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


position: Vector3

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

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:7275

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:7220

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:7265

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.