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

SiegeEngine

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

Replicated handle for a trebuchet or a cannon.

new SiegeEngine(id): SiegeEngine

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

Creates a script wrapper for an existing siege engine with this ID; use SiegeEngine.spawn() to build one.

number

Network entity identifier.

SiegeEngine

Entity.constructor

aim(target): SiegeResult

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

Turns the engine to face a point without shooting. fire turns it anyway; this is for showing where it will shoot.

Vector3 | Partial<Vector3>

The point to turn towards.

SiegeResult

What happened, and the phrase to explain it with when nothing did.


canHit(target): string

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

Whether the engine can reach a point from where it stands.

Vector3 | Partial<Vector3>

The point to test.

string

Empty when it can; otherwise why not, as a phrase.


destroy(): void

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

Removes the engine on every client after emitting siegeEngineDestroy. A projectile already in the air still lands.

void


fire(target, attacker?): SiegeResult

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

Turns a loaded engine to face the target and shoots at it. A trebuchet’s arm lets the stone go at one angle, so its speed is solved for the distance; a cannon fires at one speed, so its elevation is. The stone is let go partway through the shot (seconds), then every client nearby draws it along the same arc. It comes down where the world stops it, which the attacker is asked to report when near enough, else the player nearest the target, or on the target when nobody can.

Vector3 | Partial<Vector3>

Where the projectile should come down.

number | Player | null

The player credited with whatever it hits, in playerDamage, npcDamage and siegeImpact.

SiegeResult

What happened, and the phrase to explain it with when nothing did.


getAimGuide(): boolean

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

Whether the operator sees the aim guide; see setAimGuide.

boolean

True when the beam is shown.


load(): SiegeResult

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

Starts the reload cycle of an idle engine. siegeEngineReady fires when it can shoot.

SiegeResult

What happened, and the phrase to explain it with when nothing did.


repair(): void

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

Makes the engine whole again: health back to maxHealth, and a wreck idle and unloaded.

void


setAimGuide(enabled): void

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

Shows or hides the operator’s aim guide: a translucent red beam along the shot’s path – out of a trebuchet’s sling and along its arc, or straight from a cannon’s muzzle – to where it would come down, with a ball there. Off by default, which leaves laying the engine to the eye; the Fire hint says how far the shot goes either way.

boolean

Whether the operator sees the beam.

void


setOperator(player): boolean

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

Puts a player in the engine’s place without asking them, or takes whoever is there out of it. A player holds one place at a time, so they leave any other engine or winch first. Raises no siegeEngineUse.

Player | null

Who takes the engine’s place, or null to empty it.

boolean

False for a player who is no longer connected.


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

Formats this engine handle for logging and debugging.

string

The engine ID, its kind and where it is in its cycle.

Entity.toString


static all(virtualWorld?): SiegeEngine[]

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

Lists the siege engines the server has.

number

Optional virtual world to list; omitted lists every one.

SiegeEngine[]

One handle per engine, in no particular order.


static destroyAll(virtualWorld?): number

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

Removes siege engines, emitting siegeEngineDestroy for each one.

number

Optional virtual world to clear; omitted clears every one.

number

How many were removed.


static getById(id): SiegeEngine | null

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

Looks an engine up by its network entity ID.

number

Network entity identifier.

SiegeEngine | null

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


static spawn(kind, position, rotation?, virtualWorld?): SiegeEngine

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

Builds and replicates a siege engine, unloaded. The trebuchet is the game’s own model and plays its own winch, load and fire animations; the cannon is the game’s static gun.

string

trebuchet or cannon.

Vector3 | Partial<Vector3>

World-space position of the engine’s base.

Vector3 | Quaternion

Optional initial orientation: a Quaternion, or a Vector3 of Euler angles in degrees. fire and aim turn it to face their target.

number

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

SiegeEngine

The new engine’s handle.

ammo: number

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

Shots left to load; each load takes one, and an engine with none refuses to load. -1, the default, never runs out; any negative value means the same.


readonly crew: (Player | null)[]

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

Who mans each winch, in place order, with null for an empty one.


readonly crewPlaces: number

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

How many winches the engine has: 2 on a trebuchet, 0 on a cannon.


crewRequired: number

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

How many of the engine’s winches must be manned for its arm to be winched down; 0, the default, winds it by itself. With fewer hands than this the winding holds where it is, and goes on when they come back. Players near a usable engine that needs them are offered its winches, and each one there plays the game’s own pull. Kept to crewPlaces.


readonly cycle: string

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

Where the engine is in its cycle: idle (unloaded), drawing (a trebuchet’s arm being winched down), loading (the crew laying the projectile), ready or firing. Named cycle because every entity already has a state, which is its state bag.


damage: number

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

Health taken from anything at the point of impact; a player has 100. A quarter of it reaches the edge of damageRadius. 0 leaves hits to siegeImpact.


damageRadius: number

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

How far from the point of impact anything is hurt, in metres, up to 100.


health: number

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

What is left of maxHealth. Setting it to 0 wrecks the engine and raising it from 0 repairs one; ignored while maxHealth is 0.


readonly id: number

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

Immutable network entity identifier.

Entity.id


readonly kind: string

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

What the engine is: trebuchet or cannon. The game ships no catapult and no ballista.


readonly loadDuration: number

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

How long load takes at the engine’s speed, in seconds.


readonly loaded: boolean

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

Whether the engine is ready to fire.


maxHealth: number

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

What the engine can take before it is wrecked; 0, the default, means nothing harms it. Setting it heals the engine to the new maximum and repairs a wreck. A blast within damageRadius of an engine – any engine’s, its own included – takes its share of that shot’s damage off it, raising siegeEngineDamage.


readonly maxRange: number

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

The furthest the engine can be aimed, in metres along the ground.


readonly minRange: number

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

The closest the engine can be aimed, in metres along the ground.


readonly operator: Player | null

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

The player in the engine’s place, or null. They lay it where they look while they hold the block key, load it with the torch key, fire it with the attack key and step away with the use key; walking off lets go of it too. setOperator puts somebody there.


position: Vector3

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

Authoritative world-space position; assignment forces replicated state.

Entity.position


range: number

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

How far a shot goes along the operator’s facing when they fire before laying the engine anywhere, in metres; kept between minRange and maxRange. 150 for a trebuchet and 120 for a cannon to start with.


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


speed: number

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

How fast the cycle runs, from 0.1 to 20; 1 is the game’s own pace, which takes a trebuchet’s crew nearly two minutes to load and lets the stone go 3.5 seconds into the shot. Changing it mid-step carries on from where the engine has got to.


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


usable: boolean

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

Whether players may work the engine. A player within 2 m of an empty one gets the game’s own action hint on the use key to take its place, and becomes its operator; near a trebuchet with a crewRequired, a free winch is offered too. Each ask raises siegeEngineUse first, which may refuse it. Off by default.


readonly virtualWorld: number

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

Current virtual-world identifier.

Entity.virtualWorld


readonly wrecked: boolean

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

Whether the engine’s health ran out. A wrecked cannon shows the game’s broken gun and a wrecked trebuchet leans and settles; nothing loads, aims or fires it, and its operator and crew are let go, until repair or a new maxHealth.