Advertisement
Jirek

Computercraft - Turtle - FillArea

Dec 28th, 2013
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. --EN:
  2. --This program will fill specified area with material
  3. --It puts the materia underneath the turtle
  4.  
  5. --CZ:
  6. --Tenhle program vyplni danou oblast materialem
  7.  
  8. print("Info: Fuel place only in the last slot")
  9. print("      Material place anywhere except the last slot")
  10.  
  11. --
  12. --Input ------------------------------------------
  13. --
  14.  
  15. local tArgs = { ... }
  16. if #tArgs ~= 2 then
  17.   print("Usage: Fill <forward> <right>")
  18.   return
  19. end
  20.  
  21. --
  22. --Main variables ---------------------------------
  23. --
  24.  
  25. local nSelected = 1
  26. local X = tonumber(tArgs[1])
  27. local Y = tonumber(tArgs[2])
  28.  
  29. --
  30. --Methods ----------------------------------------
  31. --
  32.  
  33. local function CheckForAll()
  34.   --material
  35.   local bCheck = true
  36.   while bCheck do
  37.     bCheck = false
  38.     if turtle.getItemCount(nSelected) == 0 then
  39.       nSelected = nSelected + 1
  40.       turtle.select(nSelected)
  41.       bCheck = true
  42.     end
  43.     if nSelected == 16 then
  44.       bCheck = false
  45.       nSelected = 1
  46.       turtle.select(nSelected)
  47.       print("Out of material, fill me Im waiting...")
  48.       while turtle.getItemCount(1) == 0 do
  49.         os.sleep(1)
  50.       end
  51.       print("Thanks!")
  52.     end
  53.   end
  54.    
  55.   --fuel
  56.   if turtle.getFuelLevel() == 0 then
  57.     turtle.select(16)
  58.     local bFirst = true
  59.     while turtle.refuel(1) == false do
  60.       if bFirst then
  61.         print("Out of fuel, waiting...")
  62.       end
  63.       os.sleep(1)
  64.       bFirst = false
  65.     end
  66.     print("Thanks!")
  67.     turtle.select(nSelected)
  68.   end
  69. end
  70.  
  71. local function FillLine()
  72.   local x = 1
  73.   while x <= X do
  74.     CheckForAll()
  75.     turtle.placeDown()
  76.     if x ~= X then
  77.       shell.run("/rom/programs/turtle/go forward")
  78.     end
  79.     x = x + 1
  80.   end
  81. end
  82.  
  83. --
  84. --Code -------------------------------------------
  85. --
  86.  
  87. turtle.select(1)
  88. local invertedLine = false
  89. local y = 1
  90. while y <= Y do
  91.   FillLine()
  92.   if y ~= Y then
  93.     if invertedLine then
  94.       CheckForAll()
  95.       shell.run("/rom/programs/turtle/go left forward left")
  96.       invertedLine = false
  97.     else
  98.       CheckForAll()
  99.       shell.run("/rom/programs/turtle/go right forward right")
  100.       invertedLine = true
  101.     end
  102.   end
  103.   y = y + 1
  104. end
  105.  
  106. --Return
  107. if invertedLine then
  108.   shell.run("/rom/programs/turtle/go right")
  109.   for n=1, (Y - 1) do
  110.     CheckForAll()
  111.     shell.run("/rom/programs/turtle/go forward")
  112.   end
  113.   shell.run("/rom/programs/turtle/go right")
  114. else
  115.   shell.run("/rom/programs/turtle/go left")
  116.   for n=1, (Y - 1) do
  117.     CheckForAll()
  118.     shell.run("/rom/programs/turtle/go forward")
  119.   end
  120.   shell.run("/rom/programs/turtle/go left")
  121.   for n=1, (X - 1) do
  122.     CheckForAll()
  123.     shell.run("/rom/programs/turtle/go forward")
  124.   end
  125.   shell.run("/rom/programs/turtle/go left 2")
  126. end
  127.  
  128. print("All done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement