Back to Library
Physics Nov 23, 2025

Freeze Vehicle

T
by terrorsoul

Uses set drag and engine power to effectively freeze a vehicle

LUA
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)

Discussion

Please log in to post a comment.