Skip to content

atl::script

Script classes: the Rust traits for parts, tools, characters, worlds, games and terrain, split server/client classes, and the registration that exposes them.

pub struct InputBlock

What a tool's client_on_equipped_update returns: whether to block the primary / secondary input from reaching the game.

Fields

pub primary: bool
pub secondary: bool

Implements Clone, Copy, Debug, Default, Eq, IntoLua, PartialEq

pub struct CullingZoneTree

Culling portals and zones.

Fields

pub portals: Value
pub zones: Value

Implements Clone, Debug, Default, IntoLua

pub struct ClassBuilder<T>

The registration of a script class; #[atl::class] builds one. Chain .method("name", T::name) to add custom methods.

Methods

pub fn new(name: &'static str) -> Self

Starts registering T as script class name.

pub fn callback<M>(mut self, name: &'static str, h: impl Handler<T, M>) -> Self

Adds an engine callback under its game name.

pub fn method<M>(self, name: &'static str, h: impl Handler<T, M>) -> Self

Adds a custom method callable from Lua or the network (e.g. a send_to_server target), with its parameters converted from Lua by type.

pub fn client_destroy<M>(mut self, h: impl Handler<T, M>) -> Self

Sets the class's own client_onDestroy, which runs before its resources are freed.

pub fn register(self)

Adds the class to the registry.

pub fn terrain(mut self) -> Self

Marks the class as a terrain script: Init always exists, and GetHeightAt / GetClutterIdxAt get the fast path.

pub struct ServerBuilder<T>

The registration of the server half of a split class; #[atl::server] builds one.

Methods

pub fn new(class_name: &'static str, type_name: &'static str) -> Self

Registers T (named type_name in messages) as the server half of class_name.

pub fn callback<M>(self, name: &'static str, h: impl Handler<T, M>) -> Self

Adds an engine callback under its game name. The game only calls it on the server.

pub fn method<M>(self, name: &'static str, h: impl Handler<T, M>) -> Self

Adds a network target or other custom method of this half. It only runs on the server: a call that arrives on a client is logged and dropped.

pub fn on<M, H: ServerHandler<T, M>>(self, h: H) -> Self

Adds a typed-message handler: fn(&mut self, &Msg) or fn(&mut self, &Msg, Player).

pub fn register(self)

Finishes the registration.

pub struct ClientBuilder<T>

The registration of the client half of a split class; #[atl::client] builds one.

Methods

pub fn new(class_name: &'static str, type_name: &'static str) -> Self

Registers T (named type_name in messages) as the client half of class_name.

pub fn callback<M>(self, name: &'static str, h: impl Handler<T, M>) -> Self

Adds an engine callback under its game name. The game only calls it on clients.

pub fn method<M>(self, name: &'static str, h: impl Handler<T, M>) -> Self

Adds a network target or other custom method of this half. It only runs on clients: a call that arrives on the server is logged and dropped.

pub fn client_destroy<M>(self, h: impl Handler<T, M>) -> Self

Sets the half's own on_destroy.

pub fn client_data<M>(self, h: impl Handler<T, M>) -> Self

Sets the half's own on_client_data_update, for client data that isn't a typed message.

pub fn on<M, H: ClientHandler<T, M>>(self, h: H) -> Self

Adds a typed-message handler: fn(&mut self, &Msg).

pub fn register(self)

Finishes the registration.

pub struct ModCell<T>(Global<Option<Rc<RefCell<T>>>>)

Holds the export_mod! instance, created on first use.

Methods

pub const fn new() -> Self
pub fn with(&'static self, f: impl FnOnce(&mut T) + 'static)

Runs f on the mod object (deferred if it is already running).

Implements Default

pub struct ChatParam

One parameter of a chat command: its type ("int", "string", ...), name, and whether it's optional.

Fields

pub kind: &'static str
pub name: &'static str
pub optional: bool

Implements Clone, Copy, Debug

pub struct ServerNetwork(Network)

The server half's network: sends to the client halves. Every method is server-only.

Methods

pub fn new(n: Network) -> Self

Wraps self.network.

pub fn send_to_clients(&self, method: &str, data: impl IntoLua)

[server] Calls method(data) on every client half.

pub fn send_to_client(&self, player: &Player, method: &str, data: impl IntoLua)

[server] Calls method(data) on one player's client half.

pub fn set_client_data(&self, data: impl IntoLua, channel: i32)

[server] Syncs data to on_client_data_update on every client half, including players who join later.

pub fn send<M: Message>(&self, msg: &M)

[server] Sends a typed message to every client half, where .on() receives it. Messages up to wire::MAX_MESSAGE_BYTES are split into packets as needed and reassembled on arrival.

pub fn send_to(&self, player: &Player, msg: &impl Message)

[server] Sends a typed message to one player's client half.

pub fn sync<M: Message>(&self, state: &M, channel: i32)

[server] Like send, but kept: players who join later get the latest state too. One state per channel (1 or 2); a newer sync replaces the older one. A synced state must fit in one packet (wire::CHUNK_BYTES encoded); a bigger one is logged and not sent.

pub struct ClientNetwork(Network)

The client half's network: sends to the server half.

Methods

pub fn new(n: Network) -> Self

Wraps self.network.

pub fn send_to_server(&self, method: &str, data: impl IntoLua)

Calls method(data, sender) on the server half.

pub fn send<M: Message>(&self, msg: &M)

Sends a typed message to the server half, where .on() receives it.

pub enum Side

Which side may call a method. Engine callbacks are Any: the game already only calls server_* on the server. A split class's custom methods are pinned to their half.

Variants

  • Any
  • Server
  • Client

Implements Clone, Copy, Debug, Eq, PartialEq

pub trait FromArgs: Sized

A callback parameter read from the game's arguments. FromLua types read one argument; the hit structs (ProjectileHit, ...) read several.

Trait items

fn from_args(args: &Value, i: &mut i32) -> Self

Reads the value starting at args[i] and advances i past it.

pub trait Handler<T, M>: 'static

A function the game can call on a script object: fn(&mut T, params...) -> R, with FromArgs parameters and an IntoLua result.

Trait items

fn invoke(&self, obj: &mut T, args: &Value) -> Value

Converts the arguments, calls the function and converts its result.

pub trait ServerHandler<T, M>: 'static

A typed-message handler of a server half: fn(&mut T, &Msg), optionally with a third Player sender.

Trait items

type Msg: Message

The message type.

pub trait ClientHandler<T, M>: 'static

A typed-message handler of a client half: fn(&mut T, &Msg).

Trait items

type Msg: Message

The message type.

pub trait Mod: Default + 'static

Mod-wide lifecycle, independent of any part: implement it and use export_mod!(MyMod). The loader's runtime tool (or a custom game's script) calls these once per tick.

Trait items

fn server_on_create(&mut self)

[server] Called once when the mod starts.

fn server_on_fixed_update(&mut self, dt: f64)

[server] Called every physics tick (40 per second); dt is in seconds.

fn server_on_destroy(&mut self)

[server] Called when the mod shuts down.

fn client_on_create(&mut self)

[client] Called once when the mod starts.

fn client_on_fixed_update(&mut self, dt: f64)

[client] Called every physics tick.

fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

fn client_on_destroy(&mut self)

[client] Called when the mod shuts down.

script_class!

A part or block script (scriptClass for a shape).

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn shape(&self) -> Shape

The shape this script runs on.

fn interactable(&self) -> Interactable

The shape's interactable.

fn client_on_interact(&mut self, character: Character, pressed: bool)

[client] Called when a player presses / releases the interact key on the part.

fn client_can_interact(&mut self, character: Character) -> bool

[client] Whether the part can be interacted with now; also the place to set the interaction text.

fn client_on_tinker(&mut self, character: Character, pressed: bool)

[client] Called when a player presses / releases the tinker key on the part.

fn client_can_tinker(&mut self, character: Character) -> bool

[client] Whether the part can be tinkered with now.

fn client_on_action(&mut self, action: i32, pressed: bool)

[client] Called for movement and other input actions while a player is seated in the part.

fn server_can_erase(&mut self) -> bool

Whether the part may be removed now.

fn client_can_erase(&mut self) -> bool
fn client_can_carry(&mut self) -> bool

[client] Whether the part may be picked up.

fn server_on_unload(&mut self)

[server] Called when the part unloads with its cell.

fn server_on_sledgehammer(&mut self)

[server] Called when the part is hit with a sledgehammer.

fn server_on_projectile(&mut self, hit: ProjectileHit)

Called when a projectile hits the part.

fn client_on_projectile(&mut self, hit: ProjectileHit)
fn server_on_melee(&mut self, hit: MeleeHit)

Called when a melee attack hits the part.

fn client_on_melee(&mut self, hit: MeleeHit)
fn server_on_explosion(&mut self, center: Vec3, destruction_level: i32, damage: i32)

[server] Called when an explosion hits the part.

fn server_on_collision(&mut self, hit: CollisionHit)

Called when the part collides with something.

fn client_on_collision(&mut self, hit: CollisionHit)
fn client_on_interact_through_joint(&mut self, character: Character, pressed: bool, joint: Joint)

[client] Called when interacting through a child joint (e.g. a bearing). pressed is always true.

fn client_can_interact_through_joint(&mut self, character: Character, joint: Joint) -> bool

[client] Whether interacting through a child joint is allowed.

fn client_get_available_parent_connection_count(&mut self, flags: Connection) -> i32

[client] How many more parent / child connections of type flags are allowed (1+ allows one). Only called when the class's maxParentCount / maxChildCount field is 1 or more.

fn client_get_available_child_connection_count(&mut self, flags: Connection) -> i32
fn client_on_child_joint_removed(&mut self, joint: Joint)

[client] Called when a child joint is removed.

fn server_on_world_changed(&mut self)

[server] Called when the part moves to another world.

script_class!

A tool script.

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn tool(&self) -> Tool

The tool this script runs on.

fn owner(&self) -> Player

The player holding the tool.

fn is_local(&self) -> bool

True on the client of the player who owns the tool.

fn is_equipped(&self) -> bool

True while the tool is equipped.

fn client_on_equip(&mut self, animate: bool)

[client] Called when the tool is equipped / unequipped.

fn client_on_unequip(&mut self, animate: bool)
fn client_on_equipped_update(&mut self, primary_state: i32, secondary_state: i32) -> InputBlock

[client] Called every frame while equipped with the primary and secondary input states. Return which inputs to block from the game.

fn client_on_toggle(&mut self) -> bool

[client] Called on the toggle / reload key; return true to consume the key.

fn client_on_reload(&mut self) -> bool
fn client_can_equip(&mut self) -> bool

[client] Whether the tool can be equipped now.

script_class!

A character script (scriptClass for a character type).

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn character(&self) -> Character

The character this script runs on.

fn client_on_graphics_loaded(&mut self)

[client] Called when the character's graphics load / unload.

fn client_on_graphics_unloaded(&mut self)
fn client_on_interact(&mut self, character: Character, pressed: bool)

[client] Called when a player interacts with the character.

fn client_can_interact(&mut self, character: Character) -> bool

[client] Whether the character can be interacted with now.

fn client_on_event(&mut self, event: String)

[client] Called for animation events.

fn client_on_projectile(&mut self, hit: ProjectileHit)

[client] Called when the character is hit by a projectile, a melee attack or a collision.

fn client_on_melee(&mut self, hit: MeleeHit)
fn client_on_collision(&mut self, hit: CollisionHit)
script_class!

A harvestable script (trees, rocks, crops...).

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn harvestable(&self) -> Harvestable

The harvestable this script runs on.

fn server_on_unload(&mut self)

[server] Called when the harvestable unloads with its cell.

fn client_on_interact(&mut self, character: Character, pressed: bool)

[client] Called when a player interacts with the harvestable.

fn client_can_interact(&mut self, character: Character) -> bool

[client] Whether the harvestable can be interacted with now.

fn client_on_action(&mut self, action: i32, pressed: bool)

[client] Called for input actions.

fn server_can_erase(&mut self) -> bool

Whether the harvestable may be removed now.

fn client_can_erase(&mut self) -> bool
fn server_on_removed(&mut self, player: Player)

[server] Called when a player removes the harvestable.

fn server_on_ignite(&mut self)

[server] Called when the harvestable catches fire.

fn server_on_floating(&mut self)

[server] Called when the harvestable starts floating.

fn server_on_projectile(&mut self, hit: ProjectileHit)

Called when the harvestable is hit by a projectile, melee attack, explosion or collision.

fn client_on_projectile(&mut self, hit: ProjectileHit)
fn server_on_melee(&mut self, hit: MeleeHit)
fn client_on_melee(&mut self, hit: MeleeHit)
fn server_on_explosion(&mut self, center: Vec3, destruction_level: i32, damage: i32)
fn server_on_collision(&mut self, hit: CollisionHit)
fn client_on_collision(&mut self, hit: CollisionHit)
script_class!

A unit script: the AI that controls a creature, server only.

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn unit(&self) -> Unit

The unit this script runs on.

fn server_on_unit_update(&mut self, dt: f64)

[server] Called every AI update.

fn server_on_projectile(&mut self, hit: ProjectileHit)

[server] Called when the unit's character is hit by a projectile, melee attack, explosion or collision.

fn server_on_melee(&mut self, hit: MeleeHit)
fn server_on_explosion(&mut self, center: Vec3, destruction_level: i32, damage: i32)
fn server_on_collision(&mut self, hit: CollisionHit)
fn server_on_collision_crush(&mut self)

[server] Called when the character is crushed.

fn server_on_character_changed_color(&mut self, color: Color)

[server] Called when the character's color changes.

script_class!

A player script (the game's player class).

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn player(&self) -> Player

The player this script runs on.

fn client_on_interact(&mut self, character: Character, pressed: bool)

[client] Called when the player interacts with a character.

fn client_on_cancel(&mut self)

[client] Called on the cancel, skip dialog and reload keys.

fn client_on_skip_dialog(&mut self)
fn client_on_reload(&mut self)
fn server_on_projectile(&mut self, hit: ProjectileHit)

[server] Called when the player's character is hit by a projectile, melee attack, explosion or collision.

fn server_on_melee(&mut self, hit: MeleeHit)
fn server_on_explosion(&mut self, center: Vec3, destruction_level: i32, damage: i32)
fn server_on_collision(&mut self, hit: CollisionHit)
fn server_on_collision_crush(&mut self)

[server] Called when the player's character is crushed.

fn server_on_shape_removed(&mut self, items: Value)

[server] Called with the items a removed shape gave the player.

fn server_on_inventory_changes(&mut self, inventory: Container, changes: Value)

[server] Called when the player's inventory changes.

script_class!

A world script.

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn world(&self) -> World

The world this script runs on.

fn server_on_unload(&mut self)

[server] Called when the world unloads.

fn server_on_terrain_created(&mut self)

Called when the world's terrain is first created / loaded.

fn server_on_terrain_loaded(&mut self)
fn client_on_terrain_created(&mut self)
fn client_on_terrain_loaded(&mut self)
fn server_on_cell_created(&mut self, x: i32, y: i32)

[server] Called when a cell is first created, loaded or unloaded.

fn server_on_cell_loaded(&mut self, x: i32, y: i32)
fn server_on_cell_unloaded(&mut self, x: i32, y: i32)
fn client_on_cell_loaded(&mut self, x: i32, y: i32)

[client] Called when a cell is loaded / unloaded.

fn client_on_cell_unloaded(&mut self, x: i32, y: i32)
fn server_on_interactable_created(&mut self, interactable: Interactable)

[server] Called when an interactable is created / destroyed in the world.

fn server_on_interactable_destroyed(&mut self, interactable: Interactable)
fn server_on_projectile(&mut self, hit: WorldProjectileHit)

Called when a projectile hits something in the world.

fn client_on_projectile(&mut self, hit: WorldProjectileHit)
fn server_on_projectile_fire(&mut self, position: Vec3, velocity: Vec3, projectile: String, shooter: Target, uuid: Uuid)

[server] Called when a projectile is fired in the world.

fn server_on_melee(&mut self, hit: WorldMeleeHit)

[server] Called when a melee attack hits something in the world.

fn server_on_explosion(&mut self, center: Vec3, destruction_level: i32, damage: i32)

[server] Called when an explosion happens in the world.

fn server_on_collision(&mut self, hit: WorldCollision)

Called on collisions in the world.

fn client_on_collision(&mut self, hit: WorldCollision)
fn server_on_voxel_destruction(&mut self, density_loss: Value, positions: Value)

[server] Voxels removed / added by a player or creation: per-material density tables and positions.

fn server_on_voxel_construction(&mut self, density_gain: Value, positions: Value)
fn server_on_mining(&mut self, spawns: Vec<MineSpawn>)

[server] Mining loot to spawn (see World::set_mining_config).

script_class!

A scriptable object script: a script with no body in the world.

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn scriptable_object(&self) -> ScriptableObject

The scriptable object this script runs on.

fn params(&self) -> Value

The params it was created with.

fn server_on_unload(&mut self)

[server] Called when the object unloads.

script_class!

A scriptable object that exists on one client only (client_scriptable_objects::create).

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn scriptable_object(&self) -> ClientScriptableObject

The scriptable object this script runs on.

fn params(&self) -> Value

The params it was created with.

script_class!

A terrain generation script. The world class's terrainScript file runs one per generator thread, each in its own Lua state. Implement what your terrain provides; the engine calls Init, then Load (or Create when Load returns false), then PrepareCell before each cell's Get* queries. The Lua side is sm.allthelanguages.terrainScript.

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn init(&mut self, world: World, generator_index: i32)

Called first, with the world and this generator thread's index.

fn load(&mut self) -> bool

Loads saved terrain data. Return true if it was loaded; false makes the engine call Create.

fn create(&mut self, x_min: i32, x_max: i32, y_min: i32, y_max: i32, seed: i32, data: Value)

Generates new terrain data for the given cell bounds and seed.

fn prepare_cell(&mut self, cell_x: i32, cell_y: i32, load_flags: i32)

Called before a cell's queries. load_flags bits: creations, surface, assets, nodes, harvestables, kinematics.

fn get_tile_path(&mut self, tile: Uuid) -> String

The file path of a tile uuid.

fn get_height_at(&mut self, x: f64, y: f64, lod: i32) -> f64

Per-vertex queries in world coordinates: height, color and the 8 material weights. get_height_at and get_clutter_idx_at take a fast path that skips the handle table.

fn get_color_at(&mut self, x: f64, y: f64, lod: i32) -> TerrainColor
fn get_material_at(&mut self, x: f64, y: f64, lod: i32) -> MaterialWeights
fn get_clutter_idx_at(&mut self, x: f64, y: f64) -> i32

The clutter index at a point, or -1 for none.

fn get_effect_material_at(&mut self, x: f64, y: f64) -> String

The effect material at a point (used for footstep and impact sounds).

fn get_assets_for_cell(&mut self, cell_x: i32, cell_y: i32, lod: i32) -> Value

Per-cell contents: arrays of the engine's terrain tables (sm::terrain_tile returns them too).

fn get_nodes_for_cell(&mut self, cell_x: i32, cell_y: i32) -> Value
fn get_creations_for_cell(&mut self, cell_x: i32, cell_y: i32) -> Value
fn get_harvestables_for_cell(&mut self, cell_x: i32, cell_y: i32, lod: i32) -> Value
fn get_kinematics_for_cell(&mut self, cell_x: i32, cell_y: i32, lod: i32) -> Value
fn get_decals_for_cell(&mut self, cell_x: i32, cell_y: i32, lod: i32) -> Value
fn get_tags_for_cell(&mut self, cell_x: i32, cell_y: i32) -> Vec<String>

A cell's tags.

fn get_ocean_cells(&mut self) -> Value

Cells covered by ocean: {{cellX, cellY}, ...}.

fn get_h_lod_cells(&mut self) -> Value

High level-of-detail cells: {{x, y, z, effectName}, ...}.

fn get_culling_zone_tree(&mut self) -> CullingZoneTree

The culling zone tree for the whole terrain.

script_class!

The game script of a custom game (gameClass).

Trait items

pub fn this(&self) -> Value

The Lua script instance (self).

pub fn network(&self) -> Network

self.network, for network calls between the server and client sides.

pub fn data(&self) -> Value

self.data: the class's data from its JSON definition.

pub fn storage(&self) -> Storage

[server] self.storage: data kept for the next time this object loads.

pub fn call_base(&self, method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn server_on_create(&mut self)

Called once when the object is created on the server / a client.

pub fn client_on_create(&mut self)
pub fn server_on_destroy(&mut self)

Called when the object is destroyed on the server / a client.

pub fn client_on_destroy(&mut self)
pub fn server_on_refresh(&mut self)

Called after the script file is reloaded (dev mode).

pub fn client_on_refresh(&mut self)
pub fn server_on_fixed_update(&mut self, dt: f64)

Called every physics tick (40 per second); dt is in seconds.

pub fn client_on_fixed_update(&mut self, dt: f64)
pub fn client_on_update(&mut self, dt: f64)

[client] Called every frame.

pub fn client_on_client_data_update(&mut self, data: Value, channel: i32)

[client] Called with data the server set with Network::set_client_data.

pub fn server_on_receive_update(&mut self)

[server] Called when the object receives a network update.

pub fn client_on_local_player_changed_world(&mut self, world: World)

[client] Called when the local player moves to another world.

fn bind_chat_command(&self, command: &str, params: &[ChatParam], help: &str, handler: impl FnMut(Value) + 'static)

Binds a chat command to a closure, e.g. bind_chat_command("/heal", &[ChatParam { kind: "int", name: "amount", optional: true }], "Heals you", |args| ...). The handler receives the parsed parameters.

fn server_on_player_joined(&mut self, player: Player, is_new_player: bool)

[server] Called when a player joins; is_new_player is true on their first visit.

fn server_on_player_left(&mut self, player: Player)

[server] Called when a player leaves.

fn server_on_reset(&mut self)

[server] Called on the game's reset / restart.

fn server_on_restart(&mut self)
fn server_on_save_level(&mut self)

[server] Challenge mode: called when saving, testing and stopping a test of a level.

fn server_on_test_level(&mut self)
fn server_on_stop_test(&mut self)
fn server_on_unload(&mut self)

[server] Called when the game unloads.

fn client_on_loading_screen_lifted(&mut self)

[client] Called when the loading screen is lifted.

fn client_on_language_change(&mut self, language: String)

[client] Called when the game language changes.

fn client_on_unstuck(&mut self)

[client] Called when the player uses /unstuck.

pub trait ServerShapeClass: Default + 'static

The server half of a split part. Callbacks drop the game's server_ prefix: on_create is server_onCreate, and so on. See ShapeClass for what each callback does. Server only: every callback and method of this half runs on the server.

Trait items

fn this(&self) -> Value

The Lua script instance (self).

fn data(&self) -> Value

self.data: the class's data from its JSON definition.

fn shape(&self) -> Shape

The shape this script runs on.

fn interactable(&self) -> Interactable

The shape's interactable.

fn network(&self) -> ServerNetwork

[server] The network, for sending to the client halves.

fn storage(&self) -> Storage

[server] Data kept for the next time this part loads.

fn save_state<T: Message>(&self, state: &T)

[server] Saves a message struct to storage in the wire format.

fn load_state<T: Message>(&self) -> Option<T>

[server] The struct save_state saved, or None. A save from a build with a different definition of T is ignored with a warning (fields are stored by position, so it can't be read safely) and the part starts fresh.

fn on_create(&mut self)
fn on_destroy(&mut self)
fn on_refresh(&mut self)
fn on_fixed_update(&mut self, dt: f64)
fn on_receive_update(&mut self)
fn can_erase(&mut self) -> bool
fn on_unload(&mut self)
fn on_sledgehammer(&mut self)
fn on_projectile(&mut self, hit: ProjectileHit)
fn on_melee(&mut self, hit: MeleeHit)
fn on_explosion(&mut self, center: Vec3, destruction_level: i32, damage: i32)
fn on_collision(&mut self, hit: CollisionHit)
fn on_world_changed(&mut self)
pub trait ClientShapeClass: Default + 'static

The client half of a split part. Callbacks drop the game's client_ prefix: on_interact is client_onInteract, and so on. See ShapeClass for what each callback does. Client only: every callback and method of this half runs on clients.

Trait items

fn this(&self) -> Value

The Lua script instance (self).

fn data(&self) -> Value

self.data: the class's data from its JSON definition.

fn shape(&self) -> Shape

The shape this script runs on.

fn interactable(&self) -> Interactable

The shape's interactable.

fn network(&self) -> ClientNetwork

The network, for sending to the server half.

fn on_create(&mut self)
fn on_destroy(&mut self)
fn on_refresh(&mut self)
fn on_fixed_update(&mut self, dt: f64)
fn on_update(&mut self, dt: f64)
fn on_client_data_update(&mut self, data: Value, channel: i32)
fn on_local_player_changed_world(&mut self, world: World)
fn on_interact(&mut self, character: Character, pressed: bool)
fn can_interact(&mut self, character: Character) -> bool
fn on_tinker(&mut self, character: Character, pressed: bool)
fn can_tinker(&mut self, character: Character) -> bool
fn on_action(&mut self, action: i32, pressed: bool)
fn can_erase(&mut self) -> bool
fn can_carry(&mut self) -> bool
fn on_projectile(&mut self, hit: ProjectileHit)
fn on_melee(&mut self, hit: MeleeHit)
fn on_collision(&mut self, hit: CollisionHit)
fn on_interact_through_joint(&mut self, character: Character, pressed: bool, joint: Joint)

Called when interacting through a child joint (e.g. a bearing). pressed is always true.

fn can_interact_through_joint(&mut self, character: Character, joint: Joint) -> bool
fn get_available_parent_connection_count(&mut self, flags: Connection) -> i32

See ShapeClass::client_get_available_parent_connection_count.

fn get_available_child_connection_count(&mut self, flags: Connection) -> i32
fn on_child_joint_removed(&mut self, joint: Joint)
pub fn multi(values: &[Value]) -> Value

A table the loader returns to the engine as several results.

pub fn this() -> Value

The Lua script instance (self) whose code is running.

pub fn call_base<R: FromLua>(method: &str, args: impl Args) -> R

Calls the Lua base class's version of method (see scriptClass's base argument). Returns R's nil conversion when the base has no such method.

pub fn with_mut<T: 'static>(f: impl FnOnce(&mut T) + 'static) -> bool

Runs f on the running script's object of type T, e.g. from a GUI or trigger callback. If that object is busy, f runs once its current callback returns. Returns false if the running script has no object of type T.

pub extern "C" fn _initialize()

Module initializer the loader calls once before anything else: runs the class registrations.

pub extern "C" fn atl_class_describe(name_h: Handle) -> Handle

Describes class name to the loader: its id and the methods the game-side class gets. Returns nil if no such class is registered.

pub extern "C" fn atl_class_call(class_id: i32, method: i32, self_h: Handle, args: Handle) -> Handle

Calls method method (1-based) of class class_id for script instance self_h, creating the Rust object on first use.

pub extern "C" fn atl_class_release(self_h: Handle)

Destroys the Rust objects of a script instance once both its sides are gone.

pub extern "C" fn atl_terrain_height(x: f64, y: f64, lod: i32) -> f64

Terrain fast path: plain numbers in and out, no handle table.

pub extern "C" fn atl_terrain_clutter(x: f64, y: f64) -> i32
pub fn bind_chat_command(command: &str, params: &[ChatParam], help: &str, mut handler: impl FnMut(Value) + 'static)

Binds a chat command to a closure (see GameClass::bind_chat_command).