Total Miner Lua API Reference
Complete guide to Total Miner's Lua modding API — classes, methods, hooks, and data types for building mods that go beyond what the built-in command scripting can do.
Looking for the simpler, built-in command scripting used for map triggers instead? See the Scripting Command Reference.
Table of contents
Overview
The Total Miner Lua API provides access to game internals through interfaces and events. Your Lua scripts can:
- Access and modify game state (players, actors, maps)
- Respond to game events through hooks
- Create custom gameplay behaviors
- Control the game world
Lua is the language behind Total Miner’s modding API — a level below the built-in command scripting, and what the Mods on this site are built with.
Core Interfaces
ITMGame
Main interface for accessing game state and world information.
Key Properties:
Players- Array of all playersWorld- Current world dataMap- Current map instance
Key Methods:
SpawnActor(type, position)- Create a new actorPrintToChat(message)- Send message to all players
ITMPlayer
Represents a player character.
Key Properties:
Name- Player’s usernamePosition- Vector3 positionHealth- Current health (0-20)MaxHealth- Maximum health valueIsAlive- Whether player is aliveIsPlayer- Always true for players
Key Methods:
Damage(amount)- Deal damage to playerHeal(amount)- Restore player healthSetPosition(vec3)- Teleport playerPrintToChat(message)- Send private message
ITMActor
Represents a non-player character or creature.
Key Properties:
Type- Actor type (Zombie, Skeleton, Spider, etc)Position- Vector3 positionHealth- Current healthMaxHealth- Maximum healthIsAlive- Alive statusIsPlayer- Always false for actors
Key Methods:
Damage(amount)- Deal damageKill()- Destroy actorPlayAnimation(name)- Play animationSetPosition(vec3)- Set actor location
ITMMap
Interact with the map and terrain.
Key Properties:
Width- Map width in blocksHeight- Map height in blocksDepth- Map depth in blocksGravity- Current gravity value
Key Methods:
GetBlock(x, y, z)- Get block dataSetBlock(x, y, z, block)- Set block dataExplodeAt(position, power)- Create explosionGetEntitiesInRegion(bounds)- Find entities in area
Hooks
Hooks allow your Lua code to respond to game events. Define a function with the hook name and it will be called automatically.
GameLoopHook()
Called every frame for continuous logic. Use for animations, updates, and real-time checks.
function GameLoopHook()
-- Runs every frame
if Game.Players[1] then
print("Player is in game")
end
end
ModifyDamageDealtHook(info)
Called when damage is dealt. Modify damage or prevent it.
StrikeInfo Properties:
Attacker- Entity dealing damageTarget- Entity taking damageDamageDealt- Damage amount (can modify)DamageType- Type of damage
Return the modified info, or false to cancel.
function ModifyDamageDealtHook(info)
if info.Attacker.IsPlayer then
info.DamageDealt = info.DamageDealt * 2
end
return info
end
ModifyDamageTakenHook(info)
Called when entity receives damage. Reduce or negate damage.
function ModifyDamageTakenHook(info)
if info.Target.IsPlayer then
info.DamageDealt = math.floor(info.DamageDealt * 0.5)
end
return info
end
ActorSpawnedHook(actor)
Called when a new actor spawns. Modify properties immediately.
function ActorSpawnedHook(actor)
if actor.Type == "Zombie" then
actor.MaxHealth = 100
end
end
ActorDestroyedHook(actor)
Called when an actor is destroyed.
function ActorDestroyedHook(actor)
print(actor.Name .. " was destroyed")
end
PlayerInputHook(player, input)
Called when player presses input. Can modify or block input.
Return values:
- Return input string to allow
- Return
falseto cancel
function PlayerInputHook(player, input)
if input == "Sprint" then
return false -- Disable sprinting
end
return input
end
PlayerMovedHook(player)
Called when player moves. Track movement or apply effects.
function PlayerMovedHook(player)
if player.Position.Y < 0 then
player.SetPosition(Vector3.new(0, 50, 0))
end
end
Data Types
Vector3
3D coordinate or direction vector.
Properties:
X- X coordinateY- Y coordinateZ- Z coordinate
Usage:
local pos = Vector3.new(10, 20, 30)
local distance = Vector3.Distance(pos1, pos2)
StrikeInfo
Information about a damage event.
Properties:
Attacker- Entity dealing damageTarget- Entity taking damageDamageDealt- Damage amountDamageType- Type of damageIsHit- Whether attack connected
ItemInfo
Information about an item.
Properties:
Type- Item typeQuantity- Stack quantityDurability- Item durability
Examples
Double Player Damage
function ModifyDamageDealtHook(info)
if info.Attacker.IsPlayer and not info.Target.IsPlayer then
info.DamageDealt = info.DamageDealt * 2
end
return info
end
Healing on Kill
function ActorDestroyedHook(actor)
if Game.Players[1] then
local player = Game.Players[1]
player.Heal(10)
end
end
Prevent Player Damage
function ModifyDamageTakenHook(info)
if info.Target.IsPlayer then
return false -- Players take no damage
end
return info
end
Movement Boost
function PlayerInputHook(player, input)
if input == "Sprint" then
player.Velocity.X = player.Velocity.X * 1.5
player.Velocity.Z = player.Velocity.Z * 1.5
end
return input
end
Teleport on Fall
function PlayerMovedHook(player)
if player.Position.Y < 0 then
player.SetPosition(Vector3.new(0, 50, 0))
player.PrintToChat("You fell too far!")
end
end
Best Practices
- Check entity types - Always verify if something is a player or actor
- Handle missing entities - Check
if entity thenbefore using - Use math functions - Use
math.floor()for damage values - Return modified data - Always return from modifying hooks
- Avoid infinite loops - Don’t trigger hooks from within hooks
- Cache references - Store commonly used objects
- Minimize frame logic - Keep
GameLoopHook()lightweight
Troubleshooting
Hook not firing?
- Check function name spelling exactly
- Verify your script is loaded
- Ensure entity type matches your check
NullReferenceException?
- Entity was destroyed or removed
- Always check before using
Syntax errors?
- Check Lua syntax carefully
- Look for missing parentheses or brackets
Performance issues?
- Minimize work in
GameLoopHook() - Cache results when possible
- Avoid expensive operations in loops
Building a mod? Browse the Mods page for scripts that use these hooks, or the Mod Installation Guide to load one in-game. For general gameplay guidance (not scripting), see the Tutorials.