Advertisement
sethxi

SGPS

Jun 27th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. --UPDATE SGPS
  2. local towerdata = http.get("http://pastebin.com/raw.php?i=MCCNBq1a").readAll()
  3. local fl = fs.open("data/twrs", "w")
  4. fl.write(towerdata)
  5. fl.close()
  6. local fl = fs.open("data/twrs", "r")
  7. local towers = textutils.unserialize(fl.readAll())
  8. fl.close()
  9. --END UPDATE SGPS
  10.  
  11. local funcargs = {...}
  12.  
  13. local function printWithFormat(...)
  14.         local s = "&1"
  15.         for k, v in ipairs(arg) do
  16.                 s = s .. v
  17.         end
  18.         s = s .. "&0"
  19.  
  20.         local fields = {}
  21.         local lastcolor, lastpos = "0", 0
  22.         for pos, clr in s:gmatch"()&(%x)" do
  23.                 table.insert(fields, {s:sub(lastpos + 2, pos - 1), lastcolor})
  24.                 lastcolor, lastpos = clr , pos
  25.         end
  26.  
  27.         for i = 2, #fields do
  28.                 term.setTextColor(2 ^ (tonumber(fields[i][2], 16)))
  29.                 io.write(fields[i][1])
  30.         end
  31. end
  32.  
  33. local x, y, z = gps.locate(5)
  34. local you = vector.new(x,y,z)
  35.  
  36. local function printUsage()
  37.     print("Usage:")
  38.     print("sgps distance x y z")
  39.     print("sgps navdistance x y z")
  40.     print("sgps loc\nor sgps locate")
  41. end
  42.  
  43. if(funcargs[1]=="update")then
  44.     shell.run("rm","sgps")
  45.     shell.run("pastebin","get","zDQP9G99","sgps")
  46.     printWithFormat("&5Updated!\n")
  47.     return
  48. elseif(funcargs[1]=="distance") then
  49.     if(#funcargs<2) then
  50.         print("Use 'sgps distance x y z'!")
  51.         return
  52.     end
  53.     local there = vector.new(tonumber(funcargs[2]),tonumber(funcargs[3]),tonumber(funcargs[4]))
  54.     local dist = you-there
  55.     printWithFormat("&1Distance is "..dist:length().."\n&2Navigation Distance:\n&4"..tostring(dist).."\n")
  56.     return
  57. elseif(funcargs[1]=="navdistance") then
  58.     if(#funcargs<2) then
  59.         print("Use 'sgps navdistance x y z'!")
  60.         return
  61.     end
  62.     while true do
  63.         local x, y, z = gps.locate(5)
  64.         local you = vector.new(x,y,z)
  65.         term.clear()
  66.         term.setCursorPos(1,1)
  67.         local there = vector.new(tonumber(funcargs[2]),tonumber(funcargs[3]),tonumber(funcargs[4]))
  68.         local dist = you-there
  69.         printWithFormat("&1Distance is "..dist:length().."\n&2Navigation Distance:\n&4"..tostring(dist).."\n")
  70.         sleep(1)
  71.     end
  72. elseif(funcargs[1]=="locate" or funcargs[1]=="loc")then
  73.     local x, y, z = gps.locate(5)
  74.     local you = vector.new(x,y,z)
  75.     for k,v in pairs(towers) do
  76.         local sat = vector.new(v[1],v[2],v[3])
  77.         local distance = you - sat
  78.         local argstext = v[1]..", "..v[2]..", "..v[3]
  79.         printWithFormat("<TOWER> &3"..k.."\n&4@"..argstext.."\n".."+/- &7"..distance:length().."\n")
  80.     end
  81.  
  82.     if(not x) then
  83.         printWithFormat("&4Couldn't get location!\nLearn how to do trilateration!\n")
  84.     else
  85.         local loctext = x..", "..y..", "..z
  86.         printWithFormat("&2Your location is:\n&4@"..loctext.."\n")
  87.     end
  88. elseif(#funcargs<1) then
  89.     printUsage()
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement