Maxstripe

TrackerMonitorV1

Jan 3rd, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function extract(s)
  2.   local t = {}
  3.   local name, armor, account, health, world, x, y, z
  4.   local a = 0
  5.   local b = 0
  6.   while (true) do
  7.     a, b, name, armor, account, health, z, y, world, x = string.find(s, "\"sort\":0,\"name\":\"([^\"]+)\",\"armor\":(%d+),\"account\":\"([^\"]+)\",\"health\":(%d+),\"type\":\"player\",\"z\":([-0-9.]+),\"y\":([-0-9.]+),\"world\":\"([^\"]+)\",\"x\":([-0-9.]+)", b + 1)
  8.     if (a == nil) then
  9.       break
  10.     end
  11.     t[account] = {}
  12.     t[account].armor = tonumber(armor)
  13.     t[account].name = name
  14.     t[account].health = tonumber(health)
  15.     t[account].world = world
  16.     t[account].loc = vector.new(tonumber(x), tonumber(y), tonumber(z))
  17.     local offset = here - t[account].loc
  18.     t[account].dist = math.floor(math.sqrt(offset.x * offset.x + offset.z * offset.z))
  19.   end
  20.   return t
  21. end
  22.  
  23. function getDisplay()
  24.   local plist = peripheral.getNames()
  25.   local i, name
  26.   for i, name in pairs(plist) do
  27.     if peripheral.getType(name) == "monitor" then
  28.       return peripheral.wrap(name)
  29.     end
  30.   end
  31.   return term
  32. end
  33.  
  34. fh = http.get("http://tekkit.craftersland.net:25800/up/world/world/111")
  35. txt = fh.readAll()
  36. fh.close()
  37. _,_,ts = string.find(txt, "{\"timestamp\":(%d+).")
  38.  
  39. print ("Starting timestamp: ", ts)
  40. here = vector.new(-325, 80, -2538)
  41. mon = getDisplay()
  42. -- mon.setTextScale(0.8)
  43. cols, rows = mon.getSize()
  44. players = {}
  45. while (true) do
  46.   fh = http.get("http://tekkit.craftersland.net:25800/up/world/world/" .. ts)
  47.   if (fh) then
  48.     txt = fh.readAll()
  49.     fh.close()
  50.     _,_,ts = string.find(txt, "{\"timestamp\":(%d+),")
  51.     if (ts) then
  52.       players = extract(txt)
  53.     end
  54.   end
  55.   local i = 1
  56.   st = {}
  57.   for key in pairs(players) do
  58.     st[#st+1] = key
  59.   end
  60.   table.sort(st, function(a, b) return players[a].dist < players[b].dist end)
  61.   mon.clear()
  62.   for k = 1, #st do
  63.     account = st[k]
  64.     if (players[account].world == "world") then
  65.       mon.setCursorPos(1, i)
  66.       mon.write(account.." - "..players[account].dist)
  67.       -- mon.write(account.." - "..math.floor(players[account].loc.x).." "..math.floor(players[account].loc.y).." "..math.floor(players[account].loc.z).." - armor "..players[account].armor.." - health "..players[account].health.." - distance "..players[account].dist.." - "..players[account].world)
  68.       i = i + 1
  69.     end
  70.   end  
  71.  
  72.   os.sleep(5.0)
  73. end
Add Comment
Please, Sign In to add comment