Forge Project

Total Miner Files are here and free

View on GitHub

ForgeProject Logo

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:

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:

Key Methods:


ITMPlayer

Represents a player character.

Key Properties:

Key Methods:


ITMActor

Represents a non-player character or creature.

Key Properties:

Key Methods:


ITMMap

Interact with the map and terrain.

Key Properties:

Key Methods:


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:

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:

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:

Usage:

local pos = Vector3.new(10, 20, 30)
local distance = Vector3.Distance(pos1, pos2)

StrikeInfo

Information about a damage event.

Properties:

ItemInfo

Information about an item.

Properties:


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

  1. Check entity types - Always verify if something is a player or actor
  2. Handle missing entities - Check if entity then before using
  3. Use math functions - Use math.floor() for damage values
  4. Return modified data - Always return from modifying hooks
  5. Avoid infinite loops - Don’t trigger hooks from within hooks
  6. Cache references - Store commonly used objects
  7. Minimize frame logic - Keep GameLoopHook() lightweight

Troubleshooting

Hook not firing?

NullReferenceException?

Syntax errors?

Performance issues?


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.