### StartLevel Source: https://www.teardowngame.com/modding/api.html Starts a level with specified parameters. ```APIDOC ## StartLevel(mission, path, [layers], [passThrough]) ### Description Starts a level. ### Parameters - **mission** (string) - Required - An identifier of your choice - **path** (string) - Required - Path to level XML file - **layers** (string) - Optional - Active layers. Default is no layers. - **passThrough** (boolean) - Optional - If set, loading screen will have no text and music will keep playing ``` -------------------------------- ### PlayMusic Source: https://www.teardowngame.com/modding/api.html Starts playing a music track. ```APIDOC ## PlayMusic(path) ### Description Plays the music file located at the specified path. ### Parameters - **path** (string) - Required - Music path ``` -------------------------------- ### Initiate Path Query Source: https://www.teardowngame.com/modding/api.html Starts an asynchronous path planning query using the default path planner. ```lua function client.init() QueryPath(Vec(-10, 0, 0), Vec(10, 0, 0)) end ``` -------------------------------- ### UiBeginFrame Source: https://www.teardowngame.com/modding/api.html Starts a measurement frame to calculate the size of contained UI elements. ```APIDOC ## UiBeginFrame ### Description Call to start measuring the content size. Use in conjunction with UiEndFrame to calculate the total size of drawn elements. ### Signature `UiBeginFrame()` ``` -------------------------------- ### Begin Frame Measurement Source: https://www.teardowngame.com/modding/api.html Starts a measurement block to calculate the size of contained UI elements. ```lua UiBeginFrame() ``` ```lua function client.draw() UiPush() UiBeginFrame() UiColor(1.0, 1.0, 0.8) UiTranslate(UiCenter(), 300) UiFont("bold.ttf", 40) UiText("Hello") local panelWidth, panelHeight = UiEndFrame() DebugPrint(math.ceil(panelWidth) .. "x" .. math.ceil(panelHeight)) UiPop() end ``` -------------------------------- ### RegisterTool Usage Source: https://www.teardowngame.com/modding/api.html Example of registering and enabling a custom tool on the server and handling input on both server and client. ```lua #include "script/include/player.lua" function server.init() RegisterTool("lasergun", "Laser Gun", "MOD/vox/lasergun.vox", 6) end function server.tick() for p in PlayersAdded() do SetToolEnabled("lasergun", true, p) SetToolAmmo("lasergun", 60, p) end for p in Players() do if GetPlayerTool(p) == "lasergun" then --Tool is selected. Tool logic goes here. if InputPressed("usetool", p) then -- Fire the tool end end end end function client.tick() for p in Players() do if GetPlayerTool(p) == "lasergun" then if InputPressed("usetool", p) then -- Spawn client side particles, play sound, etc. end end end end ``` -------------------------------- ### GetPlayerRig Source: https://www.teardowngame.com/modding/api.html Gets the rig handle for a player. ```APIDOC ## GetPlayerRig([playerId]) ### Description Retrieves the rig handle for the specified player. ### Parameters - **playerId** (number) - Optional - Player ID. On client, zero means client player. On server, zero means server (host) player. ### Return Value - **rig** (number) - Rig handle ``` -------------------------------- ### BeginAnimationGroup Source: https://www.teardowngame.com/modding/api.html Starts a group for blending multiple looping animations together. ```lua --This will blend an entire group with 50% influence BeginAnimationGroup(animator, 0.5) PlayAnimationLoop(...) PlayAnimationLoop(...) EndAnimationGroup(animator) --You can also create a tree of groups, blending is performed in a depth-first order BeginAnimationGroup(animator, 0.5) PlayAnimationLoop(animator, "anim_a", 1.0) PlayAnimationLoop(animator, "anim_b", 0.2) BeginAnimationGroup(animator, 0.75) PlayAnimationLoop(animator, "anim_c", 1.0) PlayAnimationLoop(animator, "anim_d", 0.25) EndAnimationGroup(animator) EndAnimationGroup(animator) ``` -------------------------------- ### SetBrush Lua Example Source: https://www.teardowngame.com/modding/api.html Configures the brush settings used for subsequent voxel drawing operations. ```lua function server.init() SetBrush("sphere", 3, 3) end ``` -------------------------------- ### Get Game Version Source: https://www.teardowngame.com/modding/api.html Retrieves the current game version as a dot-separated string. ```lua version = GetVersion() ``` ```lua function init() local v = GetVersion() --v is "0.5.0" DebugPrint(v) end ``` -------------------------------- ### GetTime Source: https://www.teardowngame.com/modding/api.html Returns the time in seconds since the level was started. ```APIDOC ## GetTime ### Description Returns the time in seconds since the level was started. If called from update, this returns the simulated time, otherwise it returns wall time. ### Signature `time = GetTime()` ### Return Value - **time** (number) - The time in seconds since level was started ``` -------------------------------- ### CopyShapePalette Lua Example Source: https://www.teardowngame.com/modding/api.html Copies the material palette from a source shape to a destination shape. ```lua function server.init() CopyShapePalette(FindShape("shape", true), FindShape("shape2", true)) end ``` -------------------------------- ### DrawShapeBox Lua Example Source: https://www.teardowngame.com/modding/api.html Draws a box into a shape using the currently configured brush. ```lua function server.init() SetBrush("sphere", 3, 4) DrawShapeBox(FindShape("shape", true), 0, 0, 0, 10, 50, 5) end ``` -------------------------------- ### Begin Navigation Group Source: https://www.teardowngame.com/modding/api.html Starts a new navigation group scope to aggregate components. The group acts as a parent entity for all components declared within its scope. ```lua id = UiNavGroupBegin([id]) ``` ```lua function client.draw() -- window declaration is necessary for navigation to work UiWindow(1920, 1080) if LastInputDevice() == UI_DEVICE_GAMEPAD then -- active mouse cursor has higher priority over the gamepad control -- so it will reset focused components if the mouse moves UiSetCursorState(UI_CURSOR_HIDE_AND_LOCK) end UiTranslate(960, 540) local gId = UiNavGroupBegin() UiNavComponent(100, 20) UiTranslate(0, 50) local id = UiNavComponent(100, 20) local isInFocus = UiIsComponentInFocus(id) UiNavGroupEnd() local groupInFocus = UiIsComponentInFocus(gId) if isInFocus then DebugPrint(groupInFocus) end end ``` -------------------------------- ### Get player rig Source: https://www.teardowngame.com/modding/api.html Retrieves the rig handle currently assigned to the player. ```lua rig = GetPlayerRig([playerId]) ``` ```lua local rig = GetPlayerRig(rigid) ``` -------------------------------- ### Get Image Size Source: https://www.teardowngame.com/modding/voxscript.html Returns the width and height of the currently loaded image. ```lua width, height = GetImageSize() ``` ```lua function init() LoadImage("MOD/image.png") local w, h = GetImageSize() end ``` -------------------------------- ### GetShapePalette Lua Example Source: https://www.teardowngame.com/modding/api.html Retrieves a table of material entries from a shape, which can be used for material lookups or as brushes. ```lua function server.init() local palette = GetShapePalette(FindShape("shape2", true)) for i = 1, #palette do DebugPrint(palette[i]) end end ``` -------------------------------- ### client.init() Source: https://www.teardowngame.com/modding/api.html Called once at load time on the client. ```APIDOC ## function client.init() ### Description Called once at load time on the client. ``` -------------------------------- ### Get Simulation Time Source: https://www.teardowngame.com/modding/api.html Returns the time in seconds since the level started. Returns simulated time in update calls, otherwise wall time. ```lua time = GetTime() ``` ```lua function client.update() local t = GetTime() DebugPrint(t) end ``` -------------------------------- ### server.init() Source: https://www.teardowngame.com/modding/api.html Called once at load time on the server. ```APIDOC ## function server.init() ### Description Called once at load time on the server. ``` -------------------------------- ### PathPlannerQuery(id, start, end, [maxDist], [targetRadius], [type]) Source: https://www.teardowngame.com/modding/api.html Initiates a path planning query using a specific path planner instance. ```APIDOC ## PathPlannerQuery(id, start, end, [maxDist], [targetRadius], [type]) ### Description Works similarly to QueryPath but allows multiple paths to be built simultaneously using specific planner instances. ### Parameters - **id** (number) - Required - Path planner id - **start** (TVec) - Required - World space start point - **end** (TVec) - Required - World space target point - **maxDist** (number) - Optional - Maximum path length - **targetRadius** (number) - Optional - Maximum allowed distance to target - **type** (string) - Optional - Type of path ``` -------------------------------- ### QueryPath(start, end, [maxDist], [targetRadius], [type]) Source: https://www.teardowngame.com/modding/api.html Initiates an asynchronous path planning query using the default path planner (id 0). ```APIDOC ## QueryPath(start, end, [maxDist], [targetRadius], [type]) ### Description Initiates an asynchronous path planning query. The result is processed in the background, and the status can be checked via GetPathState. ### Parameters - **start** (TVec) - Required - World space start point - **end** (TVec) - Required - World space target point - **maxDist** (number) - Optional - Maximum path length before giving up - **targetRadius** (number) - Optional - Maximum allowed distance to target in meters - **type** (string) - Optional - Type of path ("low", "standart", "water", "flying") ``` -------------------------------- ### SetPlayerParam Usage Source: https://www.teardowngame.com/modding/api.html Example of setting player jump speed based on input within a server tick function. ```lua function server.tick() -- The parameter names are case-insensitive, so any of the specified writing styles will be correct: -- "JumpSpeed", "jumpspeed", "jumpSpeed" local paramName = "JumpSpeed" for p in Players() do -- Set player jump speed based on whether shift is pressed if InputDown("shift", p) then SetPlayerParam(paramName, 10, p) else SetPlayerParam(paramName, 5, p) end end end ``` -------------------------------- ### GetPlayerParam Usage Source: https://www.teardowngame.com/modding/api.html Example of retrieving a player parameter within a client tick function. ```lua function client.tick() -- The parameter names are case-insensitive, so any of the specified writing styles will be correct: -- "GodMode", "godmode", "godMode" local paramName = "GodMode" local param = GetPlayerParam(paramName) DebugWatch(paramName, param) end ``` -------------------------------- ### TrimAnimationClip Source: https://www.teardowngame.com/modding/api.html Trims the start and end of an animation clip. ```APIDOC ## TrimAnimationClip(handle, name, begoffset, [endoffset]) ### Description Trims the animation clip based on beginning and end offsets. ### Parameters - **handle** (number) - Required - Animator handle - **name** (string) - Required - Animation name - **begoffset** (number) - Required - Time offset from beginning - **endoffset** (number) - Optional - Time offset from end ``` -------------------------------- ### StartLevel API Usage Source: https://www.teardowngame.com/modding/api.html Initiates a level load. Supports optional layers and pass-through mode for loading screens. ```lua StartLevel(mission, path, [layers], [passThrough]) ``` ```lua function server.init() --Start level with no active layers StartLevel("level1", "MOD/level1.xml") --Start level with two layers StartLevel("level1", "MOD/level1.xml", "vehicles targets") end ``` -------------------------------- ### Get and set sound progress Source: https://www.teardowngame.com/modding/api.html Retrieves or modifies the current playback position of a sound handle in seconds. ```lua progress = GetSoundProgress(handle) ``` ```lua SetSoundProgress(handle, progress) ``` ```lua local snd function client.init() snd = LoadSound("radio/jazz.ogg") end local sndPlay function client.tick() if InputPressed("interact") then if not IsSoundPlaying(sndPlay) then local pos = Vec(0, 0, 0) sndPlay = PlaySound(snd, pos, 0.5) else SetSoundProgress(sndPlay, GetSoundProgress(sndPlay) - 1.0) end end end ``` -------------------------------- ### GetTriggerBounds Source: https://www.teardowngame.com/modding/api.html Gets the axis-aligned bounding box of a trigger. ```APIDOC ## GetTriggerBounds ### Description Returns the lower and upper points in world space of the trigger axis-aligned bounding box. ### Signature `min, max = GetTriggerBounds(handle)` ### Arguments - **handle** (number) - Trigger handle ### Return value - **min** (TVec) - Lower point of trigger bounds in world space - **max** (TVec) - Upper point of trigger bounds in world space ``` -------------------------------- ### GetTriggerTransform Source: https://www.teardowngame.com/modding/api.html Gets the world space transform of a trigger. ```APIDOC ## GetTriggerTransform ### Description Retrieves the current transform of a trigger in world space. ### Signature `transform = GetTriggerTransform(handle)` ### Arguments - **handle** (number) - Trigger handle ### Return value - **transform** (TTransform) - Current trigger transform in world space ``` -------------------------------- ### Registering a spawnable asset in spawn.txt Source: https://www.teardowngame.com/modding Defines the path to a prefab file and its display name/category in the spawn menu. ```text path/to/mycar.xml : Cars/My car ``` -------------------------------- ### TrimAnimationClip Source: https://www.teardowngame.com/modding/api.html Trims the start and end times of an animation clip. ```lua TrimAnimationClip(handle, name, begoffset, [endoffset]) ``` ```lua --This will "remove" 1s from the beginning and 2s from the end. TrimAnimationClip(animator, "walking", 1, -2) ``` -------------------------------- ### Configure info.txt Metadata Source: https://www.teardowngame.com/modding The info.txt file provides essential mod metadata and Steam Workshop categorization tags. ```text name = Laser Gun author = Tuxedo Labs description = Custom tool example mod. Laser gun that cuts through most materials tags = Tool ``` -------------------------------- ### DrawShapeLine Lua Example Source: https://www.teardowngame.com/modding/api.html Draws a voxelized line into a shape using the currently configured brush. ```lua function server.init() SetBrush("sphere", 3, 1) DrawShapeLine(FindShape("shape"), 0, 0, 0, 10, 50, 5, false, true) end ``` -------------------------------- ### Get Function Definition Source: https://www.teardowngame.com/modding/voxscript.html Defines the signature for retrieving a voxel's material ID. ```lua material = Get(x, y, z) ``` -------------------------------- ### Menu API Usage Source: https://www.teardowngame.com/modding/api.html Returns the player to the main menu. ```lua Menu() ``` ```lua function client.tick() if InputPressed("interact") then Menu() end end ``` -------------------------------- ### UiGetCanvasMousePos Source: https://www.teardowngame.com/modding/api.html Gets the mouse position in UI canvas space. ```APIDOC ## UiGetCanvasMousePos ### Description Returns the position of the mouse cursor in UI canvas space. ### Return Values - **x** (number) - X coordinate - **y** (number) - Y coordinate ``` -------------------------------- ### UiGetMousePos Source: https://www.teardowngame.com/modding/api.html Gets the mouse pointer position relative to the cursor. ```APIDOC ## UiGetMousePos ### Description Get mouse pointer position relative to the cursor. ### Return Values - **x** (number) - X coordinate - **y** (number) - Y coordinate ``` -------------------------------- ### Create and Use Path Planners Source: https://www.teardowngame.com/modding/api.html Creates a new path planner for parallel calculations and executes queries using specific planner IDs. ```lua local paths = {} function server.init() paths[1] = { id = CreatePathPlanner(), location = GetProperty(FindEntity("loc1", true), "transform").pos, } paths[2] = { id = CreatePathPlanner(), location = GetProperty(FindEntity("loc2", true), "transform").pos, } for i = 1, #paths do PathPlannerQuery(paths[i].id, GetPlayerTransform().pos, paths[i].location) end end ``` -------------------------------- ### GetWindVelocity Source: https://www.teardowngame.com/modding/api.html Gets the wind velocity at a provided world position. ```APIDOC ## GetWindVelocity ### Description Returns the wind velocity at a provided point, determined by the environment wind property and procedural variation. ### Signature `vel = GetWindVelocity(point)` ### Parameters - **point** (TVec) - Required - World point as vector ### Return Value - **vel** (TVec) - Wind at provided position ``` -------------------------------- ### UiWindow(width, height, [clip], [inherit]) Source: https://www.teardowngame.com/modding/api.html Sets up new UI bounds for window-relative operations. ```APIDOC ## UiWindow(width, height, [clip], [inherit]) ### Description Sets up new bounds. Calls to UiWidth, UiHeight, UiCenter, and UiMiddle operate within this window context. ### Parameters - **width** (number) - Required - Window width - **height** (number) - Required - Window height - **clip** (boolean) - Optional - Clip content outside window - **inherit** (boolean) - Optional - Inherit current clip region ``` -------------------------------- ### Loading a level via Lua script Source: https://www.teardowngame.com/modding Uses the StartLevel function to load an additional level XML file from the mod directory. ```lua -- Load level 2 StartLevel("level2", "MOD/mymodlevel2.xml") ``` -------------------------------- ### GetPlayerRigWorldTransform Source: https://www.teardowngame.com/modding/api.html Gets the world transform of the player's rig. ```APIDOC ## GetPlayerRigWorldTransform([playerId]) ### Description Gets the world transform of the player's rig. ### Parameters - **playerId** (number) - Optional - Player ID. On client, zero means client player. On server, zero means server (host) player. ### Return Value - **transform** (TTransform) - World transform, nil if player doesn't have a rig ``` -------------------------------- ### Get Text Dimensions Source: https://www.teardowngame.com/modding/api.html Retrieves the width, height, and AABB offsets for a given text string. ```lua w, h, x, y = UiGetTextSize(text) ``` ```lua local w, h = UiGetTextSize("Some text") ``` -------------------------------- ### CopyShapeContent Lua Example Source: https://www.teardowngame.com/modding/api.html Copies voxel content from a source shape to a destination shape, resizing the destination if necessary. ```lua function server.init() CopyShapeContent(FindShape("shape", true), FindShape("shape2", true)) end ``` -------------------------------- ### Create Material Source: https://www.teardowngame.com/modding/voxscript.html Creates a material handle with specified color and physical properties. ```lua material = CreateMaterial(type, r, g, b, [a], [reflect], [shiny], [metal], [emissive]) ``` ```lua function init() local brick = CreateMaterial("masonry", 0.6, 0.5, 0.3, 0, 0.1, 0, 0) end ``` -------------------------------- ### GetPlayerWalkingSpeed Source: https://www.teardowngame.com/modding/api.html Gets the current base walking speed of the player. ```APIDOC ## GetPlayerWalkingSpeed ### Description Gets the current base walking speed of the player. Note that real speed depends on factors like health, crouch, water, and grabbing objects. ### Signature speed = GetPlayerWalkingSpeed([playerId]) ### Parameters - **playerId** (number) - Optional - Player ID. On client, zero means client player. On server, zero means server (host) player. ### Return Value - **speed** (number) - Current player base walking speed. ``` -------------------------------- ### Menu Source: https://www.teardowngame.com/modding/api.html Returns to the main menu. ```APIDOC ## Menu() ### Description Go to main menu. ``` -------------------------------- ### SetPlayerAnimator / GetPlayerAnimator Source: https://www.teardowngame.com/modding/api.html Sets or gets the animator handle for a player. ```APIDOC ## SetPlayerAnimator ### Description Sets the animator handle for a player. ### Parameters - **animator** (number) - Required - Handle to animator or zero for no animator - **playerId** (number) - Optional - Player ID. ## GetPlayerAnimator ### Description Gets the animator handle for a player. ### Parameters - **playerId** (number) - Optional - Player ID. ### Return Value - **animator** (number) - Handle to animator or zero for no animator ``` -------------------------------- ### GetAnimationInstancePosition Source: https://www.teardowngame.com/modding/api.html Gets the current play position of an animation instance. ```APIDOC ## GetAnimationInstancePosition(handle, instance) ### Description Returns the current play position time of the animation instance. ### Parameters - **handle** (number) - Required - Animator handle - **instance** (number) - Required - Instance handle ### Returns - **time** (number) - Current play position ``` -------------------------------- ### GetAnimationClipLoopPosition Source: https://www.teardowngame.com/modding/api.html Gets the current play position of an animation clip. ```APIDOC ## GetAnimationClipLoopPosition(handle, name) ### Description Returns the current play position time of the animation clip. ### Parameters - **handle** (number) - Required - Animator handle - **name** (string) - Required - Animation name ### Returns - **time** (number) - Current play position ``` -------------------------------- ### Find screen by tag Source: https://www.teardowngame.com/modding/api.html Retrieves the handle for the first screen matching the specified tag. ```lua handle = FindScreen([tag], [global]) ``` ```lua function client.init() local screen = FindScreen("tv") DebugPrint(screen) end ``` -------------------------------- ### GetAnimationClipDuration Source: https://www.teardowngame.com/modding/api.html Gets the total duration of a specific animation clip. ```APIDOC ## GetAnimationClipDuration(handle, name) ### Description Returns the total duration of the specified animation clip. ### Parameters - **handle** (number) - Required - Animator handle - **name** (string) - Required - Animation name ### Returns - **time** (number) - Total duration of the animation ``` -------------------------------- ### Get Brush Size Source: https://www.teardowngame.com/modding/voxscript.html Returns the dimensions of the brush in voxels. ```lua x, y, z = GetBrushSize(brush) ``` ```lua function init() local brush = CreateBrush("brush/white.vox") local brick = CreateMaterial("masonry", 0.6, 0.5, 0.3, 0, 0.1, 0, 0) Material(brick) Vox(0,0,0) Box(0, 0, 0, 10, 10, 10) local xs, ys, zs = GetBrushSize(brush) end ``` -------------------------------- ### LoadLoop Source: https://www.teardowngame.com/modding/api.html Loads an OGG sound file as a loopable asset. ```APIDOC ## LoadLoop(path, [nominalDistance]) ### Description Loads an ogg sound file as a loop. ### Parameters - **path** (string) - Required - Path to ogg sound file - **nominalDistance** (number) - Optional - The distance in meters this sound is recorded at. Affects attenuation, default is 10.0 ### Return Value - **handle** (number) - Loop handle ``` -------------------------------- ### LoadHaptic Source: https://www.teardowngame.com/modding/api.html Loads a haptic effect from a file path and returns a handle. ```APIDOC ## LoadHaptic ### Description Loads a haptic effect from a specified file path. ### Signature handle = LoadHaptic(filepath) ### Parameters - **filepath** (string) - Required - Path to Haptic effect to play ### Return Value - **handle** (string) - Haptic effect handle ``` -------------------------------- ### Draw Line Source: https://www.teardowngame.com/modding/voxscript.html Draws a line from a start point to an end point. ```lua function init() Vox(0,0,0) local brush = CreateBrush("brush/white.vox") local brick = CreateMaterial("masonry", 0.6, 0.5, 0.3, 0, 0.1, 0, 0) Material(brick) Line(0, 0, 0, 15) end ``` -------------------------------- ### Material Source: https://www.teardowngame.com/modding/voxscript.html Sets the current material or brush. ```APIDOC ## Material(material) ### Description Set current material or brush. Pass in zero to remove content. ### Parameters - **material** (number) - Required - Material or brush handle ``` -------------------------------- ### Get Font Height Source: https://www.teardowngame.com/modding/api.html Returns the height of the currently active font. ```lua size = UiFontHeight() ``` ```lua local h = UiFontHeight() ``` -------------------------------- ### Get Tool Ammo Source: https://www.teardowngame.com/modding/api.html Retrieves the current ammo count for a tool. ```lua ammo = GetToolAmmo(toolId, [playerId]) ``` ```lua local ammo = GetToolAmmo("gun", 1) ``` -------------------------------- ### Line(xStart, yStart, zStart, xEnd, yEnd, zEnd, thicknessStart, thicknessEnd) Source: https://www.teardowngame.com/modding/voxscript.html Draws a line between two points. ```APIDOC ## Line(xStart, yStart, zStart, xEnd, yEnd, zEnd, thicknessStart, thicknessEnd) ### Description Draws a line from start point to end point. ### Parameters - **xStart** (number) - Required - X start - **yStart** (number) - Required - Y start - **zStart** (number) - Required - Z start - **xEnd** (number) - Required - X end - **yEnd** (number) - Required - Y end - **zEnd** (number) - Required - Z end - **thicknessStart** (number) - Required - Start thickness - **thicknessEnd** (number) - Required - End thickness ``` -------------------------------- ### RegisterTool Syntax Source: https://www.teardowngame.com/modding/api.html Syntax for registering a custom tool. ```lua RegisterTool(id, name, file, [group]) ``` -------------------------------- ### GetPlayerHurtSpeedScale Source: https://www.teardowngame.com/modding/api.html Gets the current player walking speed scale when hurt. ```APIDOC ## GetPlayerHurtSpeedScale ### Description Gets the current player walking speed scale when hurt. ### Signature speed = GetPlayerHurtSpeedScale([playerId]) ### Parameters - **playerId** (number) - Optional - Player ID. On client, zero means client player. On server, zero means server (host) player. ### Return Value - **speed** (number) - Current player walking speed when hurt. ``` -------------------------------- ### GetPlayerCrouchSpeedScale Source: https://www.teardowngame.com/modding/api.html Gets the current player walking speed scale while crouched. ```APIDOC ## GetPlayerCrouchSpeedScale ### Description Gets the current player walking speed scale while crouched. ### Signature speed = GetPlayerCrouchSpeedScale([playerId]) ### Parameters - **playerId** (number) - Optional - Player ID. On client, zero means client player. On server, zero means server (host) player. ### Return Value - **speed** (number) - Current player walking speed while crouched. ``` -------------------------------- ### LoadSound Source: https://www.teardowngame.com/modding/api.html Loads an OGG sound file into memory and returns a handle. ```APIDOC ## LoadSound(path, [nominalDistance]) ### Description Loads an ogg sound file for later playback. ### Parameters - **path** (string) - Required - Path to ogg sound file - **nominalDistance** (number) - Optional - The distance in meters this sound is recorded at. Affects attenuation, default is 10.0 ### Return Value - **handle** (number) - Sound handle ``` -------------------------------- ### GetAnimationInstancePosition Source: https://www.teardowngame.com/modding/api.html Gets the current playback position of a specific animation instance. ```lua time = GetAnimationInstancePosition(handle, instance) ``` -------------------------------- ### LoadLoop Source: https://www.teardowngame.com/modding/api.html Loads an OGG file as a looping sound. Requires manual playback via PlayLoop. ```lua handle = LoadLoop(path, [nominalDistance]) ``` ```lua local loop function client.init() loop = LoadLoop("radio/jazz.ogg") end function client.tick() local pos = Vec(0, 0, 0) PlayLoop(loop, pos, 1.0) end ``` -------------------------------- ### GetAnimationClipLoopPosition Source: https://www.teardowngame.com/modding/api.html Gets the current playback position of a looping animation clip. ```lua time = GetAnimationClipLoopPosition(handle, name) ``` -------------------------------- ### InputValue Source: https://www.teardowngame.com/modding/api.html Gets the value of a specific input, such as mouse wheel movement. ```APIDOC ## InputValue(input, [playerId]) ### Description Returns the value associated with the input identifier. ### Parameters - **input** (string) - The input identifier. - **playerId** (number, optional) - Player ID. ### Return Value - **value** (number) - The input value. ``` -------------------------------- ### SetPlayerParam Syntax Source: https://www.teardowngame.com/modding/api.html Syntax for setting player parameters, which must be executed on the server. ```lua SetPlayerParam(parameter, value, [player]) ``` -------------------------------- ### Load Level with Specific Layers Source: https://www.teardowngame.com/modding Use the StartLevel function to load a level with a specific set of active layers. The layers argument is a space-separated string of layer names. ```lua -- Load level 2 with Layers 'heist' and 'secrets' active StartLevel("level2", "MOD/mymodlevel2.xml", "heist secrets") ``` ```lua -- Load level 2 with Layer 'sandbox' active StartLevel("level2", "MOD/mymodlevel2.xml", "sandbox") ``` -------------------------------- ### UiGetFrameNo usage Source: https://www.teardowngame.com/modding/api.html Retrieves the current frame number since the level started. ```lua frameNo = UiGetFrameNo() ``` ```lua function client.draw() local fNo = GetFrame() DebugPrint(fNo) end ``` -------------------------------- ### Create Text Button Source: https://www.teardowngame.com/modding/api.html Creates a button with text and returns true if clicked. ```lua pressed = UiTextButton(text, [w], [h]) ``` ```lua if UiTextButton("Test") then ... end ``` -------------------------------- ### LoadHaptic Source: https://www.teardowngame.com/modding/api.html Loads a haptic effect from a file path. Returns a handle used for playback. ```lua handle = LoadHaptic(filepath) ``` ```lua -- Rumble with gun Haptic effect function client.init() haptic_effect = LoadHaptic("haptic/gun_fire.xml") end function client.tick() if trigHaptic then PlayHaptic(haptic_effect, 1) end end ``` -------------------------------- ### Get Image Dimensions Source: https://www.teardowngame.com/modding/api.html Retrieves the width and height of a specified image file. ```lua w, h = UiGetImageSize(path) ``` ```lua local w,h = UiGetImageSize("test.png") ``` -------------------------------- ### Get UI Cursor Position Source: https://www.teardowngame.com/modding/api.html Retrieves the current position of the UI cursor. ```lua UiGetCursorPos() ``` ```lua function client.draw() UiTranslate(100, 50) x, y = UiGetCursorPos() DebugPrint("x: " .. x .. "; y: " .. y) end ``` -------------------------------- ### Configure Button Background Source: https://www.teardowngame.com/modding/api.html Sets a 9-slice image as the background for subsequent buttons. ```lua UiButtonImageBox(path, borderWidth, borderHeight, [r], [g], [b], [a]) ``` ```lua UiButtonImageBox("button-9slice.png", 10, 10) if UiTextButton("Test") then ... end ``` -------------------------------- ### Get Canvas Size Source: https://www.teardowngame.com/modding/api.html Returns the current dimensions of the UI coordinate space. ```lua value = UiCanvasSize() ``` ```lua function client.draw() UiPush() local canvas = UiCanvasSize() UiWindow(canvas.w, canvas.h) --[[ ... ]] UiPop() end ``` -------------------------------- ### Get UI Scale Source: https://www.teardowngame.com/modding/api.html Retrieves the current scale factors of the UI context. ```lua x, y = UiGetScale() ``` ```lua function client.draw() UiPush() UiScale(2) x, y = UiGetScale() DebugPrint(x .. " " .. y) UiPop() end ``` -------------------------------- ### Create Image Button Source: https://www.teardowngame.com/modding/api.html Creates a button using an image and returns true if clicked. ```lua pressed = UiImageButton(path) ``` ```lua if UiImageButton("image.png") then ... end ``` -------------------------------- ### CreatePathPlanner() Source: https://www.teardowngame.com/modding/api.html Creates a new path planner instance for parallel path calculations. ```APIDOC ## CreatePathPlanner() ### Description Creates a new path planner that can be used to calculate multiple paths in parallel. Returns a unique identifier for the planner. ### Returns - **id** (number) - Path planner id ``` -------------------------------- ### Create QuatAlignXZ Source: https://www.teardowngame.com/modding/api.html Returns a quaternion aligned to the specified X and Z axes. ```lua quat = QuatAlignXZ(xAxis, zAxis) ``` ```lua function update() local laserSprite = LoadSprite("gfx/laser.png") local origin = Vec(0, 0, 0) local dir = Vec(1, 0, 0) local length = 10 local hitPoint = VecAdd(origin, VecScale(dir, length)) local t = Transform(VecLerp(origin, hitPoint, 0.5)) local xAxis = VecNormalize(VecSub(hitPoint, origin)) local zAxis = VecNormalize(VecSub(origin, GetCameraTransform().pos)) t.rot = QuatAlignXZ(xAxis, zAxis) DrawSprite(laserSprite, t, length, 0.05+math.random()*0.01, 8, 4, 4, 1, true, true) DrawSprite(laserSprite, t, length, 0.5, 1.0, 0.3, 0.3, 1, true, true) end ``` -------------------------------- ### Get Player Bodies Source: https://www.teardowngame.com/modding/api.html Retrieves a list of bodies associated with the specified player. ```lua bodies = GetPlayerBodies([playerId]) ``` ```lua local bodies = GetPlayerBodies(playerId) ``` -------------------------------- ### Manipulate Trigger Transforms Source: https://www.teardowngame.com/modding/api.html Gets or sets the world space transform of a trigger. ```lua transform = GetTriggerTransform(handle) ``` ```lua function client.init() local trigger = FindTrigger("toxic") local t = GetTriggerTransform(trigger) DebugPrint(t.pos) end ``` ```lua SetTriggerTransform(handle, transform) ``` ```lua function server.init() local trigger = FindTrigger("toxic") local t = Transform(Vec(0, 1, 0), QuatEuler(0, 90, 0)) SetTriggerTransform(trigger, t) end ``` -------------------------------- ### Registry Data Access Source: https://www.teardowngame.com/modding/api.html Methods for setting and getting typed values in the registry. ```lua SetInt(key, value, [sync]) ``` ```lua function init() SetInt("score.levels.level1", 4) DebugPrint(GetInt("score.levels.level1")) end ``` ```lua value = GetInt(key) ``` ```lua function init() SetInt("score.levels.level1", 4) DebugPrint(GetInt("score.levels.level1")) end ``` ```lua SetFloat(key, value, [sync]) ``` ```lua function init() SetFloat("level.time", 22.3) DebugPrint(GetFloat("level.time")) end ``` ```lua value = GetFloat(key) ``` ```lua function init() SetFloat("level.time", 22.3) DebugPrint(GetFloat("level.time")) end ``` ```lua SetBool(key, value, [sync]) ``` ```lua function init() SetBool("level.robots.enabled", true) DebugPrint(GetBool("level.robots.enabled")) end ``` ```lua value = GetBool(key) ``` ```lua function init() SetBool("level.robots.enabled", true) DebugPrint(GetBool("level.robots.enabled")) end ``` ```lua SetString(key, value, [sync]) ``` ```lua function init() SetString("level.name", "foo") DebugPrint(GetString("level.name")) end ``` ```lua value = GetString(key) ``` ```lua function init() SetString("level.name", "foo") DebugPrint(GetString("level.name")) end ``` -------------------------------- ### Create Quaternion Source: https://www.teardowngame.com/modding/api.html Creates a new quaternion. Use QuatEuler or QuatAxisAngle for initialization instead of raw values. ```lua quat = Quat([x], [y], [z], [w]) ``` ```lua function init() --These are equivalent local a1 = Quat() local a2 = {0, 0, 0, 1} DebugPrint(QuatStr(a1) == QuatStr(a2)) end ``` -------------------------------- ### Spawn Entities Source: https://www.teardowngame.com/modding/api.html Instantiates entities from an XML file or string. Supports spawning from local files or other mods. ```lua entities = Spawn(xml, transform, [allowStatic], [jointExisting]) ``` ```lua function server.init() Spawn("MOD/prefab/mycar.xml", Transform(Vec(0, 5, 0))) Spawn("", Transform(Vec(0, 10, 0))) end ``` -------------------------------- ### LoadSound Source: https://www.teardowngame.com/modding/api.html Loads an OGG sound file into memory. Returns a handle used for playback. ```lua handle = LoadSound(path, [nominalDistance]) ``` ```lua function client.init() local snd = LoadSound("warning-beep.ogg") end ``` -------------------------------- ### Get(x, y, z) Source: https://www.teardowngame.com/modding/voxscript.html Retrieves the material ID of a voxel at a specific position. ```APIDOC ## Get(x, y, z) ### Description Returns the voxel's material id at the specified position. ### Parameters - **x** (number) - Required - X coordinate - **y** (number) - Required - Y coordinate - **z** (number) - Required - Z coordinate ### Response - **material** (number) - The material ID at the position. ``` -------------------------------- ### Check Version Compatibility Source: https://www.teardowngame.com/modding/api.html Checks if the current game version is at least the provided reference version. ```lua match = HasVersion(version) ``` ```lua function init() if HasVersion("1.5.0") then --conditional code that only works on 0.6.0 or above DebugPrint("New version") else --legacy code that works on earlier versions DebugPrint("Earlier version") end end ``` -------------------------------- ### Get Voxel Material Source: https://www.teardowngame.com/modding/voxscript.html Retrieves the material ID of a voxel at a specific position. ```lua function init() Vox(0,0,0) local brush = CreateBrush("brush/white.vox") local brick = CreateMaterial("masonry", 0.6, 0.5, 0.3, 0, 0.1, 0, 0) Material(brick) Set(0, 0, 0) Material(Get(0, 0, 0)) end ``` -------------------------------- ### Get Focused Component ID Source: https://www.teardowngame.com/modding/api.html Retrieves the ID of the currently focused UI component. ```lua id = UiFocusedComponentId() ``` ```lua function client.draw() -- window declaration is necessary for navigation to work UiWindow(1920, 1080) if LastInputDevice() == UI_DEVICE_GAMEPAD then -- active mouse cursor has higher priority over the gamepad control -- so it will reset focused components if the mouse moves UiSetCursorState(UI_CURSOR_HIDE_AND_LOCK) end UiPush() UiTranslate(960, 540) local id1 = UiNavComponent(100, 20) UiTranslate(0, 50) local id2 = UiNavComponent(100, 20) UiPop() local f1 = UiIsComponentInFocus(id1) local f2 = UiIsComponentInFocus(id2) local rect = UiFocusedComponentRect() UiPush() UiColor(1, 0, 0) UiTranslate(rect.x, rect.y) UiRect(rect.w, rect.h) UiPop() DebugPrint(UiFocusedComponentId()) end ``` -------------------------------- ### SpawnTool Source: https://www.teardowngame.com/modding/api.html Spawns a tool entity. ```APIDOC ## SpawnTool(id, transform, [allowStatic], [voxScale]) ### Description Spawns a tool entity by ID. ### Parameters - **id** (string) - Required - Tool ID - **transform** (TTransform) - Required - Spawn transform - **allowStatic** (boolean) - Optional - Allow spawning static shapes and bodies (default false) - **voxScale** (number) - Optional - Applies a scale to voxels (default 1.0) ### Returns - **entities** (table) - Indexed table with handles to all spawned entities ``` -------------------------------- ### Load Image Source: https://www.teardowngame.com/modding/voxscript.html Loads a PNG image from the specified file path. ```lua LoadImage(path, [grassMapPath]) ``` ```lua function init() LoadImage("MOD/image.png") end ``` -------------------------------- ### Get Mouse Position Source: https://www.teardowngame.com/modding/api.html Retrieves the mouse pointer coordinates relative to the cursor or canvas. ```lua x, y = UiGetMousePos() ``` ```lua local x, y = UiGetMousePos() ``` ```lua x, y = UiGetCanvasMousePos() ``` ```lua function client.draw() local x, y = UiGetCanvasMousePos() DebugPrint("x :" .. x .. " y:" .. y) end ``` -------------------------------- ### Get Player Velocity Source: https://www.teardowngame.com/modding/api.html Retrieves the player's current velocity in world space. ```lua velocity = GetPlayerVelocity([playerId]) ``` ```lua function client.tick() local vel = GetPlayerVelocity() DebugPrint(VecStr(vel)) end ``` -------------------------------- ### Manage Registry Keys Source: https://www.teardowngame.com/modding/api.html Functions for clearing, listing, and checking existence of registry keys. ```lua ClearKey(key) ``` ```lua function init() --If the registry looks like this: -- score -- levels -- level1 = 5 -- level2 = 4 ClearKey("score.levels") --Afterwards, the registry will look like this: -- score end ``` ```lua children = ListKeys(parent) ``` ```lua --If the registry looks like this: -- game -- tool -- steroid -- rifle -- ... function init() local list = ListKeys("game.tool") for i=1, #list do DebugPrint(list[i]) end end --This will output: --steroid --rifle -- ... ``` ```lua exists = HasKey(key) ``` ```lua function init() DebugPrint(HasKey("score.levels")) DebugPrint(HasKey("game.tool.rifle")) end ``` -------------------------------- ### Set Material Source: https://www.teardowngame.com/modding/voxscript.html Sets the current active material or brush. Passing zero removes the current content. ```lua Material(material) ``` ```lua function init() local brush = CreateBrush("brush/white.vox") local brick = CreateMaterial("masonry", 0.6, 0.5, 0.3, 0, 0.1, 0, 0) Material(brick) Vox(0,0,0) Box(0, 0, 0, 10, 10, 10) --Make box hollow Material(0) Box(2, 2, 2, 8, 8, 8) end ``` -------------------------------- ### SetPlayerHidden Usage Source: https://www.teardowngame.com/modding/api.html Example of hiding the player character within a client tick function. ```lua function client.tick() ... SetCameraTransform(t) SetPlayerHidden() end ``` -------------------------------- ### GetPlayerParam Syntax Source: https://www.teardowngame.com/modding/api.html Syntax for retrieving player parameters. ```lua value = GetPlayerParam(parameter, [player]) ``` -------------------------------- ### Spawn Tools Source: https://www.teardowngame.com/modding/api.html Spawns a tool entity into the game world at a specified transform. ```lua entities = SpawnTool(id, transform, [allowStatic], [voxScale]) ``` ```lua function server.init() SpawnTool("sledge", Transform(Vec(0, 5, 0))) end ``` -------------------------------- ### GetVersion Source: https://www.teardowngame.com/modding/api.html Retrieves the current version of the game as a dot-separated string. ```APIDOC ## GetVersion ### Description Retrieves the current version of the game as a dot-separated string. ### Signature `version = GetVersion()` ### Return Value - **version** (string) - Dot separated string of current version of the game ``` -------------------------------- ### CreateBrush Source: https://www.teardowngame.com/modding/voxscript.html Creates a brush from a vox file. ```APIDOC ## CreateBrush(path, [local]) ### Description Creates a brush that can be used as a material. An object in the vox file can be specified using a colon (:) delimiter. ### Parameters - **path** (string) - Required - Vox file path and optional object - **local** (boolean) - Optional - Use local coordinates for all operations. Default false. ``` -------------------------------- ### PlayAnimationInstance Source: https://www.teardowngame.com/modding/api.html Controls the weight and speed of an existing animation instance. ```lua --This will control the weight and speed of the animation thas was initiated by PlayAnimation PlayAnimationInstance(animator, handle, 0.8, 1.0) ``` -------------------------------- ### Get Focused Component Rectangle Source: https://www.teardowngame.com/modding/api.html Returns the bounding rectangle of the focused component or its n-th parent. ```lua rect = UiFocusedComponentRect([n]) ``` ```lua function client.draw() -- window declaration is necessary for navigation to work UiWindow(1920, 1080) if LastInputDevice() == UI_DEVICE_GAMEPAD then -- active mouse cursor has higher priority over the gamepad control -- so it will reset focused components if the mouse moves UiSetCursorState(UI_CURSOR_HIDE_AND_LOCK) end UiPush() UiTranslate(960, 540) local id1 = UiNavComponent(100, 20) UiTranslate(0, 50) local id2 = UiNavComponent(100, 20) UiPop() local f1 = UiIsComponentInFocus(id1) local f2 = UiIsComponentInFocus(id2) local rect = UiFocusedComponentRect() UiPush() UiColor(1, 0, 0) UiTranslate(rect.x, rect.y) UiRect(rect.w, rect.h) UiPop() end ``` -------------------------------- ### Get Current Window Coordinates Source: https://www.teardowngame.com/modding/api.html Returns the top-left and bottom-right coordinates of the active UI window. ```lua tl_x, tl_y, br_x, br_y = UiGetCurrentWindow() ``` ```lua function client.draw() UiPush() UiWindow(400, 200) tl_x, tl_y, br_x, br_y = UiGetCurrentWindow() -- do something UiPop() end ```