Skip to content

atl::sm

The core Scrap Mechanic API: game object types (Shape, Body, Interactable, Character, Player, World, ...) and the sm.* namespaces that operate on them.

object!(pub Shape = "Shape" )

A block or part in the world (Lua Shape).

Methods

pub fn sticky(&self) -> Sticky

The sticky directions.

pub fn local_aabb(&self) -> Aabb

The bounding box in body-local coordinates.

pub fn destroy_with(&self, d: &Destruction)

[server] Destroys the shape with full destruction details.

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The shape's unique id.

pub fn uuid(&self) -> Uuid

The shape's item uuid.

pub fn world_position(&self) -> Vec3

Position and rotation in the world, and relative to the body.

pub fn world_rotation(&self) -> Quat
pub fn local_position(&self) -> Vec3
pub fn local_rotation(&self) -> Quat
pub fn velocity(&self) -> Vec3

Velocity in meters per second.

pub fn at(&self) -> Vec3

The shape's forward (at), up and right directions in the world.

pub fn up(&self) -> Vec3
pub fn right(&self) -> Vec3
pub fn x_axis(&self) -> Vec3

The shape's local x, y and z axes in world space.

pub fn y_axis(&self) -> Vec3
pub fn z_axis(&self) -> Vec3
pub fn bounding_box(&self) -> Vec3

Size in blocks.

pub fn mass(&self) -> f64

Mass in kilograms.

pub fn material(&self) -> String

The physics material name.

pub fn color(&self) -> Color

The paint color.

pub fn set_color(&self, c: Color)

[server] Paints the shape.

pub fn burning(&self) -> bool

True while the shape burns.

pub fn set_burning(&self, b: bool)

[server] Sets the shape on fire or puts it out.

pub fn transform_point(&self, world_point: Vec3) -> Vec3

World point / direction to shape-local.

pub fn transform_direction(&self, world_dir: Vec3) -> Vec3
pub fn transform_local_point(&self, local_point: Vec3) -> Vec3

Shape-local point / direction to world.

pub fn transform_local_direction(&self, local_dir: Vec3) -> Vec3
pub fn neighbours(&self) -> Vec<Shape>

[server] Shapes touching this one.

pub fn interpolated_world_position(&self) -> Vec3

Positions and directions smoothed between physics ticks, for rendering.

pub fn interpolated_at(&self) -> Vec3
pub fn interpolated_up(&self) -> Vec3
pub fn interpolated_right(&self) -> Vec3
pub fn transform_rotation(&self, world_rotation: Quat) -> Quat

A world rotation in shape-local terms.

pub fn closest_block_local_position(&self, world_position: Vec3) -> Vec3

The local position of the shape's block nearest to a world position.

pub fn buoyancy(&self) -> f64

Buoyancy of the shape's material.

pub fn material_id(&self) -> i32

The physics material id.

pub fn set_physics_material(&self, material: i32)

[client] Overrides the physics material.

pub fn set_collision_sound_enabled(&self, on: bool)

Turns collision sounds on or off.

pub fn is_harvest(&self) -> bool

True for a harvested item.

pub fn is_stackable(&self) -> bool

True if the item stacks.

pub fn compromised(&self) -> bool

True when the shape is structurally weakened.

pub fn set_compromised(&self, on: bool)

[server] Weakens or restores the shape.

pub fn remove_color(&self)

[server] Back to the shape's default color.

pub fn apply_shake_impulse(&self, shake: f64)

[client] Shakes the shape visually.

pub fn multi_shape_shapes(&self) -> Vec<Shape>

The shapes and joints of the multi-shape item this shape belongs to.

pub fn is_pipe(&self) -> bool

True for pipe parts.

pub fn pipe_offsets(&self, direction: Option<i32>) -> Vec<Vec3>

Pipe connection offsets, optionally for one direction only.

pub fn piped_neighbours(&self) -> Vec<Shape>

[server] Pipes connected to this one.

pub fn output_container_index(&self) -> i32

The output container index from the shapeset, for pipe graphs.

pub fn destroy(&self, attack_level: i32)

[server] Destroys the shape with an attack level.

pub fn destroy_block(&self, local_position: Vec3, size: Vec3, d: &Destruction)

[server] Removes the blocks of a block shape in the box at localPosition (a corner) of size.

pub fn replace(&self, uuid: Uuid)

[server] Replaces the shape with another item, keeping its position.

pub fn body(&self) -> Body
pub fn interactable(&self) -> Interactable
pub fn joints(&self, only_child_joints: bool) -> Vec<Joint>
pub fn apply_impulse(&self, impulse: Vec3, world_space: bool, offset: Vec3)
pub fn multi_shape_joints(&self) -> Vec<Joint>
pub fn create_joint(&self, uuid: Uuid, local_position: Vec3, direction: Vec3) -> Joint

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Body = "Body" )

A rigid body: shapes connected without joints (Lua Body).

Methods

pub fn local_aabb(&self) -> Aabb

Bounding box in body-local coordinates.

pub fn world_aabb(&self) -> Aabb

Bounding box in world coordinates.

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The body's id.

pub fn creation_id(&self) -> i32

[server] The id of the creation (bodies connected by joints) it belongs to.

pub fn world_position(&self) -> Vec3

Position of the body's origin.

pub fn center_of_mass(&self) -> Vec3

Center of mass in world space.

pub fn velocity(&self) -> Vec3

Linear / angular velocity.

pub fn angular_velocity(&self) -> Vec3
pub fn mass(&self) -> f64

Mass in kilograms.

pub fn shapes(&self) -> Vec<Shape>

The body's shapes, interactables and joints.

pub fn creation_bodies(&self) -> Vec<Body>

The bodies, shapes and joints of the whole creation.

pub fn creation_shapes(&self) -> Vec<Shape>
pub fn shape_count(&self) -> i32

Number of shapes.

pub fn shape(&self, index: i32) -> Shape

Shape by index.

pub fn shapes_by_uuid(&self, uuid: Uuid) -> Vec<Shape>

Shapes of one item type.

pub fn has_changed(&self, tick: i32) -> bool

True if the body changed after tick (compare with game::currentTick()).

pub fn is_ghost(&self) -> bool

True for a ghost (non-colliding) body.

pub fn is_on_virtual_lift(&self) -> bool

True when held by a virtual lift.

pub fn is_connectable(&self) -> bool

Permission flags: whether the body can be connected to, lifted, or made dynamic.

pub fn is_liftable(&self) -> bool
pub fn is_convertible_to_dynamic(&self) -> bool
pub fn set_connectable(&self, v: bool)

[server] Sets those permission flags.

pub fn set_liftable(&self, v: bool)
pub fn set_convertible_to_dynamic(&self, v: bool)
pub fn is_static(&self) -> bool

True if the body is static / dynamic.

pub fn is_dynamic(&self) -> bool
pub fn is_on_lift(&self) -> bool

True when on a lift.

pub fn is_buildable(&self) -> bool

Permission flags: building, destruction, erasing, painting and use.

pub fn is_destructable(&self) -> bool
pub fn is_erasable(&self) -> bool
pub fn is_paintable(&self) -> bool
pub fn is_usable(&self) -> bool
pub fn set_buildable(&self, v: bool)

[server] Sets those permission flags.

pub fn set_destructable(&self, v: bool)
pub fn set_erasable(&self, v: bool)
pub fn set_paintable(&self, v: bool)
pub fn set_usable(&self, v: bool)
pub fn transform_point(&self, world_point: Vec3) -> Vec3

World point to body-local.

pub fn transform_local_point(&self, local_point: Vec3) -> Vec3

Body-local point to world.

pub fn transform_world_point(&self, world_point: Vec3) -> Vec3

World space to the body's local space.

pub fn create_block(&self, uuid: Uuid, size: Vec3, local_position: Vec3, force_accept: bool) -> Shape

[server] Adds a block. forceAccept skips the overlap check.

pub fn create_part(&self, uuid: Uuid, local_position: Vec3, z_axis: Vec3, x_axis: Vec3, force_accept: bool) -> Shape

[server] Adds a part oriented by its z and x axes.

pub fn create_wedge(&self, uuid: Uuid, size: Vec3, local_position: Vec3, z_axis: Vec3, x_axis: Vec3, force_accept: bool)

[server] Adds a wedge.

pub fn destroy_creation(&self)

[server] Destroys the whole creation.

pub fn world(&self) -> World
pub fn interactables(&self) -> Vec<Interactable>
pub fn joints(&self) -> Vec<Joint>
pub fn seated_characters(&self) -> Vec<Character>
pub fn apply_impulse(&self, impulse: Vec3, world_space: bool, offset: Vec3)
pub fn apply_torque(&self, torque: Vec3, world_space: bool)
pub fn creation_joints(&self) -> Vec<Joint>
pub fn lift(&self) -> Lift

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Interactable = "Interactable" )

The scripted, connectable side of a part (Lua Interactable).

Methods

pub fn on_damage_destruction(&self, f: impl FnMut() + 'static)

[server] Runs when the interactable is destroyed by damage.

pub fn steering_joint(&self, joint: &Joint) -> SteeringJoint

Reads a bearing's steering settings.

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The interactable's id.

pub fn shape(&self) -> Shape

The shape and body it belongs to.

pub fn body(&self) -> Body
pub fn kind(&self) -> String

The interactable type, e.g. "engine".

pub fn is_active(&self) -> bool

True when active (on).

pub fn set_active(&self, on: bool)

[server] Turns the interactable on or off.

pub fn power(&self) -> f64

The output power value.

pub fn set_power(&self, p: f64)

[server] Sets the output power.

pub fn parents(&self, filter: Option<Connection>) -> Vec<Interactable>

Interactables connected as inputs / outputs, optionally of one connection type.

pub fn children(&self, filter: Option<Connection>) -> Vec<Interactable>
pub fn single_parent(&self) -> Interactable

The only parent, or empty.

pub fn connect(&self, child: &Interactable) -> bool

[server] Connects an output to child.

pub fn disconnect(&self, child: &Interactable) -> bool

[server] Removes a connection to child.

pub fn public_data(&self) -> Value

[server] Data other scripts can read.

pub fn set_public_data(&self, t: &Value)

[server] Sets data other scripts can read.

pub fn has_seat(&self) -> bool

True if the part has a seat.

pub fn set_uv_frame_index(&self, index: i32)

[client] Visual state: UV frame, glow, animations and sub-mesh visibility.

pub fn set_glow_multiplier(&self, v: f64)
pub fn set_anim_enabled(&self, name: &str, on: bool)
pub fn set_anim_progress(&self, name: &str, progress: f64)
pub fn set_sub_mesh_visible(&self, name: &str, visible: bool)
pub fn remove_container(&self, index: i32)

[server] Removes a container.

pub fn max_parent_count(&self) -> i32

How many parents / children may connect.

pub fn max_child_count(&self) -> i32
pub fn input_type(&self) -> Connection

The connection types accepted as input / produced as output.

pub fn output_type(&self) -> Connection
pub fn has_output_type(&self, flags: Connection) -> bool

True if the output includes all of flags.

pub fn connection_color(&self) -> Color

Connection colors (normal / highlighted).

pub fn connection_highlight_color(&self) -> Color
pub fn has_changed(&self, tick: i32) -> bool

True if the interactable had updates after tick.

pub fn client_public_data(&self) -> Value

[client] Data other client scripts can read.

pub fn set_client_public_data(&self, t: &Value)

[client] Sets data other client scripts can read.

pub fn set_params(&self, data: &Value)

Params for an interactable created from a script.

pub fn carry_data(&self) -> Value

[server] Data kept when the part is carried.

pub fn set_carry_data(&self, data: &Value)

[server] Sets data kept when the part is carried.

pub fn seat_interactables(&self) -> Vec<Interactable>

Interactables the seat controls (the hotbar of a seat).

pub fn press_seat_interactable(&self, index: i32) -> bool

Presses / releases a seat hotbar slot.

pub fn release_seat_interactable(&self, index: i32) -> bool
pub fn has_steering(&self) -> bool

True for a driver's seat with steering.

pub fn steering_angle(&self) -> f64

Steering input: A = -1, D = 1.

pub fn steering_power(&self) -> f64

Throttle input: W = 1, S = -1.

pub fn steering_sprint(&self) -> bool

True while sprinting in the seat.

pub fn set_steering_flag(&self, flags: i32)

Sets / clears steering flags.

pub fn unset_steering_flag(&self, flags: i32)
pub fn set_gyro_direction(&self, direction: Vec3)

[client] Gyro / turret seats: aim direction, force and maximum speed.

pub fn set_gyro_force(&self, force: f64)
pub fn set_gyro_max_speed(&self, speed: f64)
pub fn set_light_override_color(&self, c: Color)

[server] Overrides / restores the light color.

pub fn clear_light_override_color(&self)
pub fn glow_multiplier(&self) -> f64

The current glow multiplier.

pub fn uv_frame_index(&self) -> i32

[client] The current UV frame.

pub fn pose_weight(&self, index: i32) -> f64

[client] Reads / writes an animation pose weight.

pub fn set_pose_weight(&self, index: i32, weight: f64)
pub fn has_anim(&self, name: &str) -> bool

[client] True if the animation exists.

pub fn anim_duration(&self, name: &str) -> f64

[client] An animation's length in seconds.

pub fn is_anim_looping(&self, name: &str) -> bool

[client] True if an animation loops.

pub fn local_bone_position(&self, bone: &str) -> Vec3

A bone's position, local / in the world.

pub fn world_bone_position(&self, bone: &str) -> Vec3
pub fn seat_character(&self) -> Character
pub fn container(&self, index: i32) -> Container
pub fn add_container(&self, index: i32, size: i32, stack_size: Option<i32>) -> Container
pub fn joints(&self) -> Vec<Joint>
pub fn bearings(&self) -> Vec<Joint>
pub fn pistons(&self) -> Vec<Joint>
pub fn connect_to_joint(&self, child: &Joint)
pub fn joint_custom_data(&self, joint: &Joint) -> Value
pub fn set_joint_custom_data(&self, joint: &Joint, data: &Value)
pub fn set_seat_character(&self, character: &Character)
pub fn set_steering_joint(&self, joint: &Joint, s: &SteeringJoint)
pub fn steering_joint_left_angle_limit(&self, j: &Joint) -> f64
pub fn steering_joint_right_angle_limit(&self, j: &Joint) -> f64
pub fn steering_joint_left_angle_speed(&self, j: &Joint) -> f64
pub fn steering_joint_right_angle_speed(&self, j: &Joint) -> f64
pub fn steering_joint_unlocked(&self, j: &Joint) -> bool
pub fn set_steering_joint_left_angle_limit(&self, j: &Joint, v: f64)
pub fn set_steering_joint_right_angle_limit(&self, j: &Joint, v: f64)
pub fn set_steering_joint_left_angle_speed(&self, j: &Joint, v: f64)
pub fn set_steering_joint_right_angle_speed(&self, j: &Joint, v: f64)
pub fn set_steering_joint_unlocked(&self, j: &Joint, unlocked: bool)

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Joint = "Joint" )

A joint: bearing, piston, spring or similar (Lua Joint).

Methods

pub fn sticky(&self) -> Sticky

The sticky directions.

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The joint's id.

pub fn kind(&self) -> String

The joint type, e.g. "bearing" or "piston".

pub fn shape_a(&self) -> Shape

The shape the joint is placed on.

pub fn shape_b(&self) -> Shape

The shape on the joint's far side; empty when nothing is attached.

pub fn uuid(&self) -> Uuid

The joint's item uuid.

pub fn world_position(&self) -> Vec3

Position and rotation, in the world / on the body.

pub fn world_rotation(&self) -> Quat
pub fn local_position(&self) -> Vec3
pub fn local_rotation(&self) -> Quat
pub fn x_axis(&self) -> Vec3

The joint's local axes in world space.

pub fn y_axis(&self) -> Vec3
pub fn z_axis(&self) -> Vec3
pub fn bounding_box(&self) -> Vec3

Size in blocks.

pub fn color(&self) -> Color

Paint color.

pub fn set_color(&self, c: Color)

[server] Paints the joint.

pub fn multi_shape_shapes(&self) -> Vec<Shape>

The shapes and joints of its multi-shape item.

pub fn multi_shape_joints(&self) -> Vec<Joint>
pub fn angle(&self) -> f64

A bearing's angle in radians and angular speed.

pub fn angular_velocity(&self) -> f64
pub fn angular_velocity_vector(&self) -> Vec3

Angular velocity as a vector.

pub fn applied_impulse(&self) -> f64

The impulse the motor applied last tick.

pub fn bearing_enabled(&self) -> bool

True if the bearing turns freely.

pub fn length(&self) -> f64

A piston's current length.

pub fn is_reversed(&self) -> bool

True if the joint is reversed.

pub fn create_block(&self, uuid: Uuid, size: Vec3, local_position: Vec3, force_create: bool)

[server] Adds a block / part on the joint's far side.

pub fn create_part(&self, uuid: Uuid, local_position: Vec3, z_axis: Vec3, x_axis: Vec3, force_create: bool)
pub fn set_motor_velocity(&self, velocity: f64, max_impulse: f64)

Bearings: spins at velocity with up to maxImpulse.

pub fn set_target_angle(&self, angle: f64, velocity: f64, max_impulse: f64)

Bearings: turns to angle.

pub fn set_target_length(&self, length: f64, velocity: f64, max_impulse: f64)

[server] Pistons: extends to length.

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Character = "Character" )

A character: a player's body or a creature (Lua Character).

Methods

pub fn active_animations(&self) -> Vec<ActiveAnimation>

The animations playing now.

pub fn animation_info(&self, name: &str) -> AnimationInfo

Information about an animation.

pub fn on_animation(&self, name: &str, time: f64, f: impl FnMut() + 'static)

Calls f when animation name reaches time.

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The character's id.

pub fn is_player(&self) -> bool

True for a player's character.

pub fn world_position(&self) -> Vec3

Position in the world.

pub fn set_world_position(&self, p: Vec3)

[server] Teleports the character.

pub fn velocity(&self) -> Vec3

Velocity.

pub fn direction(&self) -> Vec3

Look direction.

pub fn mass(&self) -> f64

Mass, height and radius.

pub fn height(&self) -> f64
pub fn radius(&self) -> f64
pub fn color(&self) -> Color

Color.

pub fn set_color(&self, c: Color)

[server] Paints the character.

pub fn is_on_ground(&self) -> bool

Movement state.

pub fn is_crouching(&self) -> bool
pub fn is_sprinting(&self) -> bool
pub fn is_swimming(&self) -> bool
pub fn is_seated(&self) -> bool
pub fn is_tumbling(&self) -> bool
pub fn is_downed(&self) -> bool
pub fn set_tumbling(&self, v: bool)

[server] Knocks the character over / lets it get up.

pub fn set_downed(&self, v: bool)

[server] Downs the character or revives it.

pub fn set_movement_speed_fraction(&self, f: f64)

Scales movement speed (1 is normal).

pub fn set_name_tag(&self, name: &str, color: Option<Color>)

Shows a name tag above the character.

pub fn character_type(&self) -> Uuid

The character type's uuid.

pub fn smooth_view_direction(&self) -> Vec3

The look direction, smoothed.

pub fn surface_normal(&self) -> Vec3

The normal of the surface the character stands on.

pub fn is_default_color(&self) -> bool

True if the character has its default color.

pub fn is_moving(&self) -> bool

More movement state.

pub fn is_aiming(&self) -> bool
pub fn is_climbing(&self) -> bool
pub fn is_ladder_climbing(&self) -> bool
pub fn is_diving(&self) -> bool
pub fn is_flying(&self) -> bool
pub fn is_hovering(&self) -> bool
pub fn can_swim(&self) -> bool

True if the character type can swim.

pub fn set_swimming(&self, v: bool)

[server] Forces a movement state.

pub fn set_diving(&self, v: bool)
pub fn set_climbing(&self, v: bool)
pub fn set_flying(&self, v: bool)
pub fn set_hovering(&self, v: bool)
pub fn immovable(&self) -> bool

[server] Whether the character can be pushed.

pub fn set_immovable(&self, v: bool)

[server] Makes the character immovable or movable.

pub fn move_speed(&self) -> f64

Base walking and sprinting speeds.

pub fn sprint_speed(&self) -> f64
pub fn current_movement_speed(&self) -> f64

The current movement speed.

pub fn movement_speed_fraction(&self) -> f64

The movement speed scale.

pub fn jump_speed_fraction(&self) -> f64

Reads / writes the jump height scale.

pub fn set_jump_speed_fraction(&self, f: f64)
pub fn movement_noise_radius(&self) -> f64

How far the character's movement can be heard by AI.

pub fn set_movement_effects(&self, effect_set_path: &str)

Sets the effect set used for footsteps and other movement sounds.

pub fn tumbling_world_position(&self) -> Vec3

The tumbling (ragdoll) body's position, rotation, velocities and size.

pub fn tumbling_world_rotation(&self) -> Quat
pub fn tumbling_linear_velocity(&self) -> Vec3
pub fn tumbling_angular_velocity(&self) -> Vec3
pub fn tumbling_extent(&self) -> Vec3
pub fn apply_tumbling_impulse(&self, impulse: Vec3, offset: Option<Vec3>)

Pushes the tumbling body.

pub fn set_allow_tumble_animations(&self, allow: bool)

Whether tumbling plays animations.

pub fn public_data(&self) -> Value

[server] Data other server scripts can read.

pub fn set_public_data(&self, t: &Value)

[server] Sets data other server scripts can read.

pub fn client_public_data(&self) -> Value

[client] Data other client scripts can read.

pub fn set_client_public_data(&self, t: &Value)

[client] Sets data other client scripts can read.

pub fn tp_bone_position(&self, bone: &str) -> Vec3

A bone's third person position / rotation.

pub fn tp_bone_rotation(&self, bone: &str) -> Quat
pub fn update_animation(&self, name: &str, time: f64, weight: Option<f64>, additive: bool)

Plays an animation at time with an optional blend weight.

pub fn has_active_override_animation(&self) -> bool

True while an override animation plays.

pub fn set_movement_weights(&self, lower: f64, upper: f64)

Blend weights of the lower and upper body movement animations.

pub fn remove_animation_callbacks(&self)

Removes every onAnimation callback.

pub fn has_graphics(&self) -> bool

True once the character's graphics are loaded.

pub fn is_visible(&self) -> bool

Visibility.

pub fn set_visible(&self, visible: bool)
pub fn add_renderable(&self, rend: &str)

Adds / removes a renderable on the character.

pub fn remove_renderable(&self, rend: &str)
pub fn override_renderables(&self, rends: &[String])

Replaces the character's renderables.

pub fn glow_multiplier(&self) -> f64

Reads / writes the glow multiplier.

pub fn set_glow_multiplier(&self, v: f64)
pub fn set_up_direction(&self, up: Vec3)

Sets which way is up for the character.

pub fn player(&self) -> Player
pub fn world(&self) -> World
pub fn apply_impulse(&self, impulse: Vec3)
pub fn locking_interactable(&self) -> Interactable
pub fn set_locking_interactable(&self, i: &Interactable) -> bool
pub fn locking_harvestable(&self) -> Harvestable
pub fn set_locking_harvestable(&self, h: &Harvestable) -> bool
pub fn unit(&self) -> Unit

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Player = "Player" )

A connected player (Lua Player).

Methods

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The player's id.

pub fn name(&self) -> String

The player's display name.

pub fn character(&self) -> Character

The player's current character.

pub fn is_male(&self) -> bool

The character's body type.

pub fn is_female(&self) -> bool
pub fn public_data(&self) -> Value

[server] Data other scripts can read.

pub fn set_public_data(&self, t: &Value)

[server] Sets data other scripts can read.

pub fn client_public_data(&self) -> Value

[client] Data other client scripts can read.

pub fn set_client_public_data(&self, t: &Value)

[client] Sets data other client scripts can read.

pub fn is_active(&self) -> bool

True until the player has left.

pub fn current_tool_uuid(&self) -> Uuid

The uuid of the tool the player holds.

pub fn customization_uuid(&self, index: i32) -> Uuid

[server] The uuid of customization slot index.

pub fn set_character(&self, c: &Character)

[server] Gives the player a character.

pub fn send_character_event(&self, event: &str)

[server] Fires client_onEvent on the player's character.

pub fn carry_color(&self) -> Color

[server] The carried item's color.

pub fn carry_data(&self) -> Value

[server] Data of the carried item.

pub fn set_carry_data(&self, t: &Value)

[server] Sets the carried item's data.

pub fn place_lift(&self, creation: &[Body], position: Vec3, level: i32, rotation: i32)

[server] Places the player's lift, carrying creation, at level with rotation (0..3).

pub fn remove_lift(&self)

[server] Removes the player's lift.

pub fn inventory(&self) -> Container
pub fn hotbar(&self) -> Container
pub fn carry(&self) -> Container

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Container = "Container" )

An item container: inventory, chest, hotbar... (Lua Container).

Methods

pub fn item(&self, slot: i32) -> Item

The item stack in slot.

pub fn can_collect_all(&self, items: &[Item]) -> bool

True if the container has room for all of items.

pub fn first_item(&self) -> Item

The first non-empty stack.

pub fn on_transaction(&self, f: impl FnMut() + 'static)

[server] Runs after every transaction that changed this container.

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn size(&self) -> i32

Number of slots.

pub fn is_empty(&self) -> bool

True if every / no slot is free.

pub fn is_full(&self) -> bool
pub fn can_collect(&self, item: Uuid, quantity: i32) -> bool

True if quantity of item fit / can be taken.

pub fn can_spend(&self, item: Uuid, quantity: i32) -> bool
pub fn count(&self, item: Uuid) -> i32

Total quantity of an item.

pub fn max_stack_size(&self) -> i32

Largest stack per slot.

pub fn unique_items(&self) -> Vec<Uuid>

Each item type present, once.

pub fn item_uuids(&self) -> Vec<Uuid>

Every slot's uuid / quantity, in slot order.

pub fn quantities(&self) -> Vec<i32>
pub fn revision(&self) -> i32

Network revision, bumped on every change.

pub fn has_changed(&self, tick: i32) -> bool

[server] True if the container changed after tick.

pub fn allow_collect(&self) -> bool

[server] Whether items can be put in / taken out.

pub fn allow_spend(&self) -> bool
pub fn move_all_to_carry(&self, player: &Player, color: Color)

[server] Moves everything into player's carry container, painted color.

pub fn collect(&self, item: Uuid, quantity: i32, must_collect_all: bool) -> i32

[server] Adds / removes items; returns how many were moved. Use inside container::transaction.

pub fn spend(&self, item: Uuid, quantity: i32, must_spend_all: bool) -> i32
pub fn collect_to_slot(&self, slot: i32, item: Uuid, quantity: i32, must_collect_all: bool) -> i32

[server] Adds to / takes from one slot.

pub fn spend_from_slot(&self, slot: i32, item: Uuid, quantity: i32, must_spend_all: bool) -> i32
pub fn swap(&self, other: &Container, from_slot: i32, to_slot: i32) -> bool

[server] Swaps slots with another container.

pub fn move_all_to(&self, other: &Container)

[server] Moves everything to another container.

pub fn set_item(&self, slot: i32, item: Uuid, quantity: i32) -> bool

[server] Direct edits, outside transactions: set a slot, clear, resize, and allow collecting / spending.

pub fn clear(&self)
pub fn resize(&self, size: i32, stack_size: Option<i32>)
pub fn set_allow_collect(&self, allow: bool)
pub fn set_allow_spend(&self, allow: bool)
pub fn set_filters(&self, allowed: &[Uuid])

[server] Only these items may be put in (empty: anything).

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub World = "World" )

A world: terrain, cells and everything in them (Lua World).

Methods

pub fn cell_bounds(&self) -> CellBounds

Reads the world's cell bounds.

pub fn load_cell(&self, x: i32, y: i32, player: &Player, on_loaded: Option<CellCallback>)

[server] Loads a cell for player (nil for none); on_loaded(x, y) runs when it's ready.

pub fn load_cell_with_handle(&self, x: i32, y: i32, on_loaded: Option<CellCallback>) -> LoadCellHandle

[server] Loads a cell and keeps it loaded while the handle lives.

pub fn load_nav_mesh_with_handle(
&self,
x: i32,
y: i32,
on_loaded: Option<CellCallback>,
) -> LoadCellHandle

[server] Loads a cell's navigation mesh and keeps it loaded while the handle lives.

pub fn reload_cell(&self, x: i32, y: i32, on_done: Option<ReloadCallback>)

[server] Reloads a cell; on_done(x, y, ok) runs when it's done.

pub fn dominant_material_in_sphere(&self, position: Vec3, radius: f64) -> VoxelMaterial

