TheKojent

patchWall

Apr 2nd, 2013
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. os.loadAPI("try")
  2. os.loadAPI("check")
  3.  
  4. local dir = true
  5. local slot = 1
  6. local inv = 0
  7. local tArgs = { ... }
  8. if # tArgs ~= 2 then
  9.     print("Usage: patch <width> <height>")
  10.     return
  11. end
  12.  
  13. width = tonumber(tArgs[1])
  14. height = tonumber(tArgs[1])
  15.  
  16. local maxBlocks = width * height
  17.  
  18. for i = 1,16 do
  19.     inv = inv + turtle.getItemCount(i)
  20. end
  21.  
  22. if maxBlocks > inv then
  23.     print("Running this script may require more blocks than are available. Are you sure you want to continue? (Y/N)")
  24. end
  25.  
  26. while true do
  27.     local event, char = os.pullEvent("char")
  28.     if char == "y" then
  29.         break
  30.     elseif char == "n" then
  31.         return
  32.     else
  33.         sleep(0.2)
  34.     end
  35. end
  36.  
  37. local function slotCheck()
  38.     while turtle.getItemCount(slot) == 0 do
  39.         slot = slot + 1
  40.     end
  41.     turtle.select(slot)
  42. end
  43.  
  44. for i = 1,width do
  45.     for j = 1,height do
  46.         slotCheck()
  47.         if not turtle.place() and not turtle.detect() then
  48.             turtle.attack()
  49.         end
  50.         if j ~= height then
  51.             if dir then
  52.                 if not try.up() then
  53.                     print("Cannot move up! Exiting script...")
  54.                     return
  55.                 end
  56.             elseif not try.down() then
  57.                 print("Cannot move down! Exiting script...")
  58.                 return
  59.             end
  60.         end
  61.     end
  62.     if i ~= width then
  63.         turtle.turnRight()
  64.         if not try.forward() then
  65.             print("Cannot move forward! Exiting script...")
  66.             return
  67.         end
  68.         turtle.turnLeft()
  69.     end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment