Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 8th, 2011  |  syntax: Lua  |  size: 1.62 KB  |  views: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function widget:GetInfo()
  2.   return {
  3.     name      = "coordinates helper v1",
  4.     desc      = "(for mapmarkers) helps with finding the correct coordinates when placing rocks by logging marker coordinates into file",
  5.     author    = "knorke",
  6.     date      = "9 Nov 2010",
  7.     license   = "GNU GPL, v2 or later or horse",
  8.     layer     = 0,
  9.     enabled   = false,  --  loaded by default?
  10.   }
  11. end
  12.  
  13. local coordfile = nil
  14.  
  15. local function log_coord (px, py, pz, label)
  16. local coordfile_fn = Game.mapName .. "_coordinates.txt"
  17. if (coordfile==nil) then
  18.         coordfile = io.open (coordfile_fn, "w")
  19.         if (coordfile) then Spring.Echo ("tp_coordinate:  coordinate logfile opened: " .. coordfile_fn) else Spring.Echo ("tp_coordinate:  failed to open " .. coordfile_fn) end
  20. end
  21.  
  22. if (label==nil) then label = "" end
  23. local coordtext = "XZ (" .. px .." , " .. pz .. ")" .. "   -- " .. label
  24. --local coordtext = "waypoints[tn][1] = {x=" ..px.." , " .. "z="..pz .. "}  --" ..label
  25. coordfile:write (coordtext .. "\n")
  26. --Spring.Echo ("tp_coordinate:" ..coordtext)
  27. coordfile:flush()
  28. end
  29.  
  30. function widget:Initialize()
  31. Spring.Echo ("tp_coordinate: place markers on the map to log their coordinates")
  32. log_coord (123,123, "yoyo!")
  33. end
  34.  
  35. function widget:MapDrawCmd(playerID, cmdType, px, py, pz, label)
  36. log_coord (px, py, pz, label)
  37. end
  38. --[[
  39. function widget:UnitCreated(unitID, unitDefID, teamID, builderID)
  40.         local x,y,z=Spring.GetUnitPosition (unitID)
  41.         if (x and y and z) then
  42.                 local coordtext = "XYZ (" .. x .. " , " .. math.floor(y) .. " , " .. z .. ")"
  43.                 coordfile:write (coordtext .. "\n")
  44.                 coordfile:flush()
  45.         end
  46. end
  47. --]]
  48.  
clone this paste RAW Paste Data