The most common voxel material in a sphere / capsule.

pub fn dominant_material_in_capsule(&self, position: Vec3, radius: f64, height: f64) -> VoxelMaterial
pub fn voxel_material_at(&self, world_position: Vec3) -> VoxelMaterial

The voxel material at a world position.

pub fn weighted_voxel_density_at(&self, point: Vec3) -> WeightedDensity

Reads the interpolated voxel density at a point.

pub fn sphere_voxel_density_subtraction(
&self,
position: Vec3,
radius: f64,
filter: Option<i32>,
strength: Option<f64>,
on_done: Option<VoxelCallback>,
)

[server] Removes voxel density in a sphere; on_done(data) gets the engine's result.

pub fn voxel_density_subtraction(
&self,
position: Vec3,
direction: Vec3,
radius: f64,
target_density: i32,
filter: Option<i32>,
destruction_effect: bool,
on_done: Option<VoxelCallback>,
)

[server] Removes voxel density along direction down to target_density.

pub fn voxel_density_subtraction_per_material(
&self,
position: Vec3,
direction: Vec3,
radius: f64,
target_densities: &[i32],
filter: Option<i32>,
destruction_effect: bool,
on_done: Option<VoxelCallback>,
)

Like voxel_density_subtraction, with a target density per material.

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The world's id.

pub fn is_indoor(&self) -> bool

True for an indoor world.

pub fn destroy(&self)

[server] Destroys the world.

pub fn is_cell_in_bounds(&self, x: i32, y: i32) -> bool

True if the cell is inside the bounds.

pub fn is_cell_loaded_server(&self, x: i32, y: i32) -> bool

[server] True if the cell is loaded on the server.

pub fn is_cell_loaded_client(&self, x: i32, y: i32) -> bool

[client] True if the cell is loaded on this client.

pub fn set_terrain_script_data(&self, data: &Value)

Data for the terrain generation script (Create's data).

pub fn zone_id(&self, position: Vec3) -> Value

The zone id at a position (nil if none).

pub fn set_light_color_override(&self, c: Color)

[server] Overrides every light controller's color in the world.

pub fn clear_light_color_override(&self)

[server] Removes the light color override.

pub fn is_voxel_terrain_point_clear(&self, reference_position: Vec3, test_position: Vec3) -> bool

True if testPosition is free of voxel terrain, as seen from referencePosition.

pub fn sphere_voxel_density_addition(&self, position: Vec3, radius: f64, material: i32, player: &Player)

[server] Adds voxels in a sphere.

pub fn voxel_density_addition(&self, position: Vec3, surface_normal: Vec3, max_distance: f64, target_density: i32, material: i32, filter: Option<i32>, player: &Player)

[server] Adds voxels along surfaceNormal up to maxDistance.

pub fn set_mining_config(&self, config: &Value)

[server] Mining loot config (see WorldClass::server_onMining).

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Harvestable = "Harvestable" )

A tree, rock, plant or kinematic object (Lua Harvestable).

Methods

pub fn aabb(&self) -> Aabb

The bounding box in world / local coordinates.

pub fn local_aabb(&self) -> Aabb
pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The harvestable's id.

pub fn uuid(&self) -> Uuid

Its item uuid, name and type.

pub fn name(&self) -> String
pub fn kind(&self) -> String
pub fn position(&self) -> Vec3

Position, rotation and scale.

pub fn rotation(&self) -> Quat
pub fn scale(&self) -> Vec3
pub fn color(&self) -> Color

Color.

pub fn set_color(&self, c: Color)

Paints the harvestable.

pub fn destroy(&self)

[server] Destroys the harvestable.

pub fn world(&self) -> World

The world it's in.

pub fn set_position(&self, p: Vec3)

Moves / rotates a kinematic harvestable.

pub fn set_rotation(&self, q: Quat)
pub fn velocity(&self) -> Vec3

Velocity and angular velocity.

pub fn angular_velocity(&self) -> Vec3
pub fn mass(&self) -> f64

Mass in kilograms.

pub fn material(&self) -> String

The physics material name and id.

pub fn material_id(&self) -> i32
pub fn transform_point(&self, world_point: Vec3) -> Vec3

World point to local / local point to world / world direction to local.

pub fn transform_local_point(&self, local_point: Vec3) -> Vec3
pub fn transform_direction(&self, world_dir: Vec3) -> Vec3
pub fn is_kinematic(&self) -> bool

True for a kinematic (scripted, movable) harvestable.

pub fn is_cell_kinematic(&self) -> bool

True for a kinematic placed by a cell (vs. created from a script).

pub fn initial_hash(&self) -> f64

Identifies a kinematic across reloads (harvestables::byInitialHash).

pub fn data(&self) -> Value

The script data from the harvestable's definition.

pub fn set_params(&self, data: &Value)

[server] Sets the params of a harvestable created from a script.

pub fn public_data(&self) -> Value

[server] Data other scripts can read.

pub fn set_public_data(&self, t: &Value)

[server] Sets data other scripts can read.

pub fn client_public_data(&self) -> Value

[client] Data other client scripts can read.

pub fn set_client_public_data(&self, t: &Value)

[client] Sets data other client scripts can read.

pub fn has_seat(&self) -> bool

Seats (kinematics with a seat component): whether there is one, who sits in it, and seating a character.

pub fn apply_shake_impulse(&self, shake: f64)

[client] Shakes the harvestable visually.

pub fn uv_frame_index(&self) -> i32

[client] Reads / writes the UV frame.

pub fn set_uv_frame_index(&self, index: i32)
pub fn pose_weight(&self, index: i32) -> f64

[client] Reads / writes an animation pose weight.

pub fn set_pose_weight(&self, index: i32, weight: f64)
pub fn set_sub_mesh_visible(&self, name: &str, visible: bool)

[client] Shows or hides one / every sub-mesh.

pub fn set_all_sub_mesh_visible(&self, visible: bool)
pub fn seat_character(&self) -> Character
pub fn set_seat_character(&self, c: &Character)

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Network = "Network" )

A script's network channel between its server and client sides (self.network).

Methods and constants

pub const PACKET_LIMIT: usize = NETWORK_PACKET_LIMIT

The largest single network send (NETWORK_PACKET_LIMIT).

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

[client] Calls method(data, sender) on the server side. Pass () for no data.

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

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

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

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

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

[server] Sets data synced to client_on_client_data_update on every client, including players who join later. One value per channel (1 or 2).

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Effect = "Effect" )

A visual or sound effect (Lua Effect).

Methods

pub fn set_parameter(&self, name: &str, value: impl IntoLua)

Sets an effect parameter.

pub fn set_host(&self, host: &impl IntoLua, bone: &str)

Attaches the effect to a host, optionally to a bone ("" for none).

pub fn camera_data(&self) -> CameraData

[client] The camera the effect controls (camera effects).

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn start(&self)

Starts playing.

pub fn stop(&self)

Stops, letting the effect finish / stops at once.

pub fn stop_immediate(&self)
pub fn destroy(&self)

Destroys the effect.

pub fn is_playing(&self) -> bool

True while playing.

pub fn is_done(&self) -> bool

True once finished.

pub fn set_position(&self, p: Vec3)

Sets position, rotation, velocity and scale.

pub fn set_rotation(&self, q: Quat)
pub fn set_velocity(&self, v: Vec3)
pub fn set_scale(&self, s: Vec3)
pub fn set_offset_position(&self, p: Vec3)

Offset from the host.

pub fn set_offset_rotation(&self, q: Quat)
pub fn set_auto_play(&self, on: bool)

Whether the effect restarts by itself when done.

pub fn id(&self) -> i32

The effect's id.

pub fn world_position(&self) -> Vec3

[client] The effect's position in the world.

pub fn set_start_stop_distance(&self, start_distance: f64, stop_distance: f64)

Starts when the camera is within startDistance, stops beyond stopDistance.

pub fn has_host(&self) -> bool

[client] True if attached to a host.

pub fn detach(&self)

[client] Detaches from the host.

pub fn set_detach_on_host_destroy(&self, detach: bool)

[client] Whether to detach instead of being destroyed with the host.

pub fn set_host_axis_ignore(&self, axis: i32)

[client] A rotation axis (sm.effect.axis...) that hosted effects ignore.

pub fn set_world(&self, w: &World)

[client] The world the effect plays in.

pub fn set_world_any(&self)

[client] Plays in every world, for global sounds.

pub fn set_time_of_day(&self, enabled: bool, start_time: f64, end_time: f64, inverse: bool)

[client] Only active between startTime and endTime (0..1 time of day), or outside it if inverse.

pub fn is_break_sustaining(&self) -> bool

[client] Sustained sounds: whether the sound is finishing, and letting it finish before it's destroyed.

pub fn stop_break_sustain(&self)
pub fn has_active_camera(&self) -> bool

[client] True while the effect controls the camera.

pub fn bind_event_client_callback(&self, params: &Value, reference: &Value)

[client] Effect event callbacks: reference is the script table that receives them (default: the running script), params is passed through.

pub fn bind_event_server_callback(&self, params: &Value, reference: &Value)
pub fn clear_client_event_callback(&self)

Removes the client / server event callbacks.

pub fn clear_server_event_callback(&self)

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Tool = "Tool" )

A tool a player holds (Lua Tool).

Methods

pub fn animation_info(&self, name: &str) -> AnimationInfo

Information about a third / first person animation.

pub fn fp_animation_info(&self, name: &str) -> AnimationInfo
pub fn camera_weights(&self) -> CameraWeights

[client] Current weights of the tool's camera settings (update_camera / update_fp_camera).

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The tool's id.

pub fn uuid(&self) -> Uuid

The tool's item uuid.

pub fn owner(&self) -> Player

The player holding it.

pub fn is_local(&self) -> bool

True on the owner's client.

pub fn is_equipped(&self) -> bool

True while equipped.

pub fn is_in_first_person_view(&self) -> bool

The owner's view and movement state.

pub fn is_crouching(&self) -> bool
pub fn is_sprinting(&self) -> bool
pub fn is_on_ground(&self) -> bool
pub fn position(&self) -> Vec3

Position and aim direction of the tool.

pub fn direction(&self) -> Vec3
pub fn smooth_direction(&self) -> Vec3

Aim direction, smoothed.

pub fn movement_velocity(&self) -> Vec3

The owner's movement velocity.

pub fn movement_speed_fraction(&self) -> f64

The owner's movement speed scale.

pub fn set_fp_renderables(&self, rends: &[String])

[client] Sets the first / third person renderables (paths to .rend files) and their colors.

pub fn set_tp_renderables(&self, rends: &[String])
pub fn set_fp_color(&self, c: Color)
pub fn set_tp_color(&self, c: Color)
pub fn update_animation(&self, name: &str, time: f64, weight: Option<f64>)

[client] Plays a third person animation; time is seconds into it.

pub fn update_fp_animation(&self, name: &str, time: f64, weight: Option<f64>, looping: bool)

[client] Plays a first person animation.

pub fn set_movement_animation(&self, movement: &str, animation: &str)

[client] Replaces a movement animation (e.g. "idle") with one of the tool's.

pub fn set_movement_slow_down(&self, slow_down: bool)

[client] Slows the owner down while held.

pub fn set_block_sprint(&self, block: bool)

[client] Prevents sprinting while held.

pub fn set_cross_hair_alpha(&self, alpha: f64)

[client] Crosshair alpha, color, type and spread.

pub fn set_cross_hair_color(&self, c: Color)
pub fn set_cross_hair_type(&self, kind: i32)
pub fn set_dispersion_fraction(&self, dispersion: f64)
pub fn update_camera(&self, distance: f64, fov: f64, offset: Vec3, weight: f64)

[client] Blends the camera toward a tool-specific view (aiming, ...).

pub fn fp_bone_position(&self, bone: &str) -> Vec3

[client] A bone's first / third person position.

pub fn tp_bone_position(&self, bone: &str) -> Vec3
pub fn fp_bone_direction(&self, bone: &str, world_space: bool) -> Vec3

[client] Bones: first-person local (or world) space, third-person world space.

pub fn fp_bone_rotation(&self, bone: &str, world_space: bool) -> Quat
pub fn tp_bone_direction(&self, bone: &str) -> Vec3
pub fn tp_bone_rotation(&self, bone: &str) -> Quat
pub fn update_joint(&self, bone: &str, rotation: Vec3, weight: Option<f64>)

[client] Rotates a bone of the animation skeleton.

pub fn update_movement_animation(&self, time: f64, weight: Option<f64>)

[client] Advances the movement animation set with setMovementAnimation.

pub fn relative_move_direction(&self) -> Vec3

[client] Movement direction relative to where the player looks.

pub fn update_fp_camera(&self, fov: f64, offset: Vec3, weight: f64, bobbing: f64)

[client] Blends the first person camera toward a tool-specific view.

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub LoadCellHandle = "LoadCellHandle" )

The handle from World::loadCellWithHandle; the cell stays loaded until released.

Methods

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn release(&self) -> bool

[server] Releases the cell; returns true if it was held.

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Lift = "Lift" )

A player's or non-player lift (Lua Lift).

Methods

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The lift's id.

pub fn level(&self) -> i32

Its height level.

pub fn world_position(&self) -> Vec3

Its position.

pub fn has_bodies(&self) -> bool

True if it carries bodies.

pub fn destroy(&self)

[server] Removes the lift.

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Portal = "Portal" )

A two-opening portal between (or within) worlds. All [server].

Methods

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The portal's id.

pub fn has_opening_a(&self) -> bool

[server] True if opening A / B is placed.

pub fn has_opening_b(&self) -> bool
pub fn set_opening_a(&self, position: Vec3, rotation: Quat, world: &World)

[server] Places opening A / B.

pub fn set_opening_b(&self, position: Vec3, rotation: Quat, world: &World)
pub fn position_a(&self) -> Vec3

[server] Positions, rotations and worlds of the two openings.

pub fn position_b(&self) -> Vec3
pub fn rotation_a(&self) -> Quat
pub fn rotation_b(&self) -> Quat
pub fn world_a(&self) -> World
pub fn world_b(&self) -> World
pub fn transfer_a_to_b(&self, filter: Option<i32>) -> bool

[server] Moves what's in one opening to the other (filter: sm.areaTrigger.filter).

pub fn transfer_b_to_a(&self, filter: Option<i32>) -> bool
pub fn set_a_marker_offset(&self, offset: Vec3)

[server] Map markers: offsets, and whether each direction shows one.

pub fn set_b_marker_offset(&self, offset: Vec3)
pub fn set_a_to_b_marker_allowed(&self, allowed: bool)
pub fn set_b_to_a_marker_allowed(&self, allowed: bool)
pub fn contents_a(&self) -> Vec<Target>
pub fn contents_b(&self) -> Vec<Target>

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Storage = "Storage" )

Server-side save data of a script (ScriptClass::storage()). All [server].

Methods

pub fn save(&self, data: &impl IntoLua)

[server] Saves data for the next time the object loads.

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn load(&self) -> Value

[server] The saved data, or nil.

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Target = "Target" )

A value that may be one of several object types (a collision's "other", a projectile's shooter, ...). Test with is(), convert with to().

Methods

pub fn kind(&self) -> String

The Lua type name: "Shape", "Character", "Harvestable", ..., or "nil".

pub fn is<T: Object>(&self) -> bool

True if the target is a T.

pub fn to<T: Object>(&self) -> T

The target as a T.

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub Unit = "Unit" )

The AI driving a creature (Lua Unit). Most calls are [server].

Methods

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

[server] The unit's id.

pub fn character(&self) -> Character

[server] The character it controls.

pub fn facing_direction(&self) -> Vec3

[server] The current facing / movement direction.

pub fn movement_direction(&self) -> Vec3
pub fn set_facing_direction(&self, d: Vec3)

[server] Sets the direction to face / move in.

pub fn set_movement_direction(&self, d: Vec3)
pub fn set_movement_type(&self, kind: &str)

[server] Sets how to move: "stand", "walk", "sprint", "crouch", ...

pub fn set_wants_jump(&self, jump: bool)

[server] Requests a jump / crouch.

pub fn set_wants_crouch(&self, crouch: bool)
pub fn set_whisker_data(&self, count: i32, max_angle: f64, start_length: f64, end_length: f64)

[server] Configures the obstacle-sensing rays used for movement.

pub fn set_hearing_data(&self, noise_scale: f64)

[server] Scales how well the unit hears noise.

pub fn send_character_event(&self, event: &str)

[server] Fires client_onEvent on the unit's character.

pub fn public_data(&self) -> Value

[server] Data other scripts can read, and setting it.

pub fn set_public_data(&self, t: &Value)
pub fn container(&self, index: i32) -> Container

A container of the unit by index.

pub fn add_container(&self, index: i32, size: i32, stack_size: Option<i32>) -> Container

[server] Adds a container of size slots.

pub fn remove_container(&self, index: i32)

[server] Removes a container.

pub fn destroy(&self)

[server] Destroys the unit.

pub fn create_state(&self, name: &str) -> AiState

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub AiState = "AiState" )

A built-in AI behaviour from Unit::createState. Drive it from server_onUnitUpdate. All [server].

Methods

pub fn is_done(&self) -> AiDone

[server] Whether it's done, and why (e.g. "finished" / "failed").

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn start(&self)

[server] Starts / stops the behaviour.

pub fn stop(&self)
pub fn on_fixed_update(&self, dt: f64)

[server] Advances the behaviour; call from the matching unit callback.

pub fn on_unit_update(&self, dt: f64)
pub fn facing_direction(&self) -> Vec3

[server] What the state wants the unit to do; apply it with the Unit setters.

pub fn movement_direction(&self) -> Vec3
pub fn movement_type(&self) -> String
pub fn wants_jump(&self) -> bool
pub fn wants_crouch(&self) -> bool

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub PathNode = "PathNode" )

A navigation node for sm.pathfinder (pathNodes::create). All [server].

Methods

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn position(&self) -> Vec3

[server] The node's position.

pub fn connect(&self, to: &PathNode)

[server] Links this node to another.

pub fn destroy(&self)

[server] Removes the node.

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub ScriptableObject = "ScriptableObject" )

A scriptable object: a script with no body in the world (Lua ScriptableObject).

Methods

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The object's id.

pub fn world(&self) -> World

The world it's in.

pub fn data(&self) -> Value

The params it was created with.

pub fn public_data(&self) -> Value

[server] Data other server scripts can read.

pub fn set_public_data(&self, t: &Value)

[server] Sets data other server scripts can read.

pub fn client_public_data(&self) -> Value

[client] Data other client scripts can read.

pub fn set_client_public_data(&self, t: &Value)

[client] Sets data other client scripts can read.

pub fn destroy(&self)

[server] Destroys the object.

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

object!(pub ClientScriptableObject = "ClientScriptableObject" )

A scriptable object that only exists on one client (clientScriptableObjects::create). All [client].

Methods

pub fn new(v: Value) -> Self

Wraps a Lua value.

pub fn value(&self) -> &Value

The wrapped Lua value.

pub fn is_nil(&self) -> bool

True for nil.

pub fn exists(&self) -> bool

True when the object still exists in the game (sm.exists).

pub fn id(&self) -> i32

The object's id.

pub fn world(&self) -> World

The world it's in.

pub fn data(&self) -> Value

The params it was created with.

pub fn client_public_data(&self) -> Value

Data other client scripts can read, and setting it.

pub fn set_client_public_data(&self, t: &Value)
pub fn destroy(&self)

Destroys the object.

Implements Clone, Codec, Debug, Default, Display, FromLua, IntoLua, Object, PartialEq

pub fn is_server() -> bool

True when running on the server side.

pub fn is_host() -> bool

True when this game instance hosts the session.

  • crate::script::CullingZoneTree
  • crate::script::InputBlock
  • crate::math::*
  • core_hand::*
  • ai_api::*
  • client_api::*
  • debug_draw_api::*
  • gui_api::*
  • item_api::*
  • render_api::*
  • terrain_api::*
  • trigger_api::*
  • util_api::*
  • world_api::*

Game state and settings (sm.game).

pub fn server_tick() -> i32

The server's tick counter.

pub fn current_tick() -> i32

The current tick (40 per second).

pub fn time_of_day() -> f64

The time of day, 0..1, where 0.5 is noon.

pub fn set_time_of_day(t: f64)

[client] Sets the time of day.

pub fn difficulty() -> i32

The game difficulty.

pub fn aggro_enabled() -> bool

Whether creature aggression is enabled.

pub fn set_aggro_enabled(on: bool)

[server] Enables or disables creature aggression.

pub fn ammo_consumption_enabled() -> bool

Whether ammo consumption is enabled.

pub fn set_ammo_consumption_enabled(on: bool)

[server] Enables or disables ammo consumption.

pub fn fuel_consumption_enabled() -> bool

Whether fuel consumption is enabled.

pub fn set_fuel_consumption_enabled(on: bool)

[server] Enables or disables fuel consumption.

pub fn restrictions_enabled() -> bool

Whether build restrictions are enabled.

pub fn set_restrictions_enabled(on: bool)

[server] Enables or disables build restrictions.

pub fn upgrade_enabled() -> bool

Whether upgrades are enabled.

pub fn set_upgrade_enabled(on: bool)

[server] Enables or disables upgrades.

pub fn recipes_enabled() -> bool

Whether recipes are enabled.

pub fn set_recipes_enabled(on: bool)

[server] Enables or disables recipes.

pub fn limited_inventory() -> bool

Whether the limited inventory is enabled.

pub fn set_limited_inventory(on: bool)

[server] Enables or disables the limited inventory.

pub fn setting_bool(name: &str) -> bool

A game setting by name, as a boolean / number / string.

pub fn setting_number(name: &str) -> f64
pub fn setting_string(name: &str) -> String
pub fn kick(p: &Player)

[server] Kicks a player.

pub fn ban(p: &Player)

[server] Bans a player.

pub fn pause_saving(reason: &str, ticks: i32)

[server] Holds off autosaving while something (named reason) is mid-change.

pub fn resume_saving(reason: &str)

[server] Allows autosaving again.

pub fn exit_to_menu()

Exits to the main menu.

pub fn exit_to_menu_with_end_credits()

Exits to the main menu and plays the end credits.

pub fn load_watched_tutorials() -> Value

[client] The tutorials the user has seen (a table you define).

pub fn save_watched_tutorials(watched: &Value)

[client] Saves the tutorials the user has seen.

Sounds (sm.audio).

pub fn play(sound: &str, position: Option<Vec3>)

Plays a sound, at a position or globally.

pub fn global_parameter(name: &str) -> f64

[client] Reads / writes an FMOD global parameter.

pub fn set_global_parameter(name: &str, value: f64)

Effects (sm.effect).

pub fn play(name: &str, position: Vec3, o: &PlayOptions)

Plays a one-shot effect at a position.

pub fn create(name: &str) -> Effect

Creates an effect you control (see Effect).

pub fn create_2d(name: &str) -> Effect

[client] Creates a screen-space, first-person or sky effect.

pub fn create_first_person(name: &str) -> Effect
pub fn create_sky(name: &str) -> Effect
pub fn estimate_size(name: &str, parameters: &Value) -> f64

[client] The radius of influence of name with these parameters.

  • super::core_hand::effect_hand::*

Physics queries and forces (sm.physics).

pub fn shapes_in_sphere(center: Vec3, radius: f64, world: &World) -> Vec<Shape>

Shapes overlapping a sphere / box.

pub fn shapes_in_box(center: Vec3, rotation: Quat, half_extents: Vec3, world: &World) -> Vec<Shape>
pub fn sphere_has_contact(center: Vec3, radius: f64, include_terrain: bool, count_water: bool) -> bool

Whether anything overlaps a sphere, and how many things.

pub fn sphere_contact_count(center: Vec3, radius: f64, include_terrain: bool, count_water: bool) -> i32
pub fn capsule_has_contact(from: Vec3, to: Vec3, radius: f64, mask: Option<i32>) -> bool

Whether anything overlaps a capsule, and how many things.

pub fn capsule_contact_count(from: Vec3, to: Vec3, radius: f64, mask: Option<i32>) -> i32
pub fn is_point_in_liquid(point: Vec3) -> bool

True if the point / sphere is in liquid.

pub fn is_sphere_in_liquid(center: Vec3, radius: f64) -> bool
pub fn ground_material(point: Vec3) -> String

The ground material at a point.

pub fn material_id(material: &str) -> i32

A physics material's id by name.

pub fn gravity() -> f64

[server] The gravity strength.

pub fn set_gravity(g: f64)

[server] Sets the gravity strength.

  • super::core_hand::physics_hand::*

Players (sm.player).

pub fn all() -> Vec<Player>

Every connected player.

pub fn host() -> Player

The host player.

pub fn local() -> Player

[client] This client's player.

pub fn place_lift(p: &Player, creation: &[Body], position: Vec3, level: i32, rotation: i32)

[server] Same as Player::placeLift / removeLift.

pub fn remove_lift(p: &Player)

Creating and inspecting shapes (sm.shape).

pub fn create_part(uuid: Uuid, position: Vec3, rotation: Quat, dynamic: bool) -> Shape

[server] Creates a part.

pub fn create_block(uuid: Uuid, size: Vec3, position: Vec3, rotation: Quat, dynamic: bool) -> Shape

[server] Creates a block of size.

pub fn create_wedge(uuid: Uuid, size: Vec3, position: Vec3, rotation: Quat, dynamic: bool, force_spawn: bool) -> Shape

[server] Creates a wedge of size with its corner at position.

pub fn title(uuid: Uuid) -> String

An item's display name / upper-case display name.

pub fn upper_case_title(uuid: Uuid) -> String
pub fn type_color(uuid: Uuid) -> Color

The color of the shape's type (block, part, ...) in the inventory.

pub fn is_harvest(uuid: Uuid) -> bool

True for a harvested item / a stackable item.

pub fn is_stackable(uuid: Uuid) -> bool
pub fn exists(uuid: Uuid) -> bool

True if a shape with this uuid exists.

pub fn in_sphere(center: Vec3, radius: f64) -> Vec<Shape>

Shapes within a sphere.

Bodies (sm.body).

pub fn create(position: Vec3, rotation: Quat, dynamic: bool) -> Body

[server] Creates an empty body to build on (Body::createBlock / createPart).

pub fn all(world: &World) -> Vec<Body>

Every body, optionally in one world.

pub fn creations(bodies: &[Body]) -> Vec<Vec<Body>>

Groups bodies by creation.

JSON (sm.json).

pub fn parse(text: &str) -> Value

Parses a JSON string.

pub fn stringify(v: &Value, pretty: bool) -> String

Converts a value to JSON.

pub fn open(path: &str) -> Value

Reads a JSON file. Paths use the usual prefixes: "$CONTENT_DATA/...".

pub fn exists(path: &str) -> bool

True if the file exists.

pub fn save(root: &Value, path: &str)

Writes root (a table) as JSON. Only paths the game lets mods write, e.g. "$CONTENT_DATA/...".

[server] AI units (sm.unit).

pub fn create(uuid: Uuid, position: Vec3, yaw: f64, data: &Value) -> Unit

[server] Creates a unit of the character type uuid, feet at position, facing yaw radians.

pub fn all() -> Vec<Unit>

[server] Every unit.

pub fn in_range(world: &World, position: Vec3, range: f64) -> Vec<Unit>

[server] Units within range of a position.

pub fn force_destroy(unit: &Unit)

[server] Destroys the unit right away, skipping its death logic.

[server] Harvestables (sm.harvestable).

Functions in atl::sm::harvestables

Section titled "Functions in atl::sm::harvestables"
pub fn create(uuid: Uuid, position: Vec3, rotation: Quat) -> Harvestable

[server] Creates a harvestable.

pub fn all() -> Vec<Harvestable>

Every harvestable.

pub fn by_initial_hash(hash: f64) -> Harvestable

The kinematic with this Harvestable::initialHash() (empty if none).

Characters (sm.character).

pub fn create(player: &Player, world: &World, position: Vec3, yaw: f64, pitch: f64) -> Character

[server] Creates a character for a player in a world.

Scriptable objects (sm.scriptableObject).

Functions in atl::sm::scriptable_objects

Section titled "Functions in atl::sm::scriptable_objects"
pub fn create(uuid: Uuid, params: &Value) -> ScriptableObject

[server] Creates a scriptable object.

Container transactions (sm.container).

pub fn abort_transaction()

[server] Cancels the running transaction.

  • super::core_hand::container_hand::*

Game-wide save data (sm.storage).

pub fn load(key: &str) -> Value

Loads a value saved under a key.

pub fn load_terrain_data(world_id: i32) -> Value

The terrain data a world's terrain script saved.

  • super::core_hand::storage_hand::*