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.
InputBlock
Section titled "InputBlock"pub struct InputBlockWhat a tool's client_on_equipped_update returns: whether to block the primary / secondary input from reaching the game.
Fields
pub primary: boolpub secondary: boolImplements Clone, Copy, Debug, Default, Eq, IntoLua, PartialEq
CullingZoneTree
Section titled "CullingZoneTree"pub struct CullingZoneTreeCulling portals and zones.
Fields
pub portals: Valuepub zones: ValueImplements Clone, Debug, Default, IntoLua
ClassBuilder
Section titled "ClassBuilder"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) -> SelfStarts registering T as script class name.
pub fn callback<M>(mut self, name: &'static str, h: impl Handler<T, M>) -> SelfAdds an engine callback under its game name.
pub fn method<M>(self, name: &'static str, h: impl Handler<T, M>) -> SelfAdds 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>) -> SelfSets 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) -> SelfMarks the class as a terrain script: Init always exists, and GetHeightAt / GetClutterIdxAt get the fast path.
ServerBuilder
Section titled "ServerBuilder"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) -> SelfRegisters 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>) -> SelfAdds 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>) -> SelfAdds 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) -> SelfAdds a typed-message handler: fn(&mut self, &Msg) or fn(&mut self, &Msg, Player).
pub fn register(self)Finishes the registration.
ClientBuilder
Section titled "ClientBuilder"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) -> SelfRegisters 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>) -> SelfAdds 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>) -> SelfAdds 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>) -> SelfSets the half's own on_destroy.
pub fn client_data<M>(self, h: impl Handler<T, M>) -> SelfSets 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) -> SelfAdds a typed-message handler: fn(&mut self, &Msg).
pub fn register(self)Finishes the registration.
ModCell
Section titled "ModCell"pub struct ModCell<T>(Global<Option<Rc<RefCell<T>>>>)Holds the export_mod! instance, created on first use.
Methods
pub const fn new() -> Selfpub fn with(&'static self, f: impl FnOnce(&mut T) + 'static)Runs f on the mod object (deferred if it is already running).
Implements Default
ChatParam
Section titled "ChatParam"pub struct ChatParamOne parameter of a chat command: its type ("int", "string", ...), name, and whether it's optional.
Fields
pub kind: &'static strpub name: &'static strpub optional: boolImplements Clone, Copy, Debug
ServerNetwork
Section titled "ServerNetwork"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) -> SelfWraps 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.
ClientNetwork
Section titled "ClientNetwork"pub struct ClientNetwork(Network)The client half's network: sends to the server half.
Methods
pub fn new(n: Network) -> SelfWraps 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 SideWhich 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
AnyServerClient
Implements Clone, Copy, Debug, Eq, PartialEq
FromArgs
Section titled "FromArgs"pub trait FromArgs: SizedA 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) -> SelfReads the value starting at args[i] and advances i past it.
Handler
Section titled "Handler"pub trait Handler<T, M>: 'staticA 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) -> ValueConverts the arguments, calls the function and converts its result.
ServerHandler
Section titled "ServerHandler"pub trait ServerHandler<T, M>: 'staticA typed-message handler of a server half: fn(&mut T, &Msg), optionally with a third Player sender.
Trait items
type Msg: MessageThe message type.
ClientHandler
Section titled "ClientHandler"pub trait ClientHandler<T, M>: 'staticA typed-message handler of a client half: fn(&mut T, &Msg).
Trait items
type Msg: MessageThe message type.
pub trait Mod: Default + 'staticMod-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.
ShapeClass
Section titled "ShapeClass"script_class!A part or block script (scriptClass for a shape).
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> ShapeThe shape this script runs on.
fn interactable(&self) -> InteractableThe 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) -> boolWhether the part may be removed now.
fn client_can_erase(&mut self) -> boolfn 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) -> i32fn 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.
ToolClass
Section titled "ToolClass"script_class!A tool script.
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> ToolThe tool this script runs on.
fn owner(&self) -> PlayerThe player holding the tool.
fn is_local(&self) -> boolTrue on the client of the player who owns the tool.
fn is_equipped(&self) -> boolTrue 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) -> boolfn client_can_equip(&mut self) -> bool[client] Whether the tool can be equipped now.
CharacterClass
Section titled "CharacterClass"script_class!A character script (scriptClass for a character type).
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> CharacterThe 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)HarvestableClass
Section titled "HarvestableClass"script_class!A harvestable script (trees, rocks, crops...).
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> HarvestableThe 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) -> boolWhether the harvestable may be removed now.
fn client_can_erase(&mut self) -> boolfn 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)UnitClass
Section titled "UnitClass"script_class!A unit script: the AI that controls a creature, server only.
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> UnitThe 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.
PlayerClass
Section titled "PlayerClass"script_class!A player script (the game's player class).
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> PlayerThe 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.
WorldClass
Section titled "WorldClass"script_class!A world script.
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> WorldThe 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).
ScriptableObjectClass
Section titled "ScriptableObjectClass"script_class!A scriptable object script: a script with no body in the world.
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> ScriptableObjectThe scriptable object this script runs on.
fn params(&self) -> ValueThe params it was created with.
fn server_on_unload(&mut self)[server] Called when the object unloads.
ClientScriptableObjectClass
Section titled "ClientScriptableObjectClass"script_class!A scriptable object that exists on one client only (client_scriptable_objects::create).
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> ClientScriptableObjectThe scriptable object this script runs on.
fn params(&self) -> ValueThe params it was created with.
TerrainScript
Section titled "TerrainScript"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) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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) -> boolLoads 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) -> StringThe file path of a tile uuid.
fn get_height_at(&mut self, x: f64, y: f64, lod: i32) -> f64Per-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) -> TerrainColorfn get_material_at(&mut self, x: f64, y: f64, lod: i32) -> MaterialWeightsfn get_clutter_idx_at(&mut self, x: f64, y: f64) -> i32The clutter index at a point, or -1 for none.
fn get_effect_material_at(&mut self, x: f64, y: f64) -> StringThe 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) -> ValuePer-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) -> Valuefn get_creations_for_cell(&mut self, cell_x: i32, cell_y: i32) -> Valuefn get_harvestables_for_cell(&mut self, cell_x: i32, cell_y: i32, lod: i32) -> Valuefn get_kinematics_for_cell(&mut self, cell_x: i32, cell_y: i32, lod: i32) -> Valuefn get_decals_for_cell(&mut self, cell_x: i32, cell_y: i32, lod: i32) -> Valuefn get_tags_for_cell(&mut self, cell_x: i32, cell_y: i32) -> Vec<String>A cell's tags.
fn get_ocean_cells(&mut self) -> ValueCells covered by ocean: {{cellX, cellY}, ...}.
fn get_h_lod_cells(&mut self) -> ValueHigh level-of-detail cells: {{x, y, z, effectName}, ...}.
fn get_culling_zone_tree(&mut self) -> CullingZoneTreeThe culling zone tree for the whole terrain.
GameClass
Section titled "GameClass"script_class!The game script of a custom game (gameClass).
Trait items
pub fn this(&self) -> ValueThe Lua script instance (self).
pub fn network(&self) -> Networkself.network, for network calls between the server and client sides.
pub fn data(&self) -> Valueself.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) -> RCalls 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.
ServerShapeClass
Section titled "ServerShapeClass"pub trait ServerShapeClass: Default + 'staticThe 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) -> ValueThe Lua script instance (self).
fn data(&self) -> Valueself.data: the class's data from its JSON definition.
fn shape(&self) -> ShapeThe shape this script runs on.
fn interactable(&self) -> InteractableThe 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) -> boolfn 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)ClientShapeClass
Section titled "ClientShapeClass"pub trait ClientShapeClass: Default + 'staticThe 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) -> ValueThe Lua script instance (self).
fn data(&self) -> Valueself.data: the class's data from its JSON definition.
fn shape(&self) -> ShapeThe shape this script runs on.
fn interactable(&self) -> InteractableThe shape's interactable.
fn network(&self) -> ClientNetworkThe 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) -> boolfn on_tinker(&mut self, character: Character, pressed: bool)fn can_tinker(&mut self, character: Character) -> boolfn on_action(&mut self, action: i32, pressed: bool)fn can_erase(&mut self) -> boolfn can_carry(&mut self) -> boolfn 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) -> boolfn get_available_parent_connection_count(&mut self, flags: Connection) -> i32See ShapeClass::client_get_available_parent_connection_count.
fn get_available_child_connection_count(&mut self, flags: Connection) -> i32fn on_child_joint_removed(&mut self, joint: Joint)Functions
Section titled "Functions"pub fn multi(values: &[Value]) -> ValueA table the loader returns to the engine as several results.
pub fn this() -> ValueThe Lua script instance (self) whose code is running.
pub fn call_base<R: FromLua>(method: &str, args: impl Args) -> RCalls 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) -> boolRuns 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) -> HandleDescribes 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) -> HandleCalls 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) -> f64Terrain fast path: plain numbers in and out, no handle table.
pub extern "C" fn atl_terrain_clutter(x: f64, y: f64) -> i32pub 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).