Advertisement
zippy36jr

masterTurtle

Mar 21st, 2021 (edited)
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. function jsonCheck()
  2.     if not fs.exists("json") then
  3.         shell.run("pastebin get 4nRg9CHU json")
  4.     end
  5. end
  6. jsonCheck()
  7.  
  8. print("Press any key to start the turtle")
  9. local blah = read();
  10.  
  11. os.loadAPI('json')
  12. local connectionURL = "ws://icantcraft.net:5757"
  13. local ws, err = http.websocket(connectionURL)
  14.  
  15. local turtleCount = 0
  16.  
  17. function placeBoxes()
  18.     turtle.select(1)
  19.     turtle.placeUp()
  20.     turtle.forward()
  21.     turtle.select(2)
  22.     turtle.placeUp()
  23.     turtle.back()
  24. end
  25.  
  26.  
  27. function placeTurtles()
  28.     for i = 1, turtleCount do
  29.         turtle.select(1)
  30.         turtle.suckUp(1)
  31.         turtle.place()
  32.         os.sleep(1)
  33.         peripheral.wrap("front")
  34.         peripheral.call("front", "turnOn")
  35.         os.sleep(5)
  36.     end
  37. end
  38.  
  39.  
  40.  
  41. if err then
  42.     return printError(err)
  43. elseif ws then
  44.     ws.send("master")
  45.  
  46.     while true do
  47.         local _, url, res, isBinary = os.pullEvent("websocket_message")
  48.  
  49.         if url == connectionURL then
  50.             local obj = json.decode(res)
  51.  
  52.             turtleCount = tonumber(obj.maxX) * tonumber(obj.maxY)
  53.  
  54.             print(turtleCount)
  55.             placeBoxes()
  56.             placeTurtles()
  57.             ws.close()
  58.             break
  59.         end
  60.  
  61.     end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement