Skip to content

Instantly share code, notes, and snippets.

@abma
Created July 31, 2013 20:38
Show Gist options
  • Select an option

  • Save abma/6125933 to your computer and use it in GitHub Desktop.

Select an option

Save abma/6125933 to your computer and use it in GitHub Desktop.
debug widget for the springrts.com engine
function widget:GetInfo()
return {
name = "unitinfo",
desc = "prints unit info each frame, used for debugging",
author = "abma",
date = "Feb. 2012",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true,
}
end
local function dumpUnitDef(unitDefID)
local unitDef = UnitDefs[unitDefID]
for name,param in unitDef:pairs() do
Spring.Echo(name,param)
end
end
local function dumpUnitStates(unitID)
states = Spring.GetUnitStates(unitID)
for name,param in ipairs(states) do
Spring.Echo(name,param)
end
end
local units = nil
function widget:KeyPress(k)
if (k ~= 32) then
return
end
units = Spring.GetSelectedUnits()
end
function widget:GameFrame(n)
if (units) and (#units == 1) then
local unitID = units[1]
local sx, sy, sz = Spring.GetUnitVelocity(unitID)
Spring.Echo(string.format("%d Velocity: %.2f",n, math.sqrt(sx * sx + sy * sy + sz * sz)))
local x, y, z = Spring.GetUnitPosition(unitID)
local groundy = Spring.GetGroundHeight(x, z)
if y ~= groundy then
Spring.Echo(string.format("Position: %.2f %.2f %.2f", x, y, z))
Spring.Echo(string.format("Height: %.2f", groundy))
end
--dumpUnitDef(Spring.GetUnitDefID(units[1]))
--dumpUnitStates(unitID)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment