Advertisement
gravitowl

turtle_client.lua

Mar 13th, 2021 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. rednet.open("right")
  2.  
  3. -- GLOBALS
  4.  
  5. local MY_POS = vector.new(gps.locate(2, false))
  6. local DIRS = {
  7.     north = 1,
  8.     east = 2,
  9.     south = 3,
  10.     west = 4
  11. }
  12. local MY_DIR = DIRS.north
  13. local MY_ID = os.getComputerID()
  14. local MY_LABEL = os.getComputerLabel()
  15. if MY_LABEL == nil then MY_LABEL = MY_ID end
  16.  
  17. -- FUNCTIONS & STUFF
  18.  
  19. local function getDir()
  20.     while not turtle.forward() do
  21.         turtle.dig()
  22.     end
  23.  
  24.     local NEW_POS = vector.new(gps.locate(2, false))
  25.  
  26.     NEW_POS = NEW_POS:sub(MY_POS)
  27.  
  28.     if NEW_POS.z == -1 then
  29.         turtle.back()
  30.         return DIRS.north
  31.     elseif NEW_POS.z == 1 then
  32.         turtle.back()
  33.         return DIRS.south
  34.     elseif NEW_POS.x == -1 then
  35.         turtle.back()
  36.         return DIRS.west
  37.     elseif NEW_POS.x == 1 then
  38.         turtle.back()
  39.         return DIRS.east
  40.     end
  41.  
  42. end
  43.  
  44. local function updateInformation()
  45.     MY_DIR = getDir()
  46.     MY_POS = vector.new(gps.locate(2, false))
  47.     MY_LABEL = os.getComputerLabel()
  48. end
  49.  
  50. local function processRequest(senderId, msg)
  51.    
  52.     if msg == "%RQSTINFO" then
  53.         updateInformation()
  54.         return
  55.     end
  56.  
  57. end
  58.  
  59. local function mainLoop()
  60.  
  61.     updateInformation()
  62.  
  63.     while true do
  64.         rednet.broadcast("%CLTINFO!INF!"..MY_POS.x.."!INF!"..MY_POS.y.."!INF!"..MY_POS.z.."!INF!"..MY_DIR.."!INF!"..MY_ID.."!INF!", "botNetV1")
  65.        
  66.         os.sleep(1)
  67.     end
  68. end
  69.  
  70. -- STARTUP
  71.  
  72. mainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement