Advertisement
osmarks

THOR/Entity Sensor Interface

Nov 10th, 2019
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local sensor = peripheral.wrap "back"
  2.  
  3. local key = settings.get "lasers.key"
  4. if not key then error "SPUDNET key for laser control not found." end
  5. local ws, err = http.websocket("wss://osmarks.tk/wsthing/lasers/admin", { authorization = "Key " .. key })
  6.  
  7. if err then
  8.     error(err)
  9. else
  10.     print "Connected to THOR satellite backend."
  11. end
  12.  
  13. local hist = {}
  14. while true do
  15.     write "Target: "
  16.     local target = read(nil, hist)
  17.     table.insert(hist, target)
  18.     print "Scanning..."
  19.     local es = sensor.sense()
  20.     for _, e in pairs(es) do
  21.         if e.name:match(target) or e.displayName:match(target) then
  22.             local x, y, z = gps.locate()
  23.             local tx, ty, tz = e.x + x, e.y + y - 1, e.z + z
  24.             ws.send(("fire_position %f %f %f 5"):format(tx, ty, tz))
  25.             print(e.name, e.displayName, tx, ty, tz)
  26.         end
  27.     end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement