Advertisement
Jirek

Computercraft - Turtle - ScanVolume

Dec 31st, 2013
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. --EN:
  2. --This programs creates 3D virtual maps
  3.  
  4. --CZ:
  5. --Tenhle program vytvari 3D mapy
  6.  
  7. --
  8. --Input ------------------------------------------
  9. --
  10.  
  11. local tArgs = { ... }
  12. if #tArgs ~= 4 and #tArgs ~= 5 then
  13.   print("Usage: ScanVolume <x> <y> <z> <map name>")
  14.   return
  15. end
  16.  
  17. if fs.exists("ScanDestroyArea") == false then
  18.   print("This program requires ScanDestroyArea program in the same directory")
  19.   return
  20. end
  21.  
  22. if fs.isDir(tArgs[4]) then
  23.   print("Current directory already exists")
  24.   return
  25. end
  26.  
  27. --Runned by another program?
  28. local runByProgram = tArgs[5] == "T"
  29.  
  30. --Clear screen
  31. if runByProgram == false then
  32.   term.clear()
  33.   term.setCursorPos(1, 1)
  34.   print("Info: Fuel place only in the last slot")
  35.   print("      Run only on mining turtle")
  36.   print("")
  37. end
  38.  
  39. --
  40. --Main variables ---------------------------------
  41. --
  42.  
  43. local X = tonumber(tArgs[1])
  44. local Y = tonumber(tArgs[2])
  45. local Z = tonumber(tArgs[3])
  46.  
  47. --
  48. --Methods ----------------------------------------
  49. --
  50.  
  51. local function CheckForAll()
  52.   --fuel
  53.   if turtle.getFuelLevel() == 0 then
  54.     turtle.select(16)
  55.     local bFirst = true
  56.     while turtle.refuel(1) == false do
  57.       if bFirst then
  58.         print("Out of fuel, waiting...")
  59.       end
  60.       os.sleep(1)
  61.       bFirst = false
  62.     end
  63.     print("Thanks!")
  64.     turtle.select(1)
  65.   end
  66. end
  67.  
  68. --
  69. --Code -------------------------------------------
  70. --
  71.  
  72. --Make dir
  73. fs.makeDir(tArgs[4])
  74.  
  75. --Scan
  76. local i = 1
  77. while i <= Z do
  78.   shell.run("ScanDestroyArea "..tostring(X).." "..tostring(Y).." "..tArgs[4].."/layer"..tostring(i))
  79.   if i ~= Z then
  80.     CheckForAll()
  81.     shell.run("/rom/programs/turtle/go down")
  82.   end
  83.   i = i + 1
  84. end
  85.  
  86. if runByProgram == false then
  87.   print("All done!")
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement