osmarks

experimental 3D pointer

Feb 23rd, 2021 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local dynmap = settings.get "tracker.map" or "https://dynmap.switchcraft.pw/"
  2. local API = dynmap .. "up/world/world/"
  3. local mon = peripheral.find "monitor"
  4. if mon then mon.setTextScale(0.5) term.redirect(mon) end
  5.  
  6. local function fetch(url)
  7.     local h = http.get(url)
  8.     local o = h.readAll()
  9.     h.close()
  10.     return o
  11. end
  12.  
  13. local target = ...
  14. local operator = "gollark"
  15. local canvas3 = peripheral.call("back", "canvas3d").create()
  16. setmetatable(canvas3, {
  17.     __gc = function() canvas3.clear() end
  18. })
  19. --local box = canvas3.addBox(0, 0, 0)
  20. local line = canvas3.addLine({0, 0, 0}, {0, 0, 0})
  21. line.setScale(4)
  22.  
  23. parallel.waitForAll(function()
  24. while true do
  25.     local raw = fetch(API .. os.epoch "utc")
  26.     local data = textutils.unserialiseJSON(raw)
  27.     local players = data.players
  28.     local op
  29.     local tplayer
  30.     for _, player in pairs(players) do
  31.         if player.name:match(target) then tplayer = player end
  32.         if player.name == operator then op = player end
  33.     end
  34.     if tplayer then
  35.         local tvec = vector.new(tplayer.x, tplayer.y, tplayer.z)
  36.         local ovec = vector.new(op.x, op.y, op.z)
  37.         local dirvec = (tvec - ovec):normalize() * 10
  38.         print(tostring(dirvec))
  39.         line.setPoint(2, dirvec.x, dirvec.y, dirvec.z)
  40.     end
  41.     sleep(1)
  42. end end, function() while true do canvas3.recenter() sleep(0.1) end end)
Add Comment
Please, Sign In to add comment