Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --UPDATE SGPS
- local towerdata = http.get("http://pastebin.com/raw.php?i=MCCNBq1a").readAll()
- local fl = fs.open("data/twrs", "w")
- fl.write(towerdata)
- fl.close()
- local fl = fs.open("data/twrs", "r")
- local towers = textutils.unserialize(fl.readAll())
- fl.close()
- --END UPDATE SGPS
- local funcargs = {...}
- local function printWithFormat(...)
- local s = "&1"
- for k, v in ipairs(arg) do
- s = s .. v
- end
- s = s .. "&0"
- local fields = {}
- local lastcolor, lastpos = "0", 0
- for pos, clr in s:gmatch"()&(%x)" do
- table.insert(fields, {s:sub(lastpos + 2, pos - 1), lastcolor})
- lastcolor, lastpos = clr , pos
- end
- for i = 2, #fields do
- term.setTextColor(2 ^ (tonumber(fields[i][2], 16)))
- io.write(fields[i][1])
- end
- end
- local x, y, z = gps.locate(5)
- local you = vector.new(x,y,z)
- local function printUsage()
- print("Usage:")
- print("sgps distance x y z")
- print("sgps navdistance x y z")
- print("sgps loc\nor sgps locate")
- end
- if(funcargs[1]=="update")then
- shell.run("rm","sgps")
- shell.run("pastebin","get","zDQP9G99","sgps")
- printWithFormat("&5Updated!\n")
- return
- elseif(funcargs[1]=="distance") then
- if(#funcargs<2) then
- print("Use 'sgps distance x y z'!")
- return
- end
- local there = vector.new(tonumber(funcargs[2]),tonumber(funcargs[3]),tonumber(funcargs[4]))
- local dist = you-there
- printWithFormat("&1Distance is "..dist:length().."\n&2Navigation Distance:\n&4"..tostring(dist).."\n")
- return
- elseif(funcargs[1]=="navdistance") then
- if(#funcargs<2) then
- print("Use 'sgps navdistance x y z'!")
- return
- end
- while true do
- local x, y, z = gps.locate(5)
- local you = vector.new(x,y,z)
- term.clear()
- term.setCursorPos(1,1)
- local there = vector.new(tonumber(funcargs[2]),tonumber(funcargs[3]),tonumber(funcargs[4]))
- local dist = you-there
- printWithFormat("&1Distance is "..dist:length().."\n&2Navigation Distance:\n&4"..tostring(dist).."\n")
- sleep(1)
- end
- elseif(funcargs[1]=="locate" or funcargs[1]=="loc")then
- local x, y, z = gps.locate(5)
- local you = vector.new(x,y,z)
- for k,v in pairs(towers) do
- local sat = vector.new(v[1],v[2],v[3])
- local distance = you - sat
- local argstext = v[1]..", "..v[2]..", "..v[3]
- printWithFormat("<TOWER> &3"..k.."\n&4@"..argstext.."\n".."+/- &7"..distance:length().."\n")
- end
- if(not x) then
- printWithFormat("&4Couldn't get location!\nLearn how to do trilateration!\n")
- else
- local loctext = x..", "..y..", "..z
- printWithFormat("&2Your location is:\n&4@"..loctext.."\n")
- end
- elseif(#funcargs<1) then
- printUsage()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement