Advertisement
imposiblaa

Turtle Master 2.0

Dec 6th, 2022 (edited)
926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. local enterPathing = {"south", "goto", 2, 0, 0, "drop-off", "right", "forward", "up", "forward", "eatme"}
  2. local exitPathing = {"fuel", "forward", "forward", "forward", "forward", "forward"}
  3. gps.CHANNEL_GPS = 5033
  4. local modem = peripheral.wrap("left")
  5. local stationReturn = {
  6.     x = 2,
  7.     y = 0,
  8.     z = -2
  9. }
  10.  
  11.  
  12.  
  13.  
  14. modem.open(5037)
  15.  
  16.  
  17.  
  18.  
  19.  
  20. function makeSendData(destinationX, destinationY, destinationZ)
  21.     parentLocation = {gps.locate()}
  22.    
  23.      sendData = {
  24.         destination = {
  25.             x = destinationX,
  26.             y = destinationY,
  27.             z = destinationZ,
  28.             direction = 1
  29.         },
  30.         returnPoint = {
  31.             x = stationReturn.x + parentLocation[1],
  32.             y = stationReturn.y + parentLocation[2],
  33.             z = stationReturn.z + parentLocation[3]
  34.         },
  35.         exitPath = exitPathing,
  36.         enterPath = enterPathing,
  37.         parentLocation = parentLocation
  38.     }
  39.  
  40.     return sendData
  41. end
  42.  
  43.  
  44.  
  45. function dispatchBot(sendData)
  46.     turtle.select(findTurtle())
  47.     while turtle.inspect() do
  48.         print("No space to place turtle")
  49.         sleep(0.5)
  50.     end
  51.    
  52.     while not turtle.inspect() do
  53.         turtle.place()
  54.         sleep(0.5)
  55.     end
  56.    
  57.     local turtleChild = peripheral.wrap("front")
  58.     turtleChild.turnOn()
  59.    
  60.     connecting = true
  61.     while connecting do
  62.         print("waiting...")
  63.         messageData = {os.pullEvent('modem_message')}
  64.         if messageData[5] == 'created' then
  65.             print("created")
  66.             connecting = false
  67.             modem.transmit(messageData[4], messageData[3], sendData)
  68.             sleep(2)
  69.             return true
  70.         end
  71.     end
  72. end
  73.  
  74.  
  75.  
  76. function findTurtle()
  77.     for i=1, 16, 1 do
  78.         data = turtle.getItemDetail(i)
  79.         if data.name == "computercraft:turtle_advanced" then
  80.             return i
  81.         end
  82.     end
  83.     print("no turtles in inventory")
  84.     return nil
  85. end
  86.  
  87.  
  88.  
  89.  
  90.  
  91. print("What Y value would you like the ceiling to be?: ")
  92. ceiling = io.read()
  93. print(ceiling)
  94. print("How many slices deep would you like to go? (each slice is 3 blocks): ")
  95. slices = io.read()
  96. print(slices)
  97.  
  98.  
  99.  
  100. if slices == 0 then
  101.     print("You specified a depth of zero therefor nothing will be done... (exiting)")
  102.     exit()
  103. end
  104.  
  105. currentLocation = {gps.locate()}
  106.  
  107. for x=1, 5, 1 do
  108.     dispatchX = x*16-16+(currentLocation[1]-40)
  109.  
  110.     for y=1, 5, 1 do
  111.         dispatchZ = x*16-16+(currentLocation[3]-40)
  112.  
  113.         for i=1, slices, 1 do
  114.             dispatchY = (ceiling-(slices*3)-1)+(i*3)
  115.             dispatchBot(makeSendData(dispatchX, dispatchY, dispatchZ))
  116.         end
  117.     end
  118. end
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement