Advertisement
Jirek

Computercraft - Turtle - BuildVolume

Jan 1st, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | None | 0 0
  1. --EN:
  2. --This program uses virtual maps from ScanVolume
  3. --program. It will build exactly what's saved
  4. --in the map.
  5. --
  6. --Download ScanVolume from http://pastebin.com/BQn89Swq
  7.  
  8. --CZ:
  9. --Tenhle program pouziva virtualni mapy vytvorene
  10. --programem ScanVolume a stavi podle nich.
  11. --
  12. --Stahnete si ScanVolume z http://pastebin.com/BQn89Swq
  13.  
  14. --
  15. --Input ------------------------------------------
  16. --
  17.  
  18. local tArgs = { ... }
  19. if #tArgs ~= 1 and #tArgs ~= 2 then
  20.   print("Usage: BuildVolume <map name>")
  21.   return
  22. end
  23.  
  24. if fs.exists("BuildArea") == false then
  25.   print("This program requires BuildArea program in the same directory")
  26.   return
  27. end
  28.  
  29. if fs.isDir(tArgs[1]) == false then
  30.   print("Current map does not exist")
  31.   return
  32. end
  33.  
  34. --Runned by another program?
  35. local runByProgram = tArgs[2] == "T"
  36.  
  37. --Clear screen
  38. if runByProgram == false then
  39.   term.clear()
  40.   term.setCursorPos(1, 1)
  41.   print("Info: Fuel place only in the last slot")
  42.   print("      Material place anywhere except the last slot")
  43.   print("")
  44. end
  45.  
  46. --
  47. --Main variables ---------------------------------
  48. --
  49.  
  50. local nSelected = 1
  51. local WeirdFile = false
  52. local Z
  53.  
  54. --
  55. --Methods ----------------------------------------
  56. --
  57.  
  58. local function CheckForAll()
  59.   --material
  60.   local bCheck = true
  61.   while bCheck do
  62.     bCheck = false
  63.     if turtle.getItemCount(nSelected) == 0 then
  64.       nSelected = nSelected + 1
  65.       turtle.select(nSelected)
  66.       bCheck = true
  67.     end
  68.     if nSelected == 16 then
  69.       bCheck = false
  70.       nSelected = 1
  71.       turtle.select(nSelected)
  72.       print("Out of material, fill me Im waiting...")
  73.       while turtle.getItemCount(1) == 0 do
  74.         os.sleep(1)
  75.       end
  76.       print("Thanks!")
  77.     end
  78.   end
  79.    
  80.   --fuel
  81.   if turtle.getFuelLevel() == 0 then
  82.     turtle.select(16)
  83.     local bFirst = true
  84.     while turtle.refuel(1) == false do
  85.       if bFirst then
  86.         print("Out of fuel, waiting...")
  87.       end
  88.       os.sleep(1)
  89.       bFirst = false
  90.     end
  91.     print("Thanks!")
  92.     turtle.select(nSelected)
  93.   end
  94. end
  95.  
  96. --
  97. --Code -------------------------------------------
  98. --
  99.  
  100. --Read map
  101. local files = fs.list(tArgs[1])
  102. local i = 1
  103. while i <= #files do
  104.   if files[i] ~= "layer"..tostring(i) then
  105.     WeirdFile = true
  106.   end
  107.   i = i + 1
  108. end
  109.  
  110. --Is weird?
  111. if WeirdFile then
  112.   print("This map is weird!")
  113.   return
  114. end
  115.  
  116. Z = #files
  117.  
  118. --Build
  119. local z = Z
  120. while z >= 1 do
  121.   shell.run("BuildArea "..tArgs[1].."/layer"..tostring(z).." T")
  122.   if z ~= 1 then
  123.     CheckForAll()
  124.     shell.run("/rom/programs/turtle/go up")
  125.   end
  126.   z = z - 1
  127. end
  128.  
  129. if runByProgram == false then
  130.   print("All done!")
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement