Jirek

Computercraft - Turtle - BorderArea

Dec 28th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. --EN:
  2. --This programs fills border of specified area
  3. --with material
  4.  
  5. --CZ:
  6. --Tenhle program vyplni okraj zadane
  7. --oblasti materialem
  8.  
  9. print("Info: Fuel place only in the last slot")
  10. print("      Material place anywhere except the last slot")
  11.  
  12. --
  13. --Input ------------------------------------------
  14. --
  15.  
  16. local tArgs = { ... }
  17. if #tArgs ~= 2 then
  18.     print("Usage: BorderArea <x> <y>")
  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 BuildRowX()
  72.   local i = 1
  73.   while i <= X do
  74.     CheckForAll()
  75.     turtle.placeDown()
  76.     if i ~= X then
  77.       shell.run("/rom/programs/turtle/go forward")
  78.     end
  79.     i = i + 1
  80.   end
  81. end
  82.  
  83. local function BuildRowY()
  84.   local i = 1
  85.   while i <= Y do
  86.     CheckForAll()
  87.     turtle.placeDown()
  88.     if i ~= Y then
  89.       shell.run("/rom/programs/turtle/go forward")
  90.     end
  91.     i = i + 1
  92.   end
  93. end
  94.  
  95. --
  96. --Code -------------------------------------------
  97. --
  98.  
  99. turtle.select(1)
  100.  
  101. BuildRowX()
  102. shell.run("/rom/programs/turtle/go right")
  103.  
  104. BuildRowY()
  105. shell.run("/rom/programs/turtle/go right")
  106.  
  107. BuildRowX()
  108. shell.run("/rom/programs/turtle/go right")
  109.  
  110. BuildRowY()
  111. shell.run("/rom/programs/turtle/go right")
  112.  
  113. print("All done!")
Advertisement
Add Comment
Please, Sign In to add comment