✨ Community Modding Hub
Explore
Explore
Trailmakers Modding
Browse a growing collection of mods, guides, and libraries created by fellow players. Share your own creations and find new ways to play.
500+
Active Mods
14
Helpful Guides
1
Code Libraries
★ Featured Mods
Hand-picked community favorites
📚 Recent Guides
View Allâš¡ Latest Snippets
Quick code blocks to speed up your development
UI
Nov 25
Add UI Button
When a player joins they get a button added to their hud that when pressed sends them a subtle message
function sendMessage(callbackData)
tm.playerUI.AddSubtleMessageForPlayer(callbackData.playerId, "Hello", tm.players.GetPlayerName(callbackData.playerId), 3, "")
end
function onPlayerJoined(player)
tm.playerUI.AddUIButton(player.playerId, "playerbtn" .. tostring(player.playerId), "Press for Message", sendMessage, player.playerId) -- When a user presses the button it calls the function sendMessage
end
-- Add new UI to the player that joins
tm.players.OnPlayerJoined.add(onPlayerJoined)
T
terrorsoul
Spawning
Nov 23
Melvin Shower
Spawns melvins above players in the sky at random intervals
local nextMelvinTime = 0
function UpdateMelvinShower()
local time = tm.os.GetTime()
if time > nextMelvinTime then
nextMelvinTime = time + (math.random() * 3.0) -- Spawn a melvin between immediately and 3 seconds
local players = tm.players.CurrentPlayers()
for _, p in pairs(players) do
local pPos = tm.players.GetPlayerTransform(p.playerId).GetPosition()
-- Random Position in sky
local x = pPos.x + math.random(-50, 50)
local y = pPos.y + math.random(50, 120)
local z = pPos.z + math.random(-50, 50)
local spawnPos = tm.vector3.Create(x, y, z)
-- Spawn Melvin
local melvin = tm.physics.SpawnObject(spawnPos, "PFB_Birdo_Medium")
-- Check if spawn was successful
if melvin.Exists() then
local transform = melvin.GetTransform()
-- 1. Random Rotation
-- Generate random angles for X, Y, Z axes
local rx = math.random(0, 360)
local ry = math.random(0, 360)
local rz = math.random(0, 360)
transform.SetRotation(rx, ry, rz)
-- 2. Random Size
local randomSize = 0.5 + (math.random() * 4.0)
transform.SetScale(randomSize)
end
end
end
end
function update()
UpdateMelvinShower()
end
T
terrorsoul
Physics
Nov 23
Freeze Vehicle
Uses set drag and engine power to effectively freeze a vehicle
local savedPowerCache = {}
function ToggleVehicleFreeze(playerId, shouldFreeze)
local structure = tm.players.OccupiedStructure(playerId)
if structure ~= nil then
local blocks = structure.GetBlocks()
for _, block in pairs(blocks) do
if shouldFreeze then
-- 1. FREEZE VEHICLE
block.SetDragAll(999, 999, 999, 999, 999, 999)
-- 2. SAVE & CUT POWER
-- We store the original values in a table keyed by the block itself
local stats = {}
local needsSave = false
-- Engines
if block.IsEngineBlock() then
stats.engine = block.GetEnginePower()
block.SetEnginePower(0.0001) -- Never set the power to 0 as this will cause the game to crash
needsSave = true
end
-- Jets
if block.IsJetBlock() then
stats.jet = block.GetJetPower()
block.SetJetPower(0.0001)
needsSave = true
end
-- Propellers
if block.IsPropellerBlock() then
stats.prop = block.GetPropellerPower()
block.SetPropellerPower(0.0001)
needsSave = true
end
-- Gyros
if block.IsGyroBlock() then
stats.gyro = block.GetGyroPower()
block.SetGyroPower(0.0001)
needsSave = true
end
if needsSave then
savedPowerCache[block] = stats
end
else
-- 1. UNFREEZE VEHICLE
block.ResetDragAll()
-- 2. RESTORE POWER
local stats = savedPowerCache[block]
if stats then
if stats.engine then block.SetEnginePower(stats.engine) end
if stats.jet then block.SetJetPower(stats.jet) end
if stats.prop then block.SetPropellerPower(stats.prop) end
if stats.gyro then block.SetGyroPower(stats.gyro) end
savedPowerCache[block] = nil
end
end
end
local msg = shouldFreeze and "Frozen" or "Unfrozen"
tm.playerUI.AddSubtleMessageForPlayer(playerId, "VEHICLE", msg, 1, "")
end
end
-- Usage Example:
ToggleVehicleFreeze(0, true)
T
terrorsoul