Module tools
Multiplayer Tool & Loot System
Server-side system for managing tools, loot crates, and dropped weapons in multiplayer matches.
Responsibilities:
- Define and manage respawnable loot tiers (tool spawn points)
- Drop tools with remaining ammo when players die
- Spawn and manage physical tool bundles (crates and loose drops)
- Handle tool pickup from world entities
Functions
| toolsInit () | Initialize the tool system (server). |
| toolsSetRespawnTime (respawnTime) | Set the loot respawn time for all tiers (server). |
| toolsSetDropToolsOnDeath (dropTools) | Enable or disable dropping tools on player death (server). |
| toolsPreventToolDrop (toolId) | Prevent a specific tool from being dropped on death (server). |
| toolsAddModToolsToLootTable (lootTable[, weight]) | Add all custom (mod-defined) tools to a loot table. |
| toolsAddLootTier (transforms, lootTable) | Add a new loot tier with multiple spawn points (server). |
| toolsCleanup () | Clean up all active tool bundles and reset loot tiers (server). |
| toolsTick (dt) | Main server update loop for the tool system (server). |
Functions
- toolsInit ()
-
Initialize the tool system (server).
Resets all loot tiers and tool bundles, sets default configuration, and precomputes tool pickup data used by crates and drops.
- toolsSetRespawnTime (respawnTime)
-
Set the loot respawn time for all tiers (server).
Controls how long it takes for a loot spawn point to refill after its previous tool has despawned or been picked up.
Parameters:
- respawnTime number Time in seconds before loot respawns
- toolsSetDropToolsOnDeath (dropTools)
-
Enable or disable dropping tools on player death (server).
When enabled, tools with remaining ammo are spawned as world drops when a player dies.
Parameters:
- dropTools
boolean
trueto enable tool drops;falseto disable
- dropTools
boolean
- toolsPreventToolDrop (toolId)
-
Prevent a specific tool from being dropped on death (server).
Marks a tool ID as non-droppable even if
toolsSetDropToolsOnDeath(true)is active.Parameters:
- toolId string Tool ID to prevent from dropping
- toolsAddModToolsToLootTable (lootTable[, weight])
-
Add all custom (mod-defined) tools to a loot table.
Scans
game.toolfor tools marked withcustom=trueand inserts them into the provided loot table if they are not already present. A default pickup amount is determined from tool config or falls back to a sensible default.Can be called on server or client, but typically used when building server loot tables.
Parameters:
- lootTable table A list of loot entries to extend
- weight number Spawn weight to assign to each added tool (default: 3) (optional)
- toolsAddLootTier (transforms, lootTable)
-
Add a new loot tier with multiple spawn points (server).
A loot tier is a collection of spawn locations and tools with individual spawn configurations.
Parameters:
Usage:
lootTables = {} lootTables[1] = { {name = "steroid", weight = 10, amount = 4}, {name = "plank", weight = 2, amount = 5} } lootTables[2] = { {name = "shotgun", weight = 7}, {name = "gun", weight = 7}, {name = "bomb", weight = 5} } lootTables[3] = { {name = "rifle", weight = 9}, {name = "pipebomb", weight = 5}, {name = "rocket", weight = 10}, {name = "explosive", weight = 5} } toolsAddLootTier(toolSpawns[1], lootTables[1]) toolsAddLootTier(toolSpawns[2], lootTables[2]) toolsAddLootTier(toolSpawns[3], lootTables[3]) - toolsCleanup ()
-
Clean up all active tool bundles and reset loot tiers (server).
Deletes all spawned tool entities via
_cleanUpToolBundleand clears the loot tier definitions. Typically called when starting a new match or re-initializing the system. - toolsTick (dt)
-
Main server update loop for the tool system (server).
Should be called once per frame. Handles: * Despawning tool bundles when all players are far away * Ticking loot tiers and spawning new crates when timers expire * Dropping tools on player death * Handling player interaction with ammo/tool pickup bodies
Parameters:
- dt number Delta time in seconds