Back to Library
UI Nov 23, 2025

Stats HUD

T
by terrorsoul

Shows the players current vehicle speed and altitude

LUA
local hudUpdateInterval = 0.2
local lastHudUpdate = 0

function SetupPlayerHUD(player)  
    -- Add the labels
    tm.playerUI.AddUILabel(player.playerId, "lbl_speed", "SPD: 0 km/h")
    tm.playerUI.AddUILabel(player.playerId, "lbl_alt", "ALT: 0 m")
end

function UpdateHUDValues()
    local time = tm.os.GetTime()
    
    if time > lastHudUpdate + hudUpdateInterval then
        lastHudUpdate = time
        local players = tm.players.CurrentPlayers()
        
        for _, p in pairs(players) do
            local structure = tm.players.OccupiedStructure(p.playerId)
            
            if structure ~= nil then
                local speed = math.floor(structure.GetSpeed() * 3.6)
                local alt = math.floor(structure.GetPosition().y)
                
                tm.playerUI.SetUIValue(p.playerId, "lbl_speed", "SPD: " .. speed .. " km/h")
                tm.playerUI.SetUIValue(p.playerId, "lbl_alt", "ALT: " .. alt .. " m")
            else
                tm.playerUI.SetUIValue(p.playerId, "lbl_speed", "On Foot")
                tm.playerUI.SetUIValue(p.playerId, "lbl_alt", "Ground Level")
            end
        end
    end
end

function update()
    UpdateHUDValues()
end

-- Hook into the join event
tm.players.OnPlayerJoined.add(SetupPlayerHUD)

Discussion

Please log in to post a comment.