
Untitled
By: a guest on
Dec 8th, 2011 | syntax:
Lua | size: 1.62 KB | hits: 21 | expires: Never
function widget:GetInfo()
return {
name = "coordinates helper v1",
desc = "(for mapmarkers) helps with finding the correct coordinates when placing rocks by logging marker coordinates into file",
author = "knorke",
date = "9 Nov 2010",
license = "GNU GPL, v2 or later or horse",
layer = 0,
enabled = false, -- loaded by default?
}
end
local coordfile = nil
local function log_coord (px, py, pz, label)
local coordfile_fn = Game.mapName .. "_coordinates.txt"
if (coordfile==nil) then
coordfile = io.open (coordfile_fn, "w")
if (coordfile) then Spring.Echo ("tp_coordinate: coordinate logfile opened: " .. coordfile_fn) else Spring.Echo ("tp_coordinate: failed to open " .. coordfile_fn) end
end
if (label==nil) then label = "" end
local coordtext = "XZ (" .. px .." , " .. pz .. ")" .. " -- " .. label
--local coordtext = "waypoints[tn][1] = {x=" ..px.." , " .. "z="..pz .. "} --" ..label
coordfile:write (coordtext .. "\n")
--Spring.Echo ("tp_coordinate:" ..coordtext)
coordfile:flush()
end
function widget:Initialize()
Spring.Echo ("tp_coordinate: place markers on the map to log their coordinates")
log_coord (123,123, "yoyo!")
end
function widget:MapDrawCmd(playerID, cmdType, px, py, pz, label)
log_coord (px, py, pz, label)
end
--[[
function widget:UnitCreated(unitID, unitDefID, teamID, builderID)
local x,y,z=Spring.GetUnitPosition (unitID)
if (x and y and z) then
local coordtext = "XYZ (" .. x .. " , " .. math.floor(y) .. " , " .. z .. ")"
coordfile:write (coordtext .. "\n")
coordfile:flush()
end
end
--]]