Advertisement
Yorinar

RoadWarrior v 0.07

Oct 6th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. args = { ... }
  2.  
  3. if not args[0] and not args[1] then
  4.   write("Usage: RoadWarrior <width> <distance>\n")
  5.   exit()
  6. end
  7.  
  8. width = tonumber(args[1])
  9. distance = tonumber(args[2])
  10. currentSelection = 1
  11.  
  12. turningRight = true
  13. currentX = 1
  14. currentY = 1
  15.  
  16. function determineMaxSelection ()
  17.   for i=1,16 do
  18.     if turtle.getItemCount(i) == nil or turtle.getItemCount(i) == 0 then
  19.       return i - 1
  20.     end
  21.   end
  22.  
  23.   return 16
  24. end
  25.  
  26. maxSelection = determineMaxSelection()
  27. if maxSelection < 1 then
  28.   write("\nMust place the road blocks you wish to lay in the turtle, starting in the upper left corner.\n\n")
  29.   exit()
  30. end
  31.  
  32. function moveForward()
  33.   if turtle.detect() then
  34.     turtle.dig()
  35.   end
  36.  
  37.   return turtle.forward()
  38. end
  39.  
  40.  
  41. function layBlock (selection)
  42.   if selection > maxSelection then
  43.     write("Ran out of blocks to lay.  Stopping.\n\n")
  44.     return false
  45.   end
  46.  
  47.   leftToDrop = turtle.getItemCount(selection)
  48.   if leftToDrop > 0 then
  49.     if currentSelection ~= selection then
  50.       turtle.select(selection)
  51.     end
  52.  
  53.     turtle.digDown()
  54.     turtle.placeDown()
  55.     return selection
  56.   else
  57.     layBlock(selection + 1)
  58.     return selection + 1
  59.   end
  60. end
  61.  
  62. function advance ()
  63.   if currentX == 1 then
  64.     turtle.turnRight()
  65.     moveForward()
  66.     currentX = currentX + 1
  67.   elseif currentX == width then
  68.     turtle.turnLeft()
  69.     turtle.turnLeft()
  70.    
  71.     for i=1,(width - 1) do
  72.       moveForward()
  73.     end
  74.     turtle.turnRight()
  75.     moveForward()
  76.     currentX = 1
  77.     currentY = currentY + 1
  78.   else
  79.     moveForward()
  80.     currentX = currentX + 1
  81.   end
  82. end
  83.  
  84.  
  85. for currentY=1,distance do
  86.   write("\nLaying row "..currentY.." of "..distance..".\n")
  87.  
  88.   for currentX=1,width do
  89.     write(" laying position ("..currentX..", "..currentY..").\n")
  90.     currentSelection = layBlock(currentSelection)
  91.     if currentSelection == false then
  92.       exit()
  93.     end
  94.  
  95.     if turtle.detect() then
  96.       turtle.dig()
  97.     end
  98.     advance()
  99.   end
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement