imposiblaa

turtle parent

Dec 23rd, 2020 (edited)
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.24 KB | None | 0 0
  1. local slices = 9
  2. local enterPathing = {"south", "goto", 2, 0, 0, "drop-off", "right", "forward", "up", "forward", "eatme"}
  3. local exitPathing = {"fuel", "forward"}
  4. gps.CHANNEL_GPS = 5033
  5. local stationReturn = {
  6.     x = 2,
  7.     y = 0,
  8.     z = -2
  9. }
  10. local modem = peripheral.wrap("left")
  11. local firstSquare = true
  12. modem.open(5037)
  13.  
  14. lineProgress = 0
  15. width = 1
  16. middleSquare = {x = 0, y = 0}
  17. newSquare = {x = 0, y = -1}
  18.  
  19. -- gets the turtle going!
  20. function startTurtle(coords, parentLocation)
  21.     sendData = {
  22.         destination = {
  23.             x = coords.x,
  24.             y = coords.y,
  25.             z = coords.z,
  26.             direction = coords.direction
  27.         },
  28.         returnPoint = {
  29.             x = stationReturn.x + parentLocation[1],
  30.             y = stationReturn.y + parentLocation[2],
  31.             z = stationReturn.z + parentLocation[3]
  32.         },
  33.         exitPath = exitPathing,
  34.         enterPath = enterPathing,
  35.         parentLocation = parentLocation
  36.     }
  37.     placing = true
  38.     s = 1
  39.     while placing do
  40.         turtle.select(s)
  41.         turtle.place()
  42.         local babyTurtle = peripheral.wrap("front")
  43.         if babyTurtle then
  44.             babyTurtle.turnOn()
  45.             placing = false
  46.             break
  47.         end
  48.         if s == 16 then
  49.             s = 1
  50.         else
  51.             s = s+1
  52.         end
  53.     end
  54.     creating = true
  55.     while creating do
  56.         print("back to top")
  57.         message = {os.pullEvent("modem_message")}
  58.         data = message[5]
  59.         if data == "created" then
  60.             print("created!!!")
  61.             modem.transmit(message[4], message[3], sendData)
  62.             sleep(2)
  63.             return true
  64.         end
  65.     end    
  66. end
  67. -- passes all the in-game coordinates into the "startTurtle" function
  68. function createSquare(x, y, squareSide, parentLocation)
  69.     print(x .." " ..y)
  70.     for slice = 1, slices do
  71.         worldCoords = {x = ((parentLocation[1]) + (x * 15)), y = (((slice - 1) * 3) + 3), z = ((parentLocation[3]) + (y * 15)), direction = squareSide}
  72.         print(textutils.serialize(worldCoords))
  73.         startTurtle(worldCoords, parentLocation)
  74.     end  
  75.     sleep(10)
  76.     if(firstSquare) then
  77.         sleep(600)
  78.     end
  79.     return true
  80. end
  81.  
  82. multishell.launch({}, "mine2")
  83.  
  84. location = {gps.locate()}
  85. for part = 1, #location do
  86.     location[part] = math.floor(location[part]+0.5)
  87. end
  88.  
  89. createSquare(0, 0, 1, location)
  90. while true  do
  91.     print("debug")
  92.     lineNumber = 1
  93.     for line = 1, 4, 1 do
  94.         if lineNumber == 1 then
  95.             lineProgress = 0
  96.             startOfLine = {x = newSquare.x - 1, y = newSquare.y + 2}
  97.             for square=0, width, 1 do
  98.                 newSquare = {x = startOfLine.x + square, y = startOfLine.y}
  99.                 createSquare(newSquare.x, newSquare.y, lineNumber, location)
  100.                 lineProgress = lineProgress + 1
  101.             end
  102.             lineNumber = 2
  103.         elseif lineNumber == 2 then
  104.             lineProgress = 0
  105.             startOfLine = {x = newSquare.x + 1, y = newSquare.y}
  106.             for square=0, width, 1 do
  107.                 newSquare = {x = startOfLine.x, y = startOfLine.y - square}
  108.                 createSquare(newSquare.x, newSquare.y, lineNumber, location)
  109.                 lineProgress = lineProgress + 1
  110.             end
  111.             lineNumber = 3
  112.         elseif lineNumber == 3 then
  113.             lineProgress = 0
  114.             startOfLine = {x = newSquare.x, y = newSquare.y - 1}
  115.             for square=0, width, 1 do
  116.                 newSquare = {x = startOfLine.x - square, y = startOfLine.y}
  117.                 createSquare(newSquare.x, newSquare.y, lineNumber, location)
  118.                 lineProgress = lineProgress + 1
  119.             end
  120.             lineNumber = 4
  121.         elseif lineNumber == 4 then
  122.             lineProgress = 0
  123.             startOfLine = {x = newSquare.x - 1, y = newSquare.y}
  124.             for square=0, width, 1 do
  125.                 newSquare = {x = startOfLine.x, y = startOfLine.y + square}
  126.                 createSquare(newSquare.x, newSquare.y, lineNumber, location)
  127.                 lineProgress = lineProgress + 1
  128.             end
  129.             lineProgress = 1
  130.             width = width+2
  131.             sleep(10)
  132.         end
  133.     end
  134.  
  135.                
  136.                
  137. end
Add Comment
Please, Sign In to add comment