Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not fs.exists "json" then local a=http.get"https://raw.githubusercontent.com/rxi/json.lua/bee7ee3431133009a97257bde73da8a34e53c15c/json.lua"local b=fs.open("json","w")b.write(a.readAll())a.close()b.close() end
- local json = require "/json"
- local dynmap = settings.get "tracker.map" or "https://dynmap.switchcraft.pw/"
- local API = dynmap .. "up/world/world/"
- local mon = peripheral.find "monitor"
- if mon then mon.setTextScale(0.5) term.redirect(mon) end
- local function fetch(url)
- local h = http.get(url)
- local o = h.readAll()
- h.close()
- return o
- end
- local worlds = {
- world = "overworld",
- DIM1_the_end = "end",
- DIM1 = "end",
- ["DIM-1"] = "nether",
- ["DIM-11325"] = "deepdark"
- }
- local function render_coords(player)
- return ("%0d %0d %0d"):format(player.x, player.y, player.z)
- end
- local function render_pos(player)
- local coords = render_coords(player)
- if player.x == 0 and player.y == 64 and player.z == 0 then coords = "[unknown]" end
- return coords .. " " .. (worlds[player.world] or player.world)
- end
- local w, h = term.getSize()
- local function longest_by(t, k)
- local sofar = 0
- for _, v in pairs(t) do
- if k then v = v[k] end
- if #v > sofar then
- sofar = #v
- end
- end
- return sofar
- end
- while true do
- local raw = fetch(API .. os.epoch "utc")
- local data = json.decode(raw)
- local players = data.players
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(colors.black)
- local max_name_length = longest_by(players, "account")
- for rowix, player in ipairs(players) do
- function moveto(x) term.setCursorPos(x, rowix) end
- function at(x, txt) moveto(x) term.write(txt) end
- if rowix % 2 == 0 then term.setBackgroundColor(colors.white)
- else term.setBackgroundColor(colors.lightGray) end
- moveto(1)
- term.clearLine()
- at(1, player.account)
- at(max_name_length + 2, render_pos(player))
- at(w - 5, ("%0d"):format(player.health))
- at(w - 2, ("%0d"):format(player.armor))
- end
- if #raw < 2048 then
- sleep(1)
- else
- sleep(10)
- end
- end
Add Comment
Please, Sign In to add comment