Guest User

Untitled

a guest
Jan 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. os.unloadAPI("sensors")
  2. os.loadAPI("/rom/apis/sensors")
  3. term.clear()
  4. term.setCursorPos(1,1)
  5.  
  6. function printDict(data)
  7.   for i,v in pairs(data) do
  8.     print(tostring(i).." - "..tostring(v))
  9.   end
  10. end
  11.  
  12. function getXYZ()
  13.   ctrl = sensors.getController()
  14.   data = sensors.getSensors(ctrl)
  15.   asSensor = data[1]
  16.   data = sensors.getSensorInfo(ctrl,asSensor)
  17.  
  18.   asCoord = {}
  19.   asCoord["x"] = data["xCoord"]
  20.   asCoord["y"] = data["yCoord"]
  21.   asCoord["z"] = data["zCoord"]
  22.  
  23.   return asCoord
  24. end
  25.  
  26. print("Airship GPS Online - ID:"..os.getComputerID())
  27. a = getXYZ()
  28. print("Current - X."..a["x"].." Y."..a["y"].." Z."..a["z"])
  29. print("Waiting for ping...")
  30.  
  31. rednet.open("left")
  32. while true do
  33.   id, message = rednet.receive()
  34.   if message == "ping" then
  35.     a = getXYZ()
  36.     print("Pinged by "..id..", sending: X."..a["x"].." Y."..a["y"].." Z."..a["z"].."...")
  37.     rednet.send(id,textutils.serialize(a))
  38.     term.write("Sent")
  39.   else
  40.     print("Invalid message from "..id..", ignoring...")
  41.   end
  42. end
Add Comment
Please, Sign In to add comment