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

Door

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

Replicated handle for a door: one of the level’s own, or one a script or a world resource hung with Door.spawn.

new Door(id): Door

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

Creates a script wrapper for a door the server already knows; use Door.spawn to hang a new one, or Door.find for one the level places.

number

Network entity identifier.

Door

Entity.constructor

destroy(): void

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

Takes the door out. A door a script or a world resource hung is taken down for good. A door the level places is taken out of this handle’s virtual world, collision and all, through a level edit that every client seeing that world applies – a player in the global world sees every world, so it is hidden for them too; the copy in the global world takes it out of every world. Door.restore puts a level door back, and Door.removed lists the ones that are out. Kept in memory only, like every level edit: a removal is undone when the server restarts or the resource that made it stops.

void


setOpen(open, fromFront?): boolean

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

Opens or closes the door with nobody pushing it. Every client that has the door built plays the game’s own swing; one arriving later finds it posed the same way. Opening a locked door unlocks it, as the game’s own Open does.

boolean

True to open the door, false to close it.

boolean

Which side the leaf is worked from, and so which way it swings. Omitted keeps the side it was last worked from.

boolean

False when the door is already that way.


setVirtualWorld(world): void

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

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

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


toJSON(): DoorDefinition | null

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

The definition Door.spawn takes to hang this door again, with whether it is locked now: what a script saves. The server keeps nothing past a restart. It is one entry of a World Builder map’s doors array.

DoorDefinition | null

Null for a door the level places.


toString(): string

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

Formats this door handle for logging and debugging.

string

The door ID, its level GUID and whether it is open and locked.

Entity.toString


static all(): Door[]

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

Lists every door: the level’s own, all of which exist from boot in the global world, and every door a script or a world resource hung. In another virtual world a level door is built the first time anything there reaches it, so this lists only those. A level door taken out of a world is not listed for it; Door.removed lists those.

Door[]

One handle per known door, in no particular order.


static find(guid, virtualWorld?): Door | null

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

Looks a door up by the level’s own identity for it, which survives a restart and is the same on every machine. A door the level places is found in any virtual world it has not been taken out of. A door a script hung is found by door.guid in the world it hangs in.

string

The door’s level EntityGuid as hex, with or without an 0x prefix, as door.guid prints it.

number

Optional virtual world to look in; omitted looks in the global one, where every body starts.

Door | null

The door’s handle, or null when there is no such door there.


static getById(id): Door | null

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

Looks a door up by its network entity ID.

number

Network entity identifier.

Door | null

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


static getForArea(areaId): AreaDoor[]

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

Lists the doors the level links to an area as its crime_doors, with their GUID, name, position and link type, straight from the level catalog – so a door that no client has reported yet is listed too. Pass a guid to Door.find for the live handle and its locked state. Only native links: a script area has none.

string

The area’s id, as area.id prints it.

AreaDoor[]

The doors; empty for an unknown area or one with no links.


static models(): DoorModelInfo[]

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

Lists every leaf mesh the shipped levels hang doors from, which is every model Door.spawn takes.

DoorModelInfo[]

One row per mesh, sorted by path.


static queryNearest(player): Promise<NearestDoor>

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

Asks a player’s client which door their body is standing at. The server knows every door the level places but has no world to measure distances in, so this is how a command finds the door in front of a player, and the answer is what that client sees now rather than what the replica last carried.

The promise always settles: on the answer, on a five-second timeout, or when the player leaves, with found false and reason saying which.

Player

The player to ask. The question goes to their own client.

Promise<NearestDoor>

The answer, once that client has given one.


static remove(guid, virtualWorld?): void

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

Takes a door the level places out of a virtual world, collision and all, as door.destroy() does, without needing its handle. Taking out a door that is already out of that world, or of the global one, does nothing; taking out one that has a level edit in that world, a move or a swap, replaces that edit.

string

The level door’s EntityGuid as hex, as door.guid prints it.

number

Optional virtual world to take it out of; the global one, and so every world, when omitted.

void

Throws for a GUID that is not one of the level’s doors.


static removed(virtualWorld?): RemovedDoor[]

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

Lists the doors the level places that are taken out of a virtual world, by a script or a World Builder export alike.

number

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

RemovedDoor[]

One row per removal, in no particular order.


static restore(guid, virtualWorld?): Door | null

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

Puts back a level door that a script, a world resource or any other level edit took out of a virtual world. It comes back closed, and locked as the level builds it.

string

The level door’s EntityGuid as hex, as Door.removed lists it.

number

Optional virtual world to put it back in; the global one when omitted. A door taken out of the global world is only put back from there.

Door | null

The door, or null when that world had no such removal.


static spawn(definition, virtualWorld?): Door

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

Hangs a working door where the level has none: every player in the virtual world sees it, opens and closes it, keys or picks its lock, and the server judges every use by the same rules as the level’s own doors. It starts closed. Kept in memory only: hang it again on boot. The resource that hangs it owns it, so it goes when that resource stops. NPCs do not path through it: the level’s navigation mesh has no link for it.

DoorDefinition

The leaf, where it hangs and how it locks, in the format of one entry of a World Builder map’s doors array.

number

Optional virtual world whose players see it; the global one when omitted.

Door

The door. Throws for an unknown model, a transform that is not finite, a lock name that is not one of the four, or a key that is not an item class.

readonly areas: Area[]

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

The level areas that link this door as one of their crime_doors – the house, workshop or storage room it belongs to, as the level itself records it. Nothing is inferred from where the door stands.


readonly guid: string

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

The door’s EntityGuid, as sixteen lowercase hex digits, the same on every machine; Door.find takes it back. A level door’s never changes, so it is the identity to store one under. A hung door’s lasts only until the server stops: store its toJSON() instead.


readonly id: number

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

Immutable network entity identifier.

Entity.id


readonly keyItem: string

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

The item class GUID of the key the level assigns to the door’s keyhole, as player.giveItem takes it. Empty when it takes none of its own – most doors open to the generated home or shop key instead. The server does not see inventories, so this is for a resource that keeps its own.


locked: boolean

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

Whether the door is locked. Assignment reaches every client that has the door streamed in, including one already standing at it. A door locked from here can only be opened again from here or with a lockpick: a player unlocking it by hand or with a key is refused.


readonly lockedByServer: boolean

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

Whether the lock was set by a script or an operator rather than by the level. It clears when the door is unlocked, by any route the server accepted.


readonly lockpickable: boolean

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

Whether the level lets this door be lockpicked. A lockpick reported on one that cannot be is refused.


readonly model: string

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

The leaf mesh the door hangs, as Door.models() lists it: objects/characters/assets/doors/...cdf.


readonly name: string

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

The entity name the level gives the door; for a hung door, the name it was hung with, or spawned_door_<n> without one.


readonly open: boolean

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

Whether the door is standing open. Change it with setOpen, which also says which way it swings.


readonly openedFromFront: boolean

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

Which side the leaf was last worked from, which decides the way it swings. A player arriving later poses the door from this, so everyone sees it swung the same way.


position: Vector3

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

Authoritative world-space position; assignment forces replicated state.

Entity.position


rotation: Vector3 | Quaternion

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

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

Entity.rotation


readonly spawned: boolean

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

Whether a script or a world resource hung this door with Door.spawn, rather than the level placing it.


readonly startsLocked: boolean

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

Whether the level builds this door locked, which is the state it has at boot; for a hung door, whether it was hung locked.


readonly state: StateBag

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

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 stateToken: number

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

Bumped on every durable change. Clients act on the edges rather than the value, so it only tells one change from the next.


usable: boolean

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

Whether players may work the door. False hides its prompt to open, close, unlock or pick it, and a player’s use is refused on their own machine before the door or the body moves – no round trip, no swing back. A report against it is refused here too, for a client that did not. Assignment reaches every client that has the door streamed in, including one already standing at it. The door stays as it is: setOpen and locked still work, and NPCs still pass it. Per door, not per player: refuse one player with a client doorInteract handler.


readonly virtualWorld: number

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

Current virtual-world identifier.

Entity.virtualWorld