Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.43 KB | None | 0 0
  1. -- pastebin get xS8Fy4kG quarry
  2. -- version 1.1.0
  3. local direction = {
  4.     ["forw"]  = 1,
  5.     ["right"] = 2,
  6.     ["back"]  = 3,
  7.     ["left"]  = 4,
  8. }
  9. local dir = direction.forw
  10. local pos = {
  11.     ["x"]   = 0,
  12.     ["y"]   = 0,
  13.     ["z"]   = 0,
  14. }
  15.  
  16. local name = "quarry"
  17. local done = false
  18. globalState = 0
  19. aState = 0 --состояние автомата
  20. tmpState = 0
  21. local lenght,width,height = 0,0,0
  22. local xt,yt,zt,dt = 0,0,0,direction.forw
  23. mode = 1
  24.  
  25. local function saveState()
  26.     name = shell.getRunningProgram()
  27.     local file = fs.open(name..".save","w")
  28.     file.writeLine(mode)
  29.     file.writeLine(globalState)
  30.     file.writeLine(pos.x)
  31.     file.writeLine(pos.y)
  32.     file.writeLine(pos.z)
  33.     file.writeLine(dir)
  34.     file.writeLine(tmpState)
  35.     file.writeLine(aState)
  36.     file.writeLine(xt)
  37.     file.writeLine(yt)
  38.     file.writeLine(zt)
  39.     file.writeLine(dt)
  40.     file.writeLine(lenght)
  41.     file.writeLine(width)
  42.     file.writeLine(height)
  43.     file.writeLine(done)
  44.     file.close()
  45. end
  46.  
  47. local function readState()
  48.     name = shell.getRunningProgram()
  49.     if not fs.exists(name..".save") then
  50.         return false
  51.     end
  52.     local file = fs.open(name..".save","r")
  53.     mode =      tonumber(file.readLine())
  54.     globalState = tonumber(file.readLine())
  55.     pos.x =     tonumber(file.readLine())
  56.     pos.y =     tonumber(file.readLine())
  57.     pos.z =     tonumber(file.readLine())
  58.     dir =       tonumber(file.readLine())
  59.     tmpState =  tonumber(file.readLine())
  60.     aState =    tonumber(file.readLine())
  61.     xt =        tonumber(file.readLine())
  62.     yt =        tonumber(file.readLine())
  63.     zt =        tonumber(file.readLine())
  64.     dt =        tonumber(file.readLine())  
  65.     lenght =    tonumber(file.readLine())
  66.     width =     tonumber(file.readLine())
  67.     height =    tonumber(file.readLine())
  68.     done =      file.readLine()
  69.     if done == "true" then
  70.         done = true
  71.     else
  72.         done = false
  73.     end
  74.     file.close()
  75.     return true
  76. end
  77.  
  78. local function setStartup()
  79.     if fs.exists("startup") then
  80. --      if fs.exists("startup.old") then
  81.             fs.delete("startup")
  82. --      else
  83. --          shell.run("move","startup","startup.old")
  84. --      end
  85.     end
  86.     name = shell.getRunningProgram()
  87.     local file = fs.open("startup","w")
  88.     file.writeLine("shell.run(\""..name.."\")")
  89.     file.close()
  90. end
  91.  
  92. local function delStartup()
  93.     if fs.exists("startup") then
  94.         fs.delete("startup")
  95.     end
  96. --  if fs.exists("startup.old") then
  97. --      shell.run("move","startup.old","startup")
  98. --  end
  99.     name = shell.getRunningProgram()
  100.     if fs.exists(name..".save") then
  101.         fs.delete(name..".save")
  102.     end
  103. end
  104.  
  105. function refuel(ammount)
  106.     local fuelLevel = turtle.getFuelLevel()
  107.     if fuelLevel == "unlimited" then
  108.         return true
  109.     end
  110.     local needed = 0
  111.     if ammount == nil then
  112.         needed = math.abs(pos.x) + math.abs(pos.y) + math.abs(pos.z) + 3
  113.     else
  114.         needed = ammount
  115.     end
  116.     if turtle.getFuelLevel() < needed then
  117.         for i=1,16 do
  118.             if turtle.getItemCount(i) > 0 then
  119.                 turtle.select(i)
  120.                 if turtle.refuel(64) then
  121.                     print("turtle get fuel")
  122.                     while turtle.getItemCount(i) > 0 and turtle.getFuelLevel() < needed do
  123.                         print("turtle get fuel")
  124.                         turtle.refuel(64)
  125.                     end
  126.                     if turtle.getFuelLevel() >= needed then
  127.                         turtle.select(1)
  128.                         return true
  129.                     end
  130.                 end
  131.             end
  132.         end
  133.         turtle.select(1)
  134.         return false
  135.     end
  136.     return true
  137. end
  138.  
  139. local function inventoryFull()
  140.     local bFull = true
  141.     for n=1,16 do
  142.         if turtle.getItemCount(n) == 0 then
  143.             bFull = false
  144.         end
  145.     end
  146.     if bFull then
  147.         print( "No empty slots left." )
  148.         return true
  149.     end
  150.     return false
  151. end
  152.  
  153. local function unload()
  154.     print( "Unloading items..." )
  155.     local n = 1
  156.     if mode == 1 then
  157.         if not turtle.detect() then
  158.             print("no detect chest")
  159.             while not turtle.detect() do
  160.                 os.sleep(1)
  161.             end
  162.         end
  163.         while n <= 16 do
  164.             turtle.select(n)
  165.             if turtle.getItemCount(n) > 0 and not turtle.drop() then
  166.                 print("Don't unload to chest")
  167.                 os.sleep(5)
  168.             else
  169.                 n = n + 1
  170.             end
  171.         end
  172.     else
  173.         if not turtle.detectUp() then
  174.             print("no detect chest")
  175.             while not turtle.detectUp() do
  176.                 os.sleep(1)
  177.             end
  178.         end
  179.         n = 2
  180.         while n <= 16 do
  181.             turtle.select(n)
  182.             if turtle.getItemCount(n) > 0 and not turtle.dropUp() then
  183.                 print("Don't unload to chest")
  184.                 os.sleep(5)
  185.             else
  186.                 n = n + 1
  187.             end
  188.         end
  189.     end
  190.     turtle.select(1)
  191. end
  192.  
  193. local goTo
  194.  
  195. local function returnToEnderChest()
  196.     if globalState == 1 or globalState == 2 then
  197.         globalState = 5
  198.         saveState()
  199.     end
  200.     if globalState == 5 then
  201.         turtle.select(1)
  202.         while turtle.getItemCount(1) < 0 do
  203.             print("Don't found chest" )
  204.             print("Press any key to continue")
  205.             local input = read()
  206.         end
  207.         while true do
  208.             if turtle.detectUp() then   --обнаружен блок, сломать
  209.                 if turtle.digUp() then
  210.                     --print("detect block")
  211.                 else
  212.                     print("ERROR! Detect bedrock or unbreaking block.")
  213.                     error()
  214.                     return
  215.                 end
  216.             elseif turtle.attackUp() then -- Сверху нет блока, проверяем есть ли там существо
  217.                 print("detect monster or player")
  218.             else    -- Ставим СЃСѓРЅРґСѓРє
  219.                 if turtle.placeUp() then
  220.                     -- it's ok!
  221.                     globalState = 6
  222.                     saveState()
  223.                     break
  224.                 else
  225.                     print("detect unknowing object")
  226.                     os.sleep(0.5)
  227.                 end
  228.             end
  229.         end
  230.     end
  231.     if globalState == 6 then
  232.         unload()
  233.         turtle.select(1)
  234.         if turtle.getItemCount(1) > 0 then
  235.             turtle.dropUp()
  236.         end
  237.         turtle.digUp()
  238.         globalState = 2
  239.         saveState()
  240.     end
  241. end
  242.  
  243. local function returnToChest(drop)
  244.     if globalState == 1 or globalState == 2 then
  245.         xt = pos.x
  246.         yt = pos.y
  247.         zt = pos.z
  248.         dt = dir
  249.         globalState = 3
  250.         saveState()
  251.     end
  252.     if globalState == 3 then
  253.         print( "Returning to surface..." )
  254.         goTo( 0,0,0,direction.back)
  255.         if drop then
  256.             unload()
  257.         end
  258.         globalState = 4
  259.         saveState()
  260.     end
  261.     if globalState == 4 then
  262.         local fuelNeeded = (math.abs(xt) + math.abs(yt) + math.abs(zt) + 3)*2
  263.         if not refuel( fuelNeeded ) then
  264.             print( "Waiting for fuel" )
  265.             while not refuel( fuelNeeded ) do
  266.                 sleep(1)
  267.             end
  268.         end
  269.         print( "Resuming mining..." )
  270.         goTo( xt,yt,zt,dt )
  271.         globalState = 2
  272.         xt = 0
  273.         yt = 0
  274.         zt = 0
  275.         dt = direction.forw
  276.         saveState()
  277.     end
  278. end
  279.  
  280. local function returnSupplies()
  281.     if mode == 1 then
  282.         returnToChest(true)
  283.     else
  284.         returnToEnderChest()
  285.     end
  286. end
  287.  
  288. local function turnRight()
  289.     dir=dir+1  
  290.     if dir==5 then dir = direction.forw end
  291.         saveState()
  292.     turtle.turnRight()
  293. end
  294.  
  295. local function turnLeft()
  296.     dir=dir-1  
  297.     if dir==0 then dir = direction.left end
  298.         saveState()
  299.     turtle.turnLeft()
  300. end
  301.  
  302. local function checkBorder()
  303.     if (math.abs(pos.x) >=  width) or (math.abs(pos.z) >= lenght) then
  304.         print("going beyond a border")
  305.         delStartup()
  306.         error()
  307.     end
  308. end
  309.  
  310. local function down()
  311.     while true do
  312.         if turtle.detectDown() then
  313.             if turtle.digDown() then
  314. --              print("detect block")
  315.             else
  316.                 print("detect bedrock or unbreaking block")
  317.                 return false
  318.             end
  319.         elseif turtle.attackDown() then
  320.             print("detect monster or player")
  321.         else   
  322.             local ty = pos.y
  323.             pos.y = pos.y - 1
  324.             saveState()
  325.             if turtle.down() then
  326. --              print("it's ok!")
  327.                 checkBorder()
  328.                 return true
  329.             else
  330.                 print("detect unknowing object")
  331.                 pos.y = ty
  332.                 saveState()
  333.                 os.sleep(0.5)
  334.             end
  335.         end
  336.     end
  337. end
  338.  
  339. local function up()
  340.     while true do
  341.         if turtle.detectUp() then   --обнаружен блок, сломать
  342.             if turtle.digUp() then
  343. --              print("detect block")
  344.             else
  345.                 print("detect bedrock or unbreaking block")
  346.                 return false
  347.             end
  348.         elseif turtle.attackUp() then -- Сверху нет блока, проверяем есть ли там существо
  349.             print("detect monster or player")
  350.         else    -- Передвигаемся вверх
  351.             local ty = pos.y
  352.             pos.y = pos.y + 1
  353.             saveState()
  354.             if turtle.up() then
  355.                 -- it's ok!
  356. --              print("it's ok!")
  357.                 checkBorder()
  358.                 return true
  359.             else
  360.                 -- backup
  361.                 print("detect unknowing object")
  362.                 pos.y = ty
  363.                 saveState()
  364.                 os.sleep(0.5)
  365.             end
  366.         end
  367.     end
  368. end
  369.  
  370. local function forward(mined)
  371.     if mined then
  372.         if turtle.detectUp() then
  373.             turtle.digUp()
  374.             if inventoryFull() then
  375.                 returnSupplies()
  376.             end
  377.         end
  378.         if turtle.detectDown() then
  379.             turtle.digDown()
  380.             if inventoryFull() then
  381.                 returnSupplies()
  382.             end
  383.         end
  384.     end
  385.    
  386.     while true do
  387.         if turtle.detect() then --обнаружен блок, сломать
  388.             if turtle.dig() then
  389. --              print("detect block")
  390.                  if mined and inventoryFull() then
  391.                      returnSupplies()
  392.                  end
  393.             else
  394.                 print("detect bedrock or unbreaking block")
  395.                 return false
  396.             end
  397.         elseif turtle.attack() then -- Впереди нет блока, проверяем есть ли там существо
  398.             print("detect monster or player")
  399.              if mined and inventoryFull() then
  400.                  returnSupplies()
  401.              end
  402.         else    -- Передвигаемся вперед
  403.             if mined then -- Уберем гравий
  404.                 while turtle.detectUp() do
  405.                     turtle.digUp()
  406.                     os.sleep(0.5)
  407.                 end
  408.             end
  409.             local tz,tx = pos.z,pos.x
  410.             if dir == direction.forw then
  411.                 pos.z=pos.z+1
  412.             elseif dir == direction.right then
  413.                 pos.x=pos.x+1
  414.             elseif dir == direction.back then
  415.                 pos.z=pos.z-1
  416.             elseif dir == direction.left then
  417.                 pos.x=pos.x-1
  418.             end
  419.             saveState()
  420.             if turtle.forward() then
  421. --              print("it's ok!")
  422.                 checkBorder()
  423.                 return true
  424.             else
  425.                 -- backup
  426.                 if not turtle.detect() then
  427.                     print("detect unknowing object")
  428.                 end
  429.                 pos.z = tz
  430.                 pos.x = tx
  431.                 saveState()
  432.                 os.sleep(0.5)
  433.             end
  434.         end
  435.     end
  436. end
  437.  
  438. local function detectBedrock() --объехать бедрок
  439.     turnLeft()
  440.     turnLeft()
  441.     while not up() do
  442.         if not forward() then
  443.             print("don't going to bedrock!")
  444.             delStartup()
  445.             error()
  446.             return false
  447.             -- РЅРµ получилось объехать бедрок
  448.         end
  449.     end
  450.     return true
  451. end
  452.  
  453. function goTo( x, y, z, d)
  454.     while pos.y < y do  -- идем вверх
  455.         if not up() then
  456.             detectBedrock()
  457.         end
  458.     end
  459.     if pos.x > x then  
  460.         while dir ~= direction.left do
  461.             turnLeft()
  462.         end
  463.         while pos.x > x do
  464.             forward(false)
  465.         end
  466.     end
  467.     if pos.x < x then
  468.         while dir ~= direction.right do
  469.             turnRight()
  470.         end
  471.         while pos.x < x do
  472.             forward(false)
  473.         end
  474.     end
  475.     if pos.z > z then
  476.         while dir ~= direction.back do
  477.             turnRight()
  478.         end
  479.         while pos.z > z do
  480.             forward(false)
  481.         end
  482.     end
  483.     if pos.z < z then
  484.         while dir ~= direction.forw do
  485.             turnLeft()
  486.         end
  487.         while pos.z < z do
  488.             forward(false)
  489.         end
  490.     end
  491.     while pos.y > y do  -- идем РІРЅРёР·
  492.         down()
  493.     end
  494.     while d ~= dir do
  495.         turnLeft()
  496.     end
  497. end  
  498.  
  499. local function nextState()
  500.     if aState == 0 then
  501.         aState = 1
  502.     elseif aState == 1 then
  503.         if pos.z == lenght-1 and pos.x ~= width-1 then
  504.             aState = 2
  505.         elseif pos.z == lenght-1 and pos.x == width-1 then
  506.             aState = 9
  507.         end
  508.     elseif aState == 2 then
  509.         aState = 3
  510.     elseif aState == 3 then
  511.         if pos.z == 0 and pos.x ~= width-1 then
  512.             aState = 4
  513.         elseif pos.z == 0 and pos.x == width-1 then
  514.             aState = 10
  515.         end
  516.     elseif aState == 4 then
  517.         aState = 1
  518.     elseif aState == 5 then
  519.         if pos.z == lenght-1 and pos.x ~= 0 then
  520.             aState = 6
  521.         elseif pos.z == lenght-1 and pos.x == 0 then
  522.             aState = 11
  523.         end
  524.     elseif aState == 6 then
  525.         aState = 7
  526.     elseif aState == 7 then
  527.         if pos.z == 0 and pos.x ~= 0 then
  528.             aState = 8
  529.         elseif pos.z == 0 and pos.x == 0 then
  530.             aState = 12
  531.         end
  532.     elseif aState == 8 then
  533.         aState = 5
  534.     elseif aState == 9 then
  535.         aState = 7
  536.     elseif aState == 10 then
  537.         aState = 5
  538.     elseif aState == 11 then
  539.         aState = 3
  540.     elseif aState == 12 then
  541.         aState = 1
  542.     end
  543.     tmpState = 0
  544.     saveState()
  545.     return
  546. end
  547.  
  548. local function ref()
  549.     if not refuel() then
  550.         print( "Not enough Fuel" )
  551.         if mode == 1 then
  552.             returnSupplies()
  553.         else
  554.             returnToEnderChest()
  555.             returnToChest(false)
  556.         end
  557.     end
  558. end
  559.  
  560. local function lower()
  561.     if turtle.detectUp() then
  562.         turtle.digUp()
  563.     end
  564.     while tmpState ~= 3 do
  565.         ref()
  566.         tmpState = tmpState + 1
  567.         if not down() then
  568.             done = true
  569.             break
  570.         end
  571.     end
  572. end
  573.  
  574. local function main()
  575.     while not done do
  576.         if globalState == 2 then
  577.             if aState == 1 then
  578.                 ref()
  579.                 if not forward(true) then
  580.                     done = true
  581.                     break
  582.                 end
  583.             elseif aState == 2 then
  584.                 while tmpState ~= 3 do
  585.                     if tmpState == 0 then
  586.                         tmpState = tmpState + 1
  587.                         turnRight()
  588.                     elseif tmpState == 1 then
  589.                         ref()
  590.                         tmpState = tmpState + 1
  591.                         if not forward(true) then
  592.                             done = true
  593.                             break
  594.                         end
  595.                     elseif tmpState == 2 then
  596.                         tmpState = tmpState + 1
  597.                         turnRight()
  598.                     end
  599.                 end
  600.             elseif aState == 3 then
  601.                 ref()
  602.                 if not forward(true) then
  603.                     done = true
  604.                     break
  605.                 end
  606.             elseif aState == 4 then
  607.                 while tmpState ~= 3 do
  608.                     if tmpState == 0 then
  609.                         tmpState = tmpState + 1
  610.                         turnLeft()
  611.                     elseif tmpState == 1 then
  612.                         ref()
  613.                         tmpState = tmpState + 1
  614.                         if not forward(true) then
  615.                             done = true
  616.                             break
  617.                         end
  618.                     elseif tmpState == 2 then
  619.                         tmpState = tmpState + 1
  620.                         turnLeft()
  621.                     end
  622.                 end
  623.             elseif aState == 5 then
  624.                 ref()
  625.                 if not forward(true) then
  626.                     done = true
  627.                     break
  628.                 end
  629.             elseif aState == 6 then
  630.                 while tmpState ~= 3 do
  631.                     if tmpState == 0 then
  632.                         tmpState = tmpState + 1
  633.                         turnLeft()
  634.                     elseif tmpState == 1 then
  635.                         ref()
  636.                         tmpState = tmpState + 1
  637.                         if not forward(true) then
  638.                             done = true
  639.                             break
  640.                         end
  641.                     elseif tmpState == 2 then
  642.                         tmpState = tmpState + 1
  643.                         turnLeft()
  644.                     end
  645.                 end    
  646.             elseif aState == 7 then
  647.                 ref()
  648.                 if not forward(true) then
  649.                     done = true
  650.                     break
  651.                 end
  652.             elseif aState == 8 then
  653.                 while tmpState ~= 3 do
  654.                     if tmpState == 0 then
  655.                         tmpState = tmpState + 1
  656.                         turnRight()
  657.                     elseif tmpState == 1 then
  658.                         ref()
  659.                         tmpState = tmpState + 1
  660.                         if not forward(true) then
  661.                             done = true
  662.                             break
  663.                         end
  664.                     elseif tmpState == 2 then
  665.                         tmpState = tmpState + 1
  666.                         turnRight()
  667.                     end
  668.                 end    
  669.             elseif height+pos.y<3 then
  670.                 done = true
  671.                 break
  672.             elseif aState == 9 then
  673.                 while dir ~= direction.back do
  674.                     turnLeft()
  675.                 end
  676.                 lower()
  677.             elseif aState == 10 then
  678.                 while dir ~= direction.forw do
  679.                     turnLeft()
  680.                 end
  681.                 lower()    
  682.             elseif aState == 11 then
  683.                 while dir ~= direction.back do
  684.                     turnLeft()
  685.                 end
  686.                 lower()    
  687.             elseif aState == 12 then
  688.                 while dir ~= direction.forw do
  689.                     turnLeft()
  690.                 end
  691.                 lower()    
  692.             end
  693.             nextState()
  694.         elseif globalState == 3 or globalState == 4 or globalState == 5 or globalState == 6 then
  695.             returnSupplies()
  696.         end
  697.     end
  698.     saveState()
  699.     print( "Returning to surface..." )
  700.  
  701.     -- Return to where we started
  702.     goTo( 0,0,0,direction.back )
  703.     if mode == 1 then
  704.         unload()
  705.     else
  706.         returnToEnderChest()
  707.     end
  708.     goTo( 0,0,0,direction.forw )
  709.     delStartup()
  710. end
  711.  
  712. local function recover()
  713.     if not readState() or globalState == 0 then
  714.         print("Programm is not running")
  715.         print( "Usage: quarry <lenght> <width> [<height>]" )
  716.         return
  717.     end
  718.     if globalState == 1 then
  719.         local done = false
  720.         while tmpState ~= 1 do
  721.             ref()
  722.             if not down() then
  723.                 done = true
  724.                 break
  725.             end
  726.             tmpState=tmpState+1
  727.             saveState()
  728.         end
  729.         globalState = 2
  730.         saveState()
  731.     end
  732.     if globalState >= 2 then
  733. --      nextState()
  734.         main()
  735.     end
  736. end
  737.  
  738. local function start()
  739.     setStartup()
  740.     globalState = 1 -- Поехали копать
  741.     done = false
  742.  
  743.     while tmpState < 1 do
  744.         ref()
  745.         if not down() then
  746.             done = true
  747.             break
  748.         end
  749.         tmpState=tmpState+1
  750.         saveState()
  751.     end
  752.  
  753.     globalState = 2
  754.     saveState()
  755.     nextState()
  756.     main()
  757. end
  758.  
  759. function FuelInfo()
  760.     local fuelLevel = turtle.getFuelLevel()
  761.     local fuelNeed = 0
  762.     local minFuel = lenght*width
  763.     if fuelLevel ~= "unlimited" then
  764.         if height == 256 then
  765.             minFuel = minFuel*64
  766.         else
  767.             minFuel = minFuel*height
  768.         end
  769.         minFuel = math.ceil(minFuel/2)
  770.         fuelNeed = minFuel - turtle.getFuelLevel()
  771.         if fuelNeed < 0 then
  772.             fuelNeed = 0
  773.         end
  774.     end
  775.     print( "Fuel level: "..turtle.getFuelLevel())
  776.     print( "Need fuel: "..fuelNeed)
  777. end
  778.  
  779. local function GetFuel()
  780.     local fuelLevel = turtle.getFuelLevel()
  781.     if fuelLevel == "unlimited" then
  782.         return
  783.     end
  784.     local minFuel = lenght*width
  785.     if height == 256 then
  786.         minFuel = minFuel*64
  787.     else
  788.         minFuel = minFuel*height
  789.     end
  790.     minFuel = math.ceil(minFuel/2)
  791. --  print( "Waiting for fuel level: "..minFuel)
  792.     print( "Fuel level: "..math.ceil((turtle.getFuelLevel()*100)/minFuel).."%")
  793.     local waiting=true
  794.    
  795.     parallel.waitForAll(
  796.         function()
  797.             while waiting do
  798.                 for i = 1,16 do
  799.                     if turtle.getItemCount(i)>0 then
  800.                         turtle.select(i)
  801.                         if turtle.refuel() then
  802.                             print( "Fuel level: "..math.ceil((turtle.getFuelLevel()*100)/minFuel).."%")
  803.                         end
  804.                     end
  805.                 end
  806.                 os.sleep(0.5)
  807.             end
  808.         end
  809.         ,
  810.         function()
  811.             print("press any key to run quarry")
  812.             local input = read()
  813.             waiting = false
  814.             term.clear()
  815.             term.setCursorPos( 1, 1 )
  816.             turtle.select(1)
  817.             if mode == 2 and turtle.getItemCount(1) < 1 then
  818.                 print("Waiting for get chest to first slot")
  819.                 while turtle.getItemCount(1) < 1 do
  820.                     os.sleep(1)
  821.                 end
  822.             end
  823. --          print( "Fuel level: "..turtle.getFuelLevel())
  824.             print( "Excavating...")
  825.             start()
  826.             return
  827.         end
  828.     )
  829. end
  830.  
  831. local tArgs = { ... }
  832. if #tArgs == 0 then
  833.     print( "Recovering...")
  834.     recover()
  835.     return
  836. elseif #tArgs == 2 or #tArgs == 3 or #tArgs == 4 then
  837.     lenght = tonumber( tArgs[1] )
  838.     width  = tonumber( tArgs[2] )
  839.     height = 256
  840.     local arg = ""
  841.     if lenght < 1 or width < 1 or lenght > 255 or width > 255 then
  842.         print( "Quarry size must be positive" )
  843.         return
  844.     end
  845.     if #tArgs == 3 then
  846.         arg = tonumber( tArgs[3] )
  847.         if tArgs[3] == "-e" then
  848.             mode = 2
  849.         elseif tArgs[3] == "-f" then
  850.             FuelInfo()
  851.             return
  852.         elseif arg ~= nill then
  853.             height = arg
  854.             if height < 1 or height > 255 then
  855.                 print( "Quarry size must be positive" )
  856.                 return
  857.             end
  858.         else
  859.             print( "Usage: quarry <lenght> <width> [<height>] [<key>]; key: \"-e\", \"-f\"" )
  860.             return
  861.         end
  862.     elseif #tArgs == 4 then
  863.         arg = tonumber( tArgs[3] )
  864.         if arg ~= nill then
  865.             height = arg
  866.             if height < 1 or height > 255 then
  867.                 print( "Quarry size must be positive" )
  868.                 return
  869.             end
  870.         else
  871.             print( "Usage: quarry <lenght> <width> [<height>] [<key>]; key: \"-e\", \"-f\"" )
  872.             return
  873.         end
  874.         if tArgs[4] == "-e" then
  875.             mode = 2
  876.         elseif tArgs[4] == "-f" then
  877.             FuelInfo()
  878.             return
  879.         else
  880.             print( "Usage: quarry <lenght> <width> [<height>] [<key>]; key: \"-e\", \"-f\"" )
  881.             return
  882.         end
  883.     end
  884.     --starting
  885.     GetFuel()
  886.     return
  887. else
  888.     print( "Usage: quarry <lenght> <width> [<height>] [<key>]; key: \"-e\", \"-f\"" )
  889.     return
  890. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement