Razara

Tower Builder

May 8th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. tArgs = {...}
  2.  
  3.  
  4.  
  5.  
  6. local length, height, width
  7. if #tArgs ~= 3 then
  8.     print("Invalid number of arguments. Needs length, width, height")
  9. else
  10.     length = tonumber(tArgs[1])
  11.     width = tonumber(tArgs[2])
  12.     height = tonumber(tArgs[3])
  13. end
  14.  
  15.  
  16. term.clear()
  17. mt = {}
  18. count = 1
  19.  
  20. function look(y,x)
  21.     mt[count] = turtle.detectDown()
  22. end
  23.  
  24. function place(y,x)
  25.    
  26.     while turtle.getItemCount(1) == 1 do
  27.         res.resupply(1)
  28.         sleep(5)
  29.     end
  30.    
  31.     if mt[count] then
  32.         turtle.placeDown()
  33.     end
  34. end
  35.  
  36. function scan()
  37.     for y = 1,width do
  38.         for xx = 1,length-1 do
  39.             x = xx
  40.             if y%2 == 0 then
  41.                 x = length - xx
  42.             end
  43.             look(y,x)
  44.             forward()
  45.         end
  46.         if y < width then
  47.             if y%2 ~= 0 then
  48.                 turtle.turnRight()
  49.                 look(y,length)
  50.                 forward()
  51.                 turtle.turnRight()
  52.             else
  53.                 turtle.turnLeft()
  54.                 look(y,1)
  55.                 forward()
  56.                 turtle.turnLeft()
  57.             end
  58.            
  59.         end
  60.     end
  61. end
  62.  
  63.  
  64. function fill()
  65.     for z = 1,height do
  66.     count = 1
  67.         for y = 1,width do
  68.             for xx = 1,length-1 do
  69.                 x = xx
  70.                 if y%2 == 0 then
  71.                     x = length - xx
  72.                 end
  73.                 place(y,x)
  74.                 forward()
  75.             end
  76.             if y < width then
  77.                 if y%2 ~= 0 then
  78.                     turtle.turnRight()
  79.                     place(y,length)
  80.                     forward()
  81.                     turtle.turnRight()
  82.                 else
  83.                     turtle.turnLeft()
  84.                     place(y,1)
  85.                     forward()
  86.                     turtle.turnLeft()
  87.                 end
  88.                
  89.             end
  90.         end
  91.         turtle.up()
  92.         returnToStart()
  93.     end
  94. end
  95.  
  96. function returnToStart()
  97.     if width%2 ~= 0 then
  98.         turtle.turnRight()
  99.         turtle.turnRight()
  100.         for x = 1,length-1 do
  101.          forward()
  102.         end
  103.     end
  104.     turtle.turnRight()
  105.     for y = 1,width-1 do
  106.          forward()
  107.     end
  108.     turtle.turnRight()
  109. end
  110.  
  111. function forward()
  112.    
  113.    while turtle.getFuelLevel() < 100 do
  114.     turtle.select(2)
  115.     turtle.refuel(63)
  116.     res.resupply(2)
  117.     turtle.select(1)
  118.     sleep(5)
  119.    end
  120.    
  121.    while not turtle.forward() do sleep(0.5) end
  122.    count = count + 1
  123.  
  124. end
  125.  
  126. write("Establishing link to resupply module... ")
  127. res = peripheral.wrap("left")
  128. res.link()
  129. print("Done")
  130.  
  131. write("Scanning pattern...")
  132. scan()
  133. print("Done")
  134.  
  135. print("Placing blocks")
  136. returnToStart()
  137. turtle.up()
  138. fill()
  139.  
  140. for i = 1,height+1 do turtle.down() end
  141.  
  142. term.setCursorPos(0,length+2)
Advertisement
Add Comment
Please, Sign In to add comment