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

Stash

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

Container handle for a spawned chest, a level chest, or virtual stock without a world entity.

new Stash(id): Stash

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

Creates a script wrapper for an existing container with this ID; use Stash.spawn() for a chest, Stash.createVirtual() for stock without a chest, or Stash.find() for one the level places.

number

Network entity identifier.

Stash

Entity.constructor

addItem(request): InventoryResult

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

Puts items in the container, as Inventory.add gives them to a player.

number

string

Record<string, unknown>

number

InventoryResult


destroy(): void

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

Destroys this scripted chest or virtual stash and forgets what was in it. Anything inside goes with it. Does nothing to a container the level places.

void


getInventory(): { items: InventoryRow[]; revision: number; } | null

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

Reads what the container holds. A linked child reads its master’s.

{ items: InventoryRow[]; revision: number; } | null

A copy of its rows, or null once the container is gone.


open(player): boolean

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

Opens a virtual stash from anywhere in its virtual world. Calls stashInteract before granting exclusive access. Returns false for a physical stash, a locked or busy stash, an unavailable player, or a script refusal. A true result requests the screen; the client releases access if it cannot open.

Player

Player whose native transfer screen should open.

boolean


removeItem(request): InventoryResult

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

Takes exact units out of named rows, every one of them or none.

number

InventoryUnit[]

InventoryResult


setInventory(request): InventoryResult

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

Replaces everything in the container, which is how saved contents come back. At most 128 rows. An empty list empties it.

object[]

number

InventoryResult


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


toString(): string

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

Formats this container handle for logging and debugging.

string

The stash ID, its level GUID, how much is in it, who has it open and whether it is locked.

Entity.toString


static all(): Stash[]

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

Lists every container the server currently has: every one the level places, which exist from boot in the global world, and every scripted chest or virtual stash. In another virtual world a level container is built the first time anything there reaches it, so this lists only those.

Stash[]

One handle per live container, in no particular order.


static createVirtual(virtualWorld?): Stash

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

Creates empty server-owned stock without spawning a chest on any client. Supports the same inventory methods and events as physical stashes. Use open(player) to show the native transfer screen, and destroy() to discard it. Contents last until destroyed or the server restarts.

number

World whose players may open it, as a uint32 number; defaults to the global world. Invalid values throw before creating stock.

Stash


static destroyAll(virtualWorld?): number

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

Destroys scripted chests and virtual stashes, including everything inside. The level’s own stay.

number

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

number

How many containers were removed.


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

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

Looks a container up by its EntityGuid: one the level places, by the level’s own identity for it, which survives a restart and is the same on every machine, and is found in any virtual world; or one a script spawned, in the virtual world it was spawned in, for as long as it exists.

string

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

number

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

Stash | null

The container’s handle, or null when no container has that GUID there.


static getById(id): Stash | null

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

Looks a container up by its network entity ID.

number

Network entity identifier.

Stash | null

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


static nearest(position, maxDistance?, virtualWorld?): Stash | null

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

Finds the physical container nearest a point, level or spawned. Virtual stock is excluded. The server knows where every container the level places stands, so this answers at once, without asking a client.

Vector3 | Partial<Vector3>

The point to measure from, usually a player’s position.

number

How far to look, in metres; omitted looks 5 m, about the reach the game gives a chest.

number

Optional virtual world to look in; omitted looks in the global one.

Stash | null

The nearest container’s handle, or null when none is that close.


static spawn(position?, rotation?, virtualWorld?): Stash

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

Spawns and replicates an empty container. Fill it with addItem or setInventory, or let players put things in it.

Vector3 | Partial<Vector3>

Optional world-space spawn position; omitted components default to zero.

Vector3 | Quaternion

Optional initial orientation: a Quaternion, or a Vector3 of Euler angles in degrees.

number

Optional virtual world the container belongs to; omitted puts it in the global one.

Stash

The newly spawned container handle.

readonly guid: string

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

The EntityGuid every client finds this container under, as sixteen lowercase hex digits: the level’s own for a container the level places, the one minted when a script spawned it otherwise. Empty for virtual stock; Stash.find takes physical container GUIDs back.


readonly holderId: number

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

The network ID of the player who has its contents open, or 0. While it is held, every other player’s open is refused before their transfer screen appears.


readonly id: number

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

Immutable network entity identifier.

Entity.id


readonly isOpen: boolean

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

Whether a player holds its view. Physical chests animate their lid by it; virtual stashes have no lid.


readonly isVirtual: boolean

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

Whether this stash has stock without a chest entity. Open it with open(player); its position and rotation do not govern access, and guid is empty.


readonly itemCount: number

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

How many rows the server is holding. A container linked to another in the level opens that one’s contents, and reads them here too.


keyItem: string

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

The item class GUID of the key that unlocks the container, as player.giveItem takes it. Reads the level’s own key until a script assigns one; empty when it has none. Assigning a class makes every client ask for that class instead, so a player holding it is offered “unlock and open”; assigning an empty string restores the level’s. An unknown class is refused and logged. The server does not see inventories: which key a player holds is their client’s to say, and stashInteract is where a script checks its own record.


readonly levelGuid: string

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

The level’s own EntityGuid for a container the level places, as sixteen lowercase hex digits; empty for a scripted chest or virtual stock. The same on every machine, so it is the identity to store a container under; Stash.find takes it back.


locked: boolean

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

Whether the container is locked. Assignment reaches every client that has it streamed in. A locked container offers only its key and its lockpick; a script locking one marks it lockedByServer, which the generated home or shop key does not open. Unlocking it by any route the server accepted clears both.


readonly lockedByServer: boolean

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

Whether the lock was set by a script rather than by the level. The generated home or shop key does not open a container locked from here.


lockpickable: boolean

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

Whether the container offers the lockpick while locked. Starts as the level authored it; assignment reaches every client, and a pick on one that cannot be is refused.


readonly name: string

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

The entity name the level gives the container, or spawned_stash_<stashId> for a scripted chest; empty for virtual stock.


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 startsLocked: boolean

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

Whether the level builds this container locked, which is the state it has at boot. False for one a script spawned.


readonly stashId: number

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

The server-minted identity of a scripted chest or virtual stash, from 1. Distinct from the network entity id. Virtual stashes use it for an inventory GUID without creating a chest. 0 for a level chest.


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 useDirection: Vector3

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

The horizontal unit direction a player has to face the container along to be offered it: the game’s own use check only offers a chest to a body standing behind this axis and looking along it. Stand at position - useDirection * distance to face it.


readonly virtualWorld: number

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

Current virtual-world identifier.

Entity.virtualWorld