zed_com

Карьер CC

Apr 1st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.00 KB | None | 0 0
  1. -- Variable section --
  2.  
  3. A1 = 1
  4.  
  5. A2 = 1
  6. LineNum = 1
  7.  
  8. completed = 0
  9.  
  10. xcor = 0
  11.  
  12. zcor = 0
  13.  
  14. ycor = 1
  15.  
  16. zd = 0
  17.  
  18. yd = 0
  19.  
  20. xd = 0
  21.  
  22. r = 0
  23.  
  24. -- GUI --
  25.  
  26. term.clear()
  27.  
  28. term.setCursorPos(1,1)
  29.  
  30. print("Welcome to Digging programm!")
  31.  
  32. sleep(0.5)
  33.  
  34. write("X size(Forward): ")
  35. xs = read()
  36.  
  37. xs = xs + 0
  38. write("Z size(Right): ")
  39.  
  40. zs = read()
  41.  
  42. zs = zs + 0
  43.  
  44. write("Y size(Up/Down): ")
  45.  
  46. ys = read()
  47.  
  48. ys = ys + 0
  49.  
  50. print("Drop items in chest?")
  51.  
  52. while A1 == 1 do
  53.  
  54. if LineNum == 1 then
  55.  
  56. term.clearLine(6)
  57.  
  58. term.setCursorPos(1,6)
  59.  
  60. print("[Yes]   No ")
  61.  
  62. elseif LineNum == 2 then
  63.  
  64. term.clearLine(6)
  65.  
  66. term.setCursorPos(1,6)
  67.  
  68. print(" Yes   [No]")
  69.  
  70. end
  71.  
  72. name,data = os.pullEvent()
  73.  
  74. if name == "key" then
  75.  
  76. if data == 28 then
  77.  
  78. if LineNum == 1 then
  79.  
  80. Chest = 1
  81.  
  82. A1 = 0
  83.  
  84. elseif LineNum == 2 then
  85.  
  86. Chest = 0
  87.  
  88. A1 = 0
  89.  
  90. end
  91.  
  92. end
  93. if data == 205 or data == 200 then
  94.  
  95. LineNum = LineNum + 1
  96.  
  97. elseif data == 203 or data == 208 then
  98.  
  99. LineNum = LineNum - 1
  100. end
  101.  
  102. end
  103.  
  104. if name == "mouse_scroll" then
  105.    
  106. if data == 1 then
  107.      
  108. LineNum = LineNum + 1
  109.    
  110. elseif data == - 1 then
  111.      
  112. LineNum = LineNum - 1  
  113.    
  114. end  
  115.  
  116. end
  117.  
  118. if LineNum == 3 then
  119.    
  120. LineNum = 1
  121.  
  122. end
  123.  
  124.  if LineNum == 0 then  
  125.    
  126. LineNum = 2
  127.  
  128. end
  129.  
  130. end
  131.  
  132. LineNum = 1
  133.  
  134. while A2 == 1 do
  135.  
  136. if LineNum == 1 then
  137.    
  138. term.clearLine(7)
  139.    
  140. term.setCursorPos(1,7)
  141.    
  142. print("[Dig Up]   Dig Down ")
  143.  
  144. elseif LineNum == 2 then
  145.    
  146. term.clearLine(7)
  147.    
  148. term.setCursorPos(1,7)
  149.    
  150. print(" Dig Up   [Dig Down]")
  151.  
  152. end
  153.  
  154. name,data = os.pullEvent()
  155.  
  156.  if name == "key" then
  157.    
  158.  if data == 205 or data == 200 then
  159.      
  160. LineNum = LineNum + 1    
  161.    
  162. elseif data == 203 or data == 208 then
  163.      
  164. LineNum = LineNum - 1
  165.    
  166. end
  167.    
  168. if data == 28 then
  169.      
  170. if LineNum == 1 then
  171.        
  172. Dir = "up"
  173.        
  174. A2 = 0
  175.      
  176. elseif LineNum == 2 then
  177.        
  178. Dir = "down"
  179.        
  180.  A2 = 0
  181.      
  182. end
  183.    
  184. end
  185.  
  186. end
  187.  
  188. if name == "mouse_scroll" then
  189.    
  190. if data == 1 then
  191.      
  192. LineNum = LineNum + 1
  193.    
  194. elseif data == -1 then
  195.      
  196. LineNum = LineNum - 1
  197.    
  198. end
  199.  
  200. end
  201.  
  202. if LineNum == 3 then
  203.    
  204. LineNum = 1
  205.  
  206. elseif LineNum == 0 then
  207.    
  208. LineNum = 2
  209.  
  210. end  
  211.  
  212. end
  213.  
  214. LineNum = 1
  215.  
  216. term.clear()
  217.  
  218. term.setCursorPos(1,1)
  219.  
  220. reqfuel = xs*zs*ys
  221.  
  222. print("Minimum fuel required: ",reqfuel)
  223.  
  224. turtle.select(1)
  225.  
  226. turtle.refuel(10)
  227.  
  228. fuel = turtle.getFuelLevel()
  229.  
  230. print("Fuel : ",fuel)
  231.  
  232. A3 = 0
  233.  
  234. if reqfuel > 100000 then
  235.  
  236. print("Sorry but selected size is")
  237.  
  238. print("too large :)")
  239.  
  240. sleep(2,5)
  241.  
  242. print("rebooting...")
  243.  
  244. sleep(1.5)
  245.  
  246. os.reboot()
  247.  
  248. end
  249.  
  250. if fuel < reqfuel then
  251.  
  252.  A3 = 1
  253.  
  254. end
  255.  
  256. while A3 == 1 do
  257.  
  258. term.clearLine(2)
  259.  
  260. term.setCursorPos(1,2)
  261.  
  262. print("Fuel: [",fuel,"/",reqfuel,"]")
  263.  
  264. print("Place fuel in slot 1")
  265.  
  266. turtle.select(1)
  267.  
  268. turtle.refuel(10)
  269.  
  270. fuel = turtle.getFuelLevel()
  271.  
  272. if fuel >= reqfuel then
  273.    
  274. term.clearLine(3)
  275.    
  276. term.setCursorPos(1,3)
  277.    
  278. A3 = 0
  279.  
  280. end
  281.  
  282. end
  283.  
  284. term.clearLine(2)
  285.  
  286. term.clearLine(3)
  287.  
  288. term.setCursorPos(1,3)
  289.  
  290. print("X size : ",xs)
  291.  
  292. print("Y size : ",ys)
  293.  
  294. print("Z size : ",zs)
  295.  
  296. write("Use chest : ")
  297.  
  298. if Chest ==  1 then
  299.  
  300. print("Yes"
  301. )
  302. elseif Chest == 0  
  303. then
  304.   print("No")
  305.  
  306. end
  307. print("Mining direction : ",Dir)
  308.  
  309. print("To start press any botton...")
  310.  
  311. print("To reboot press Ctrl...")
  312.  
  313. name,data = os.pullEvent("key")
  314.  
  315. if name == "key" and data == 29 then
  316.  
  317. os.reboot()
  318.  
  319. end
  320.  
  321. size = xs * zs * ys
  322.  
  323. local function monitor()
  324.  
  325. term.clear()
  326.  
  327. term.setCursorPos(1,1)
  328.  
  329. rfuel = turtle.getFuelLevel()
  330.  
  331. print("Fuel : ",rfuel)
  332.  
  333. print("Position : "," X: ",xcor," Y: ",ycor," Z: ",zcor)
  334.  
  335. end
  336.  
  337.  
  338. -- Mining section --
  339.  
  340. zcor = 1
  341.  
  342. completed = 0
  343.  
  344. finish = 0
  345.  
  346. A9 = 0
  347.  
  348. bd = 0
  349.  
  350. while finish == 0 do
  351.  
  352. monitor()
  353.  
  354. if Chest == 1 and turtle.getItemCount(16) > 0 then
  355.  
  356. A9 = 1
  357. xlcor = xcor
  358.  
  359. zlcor = zcor
  360.  
  361. ylcor = ycor
  362. if r == 0 then
  363.      
  364. while xcor > 1 do
  365.        
  366. if turtle.back() then
  367.          
  368. xcor = xcor - 1
  369.        
  370. end
  371.      
  372. end
  373.      
  374. turtle.turnLeft()
  375.      
  376. while zcor > 1 do        
  377.        
  378. if turtle.forward() then
  379.          
  380. zcor = zcor - 1
  381.        
  382. end
  383.      
  384. end
  385.      
  386. while ycor > 1 do
  387.        
  388. if Dir == "up" then
  389.          
  390. if turtle.down() then
  391.            
  392. ycor = ycor - 1
  393.          
  394. end
  395.        
  396. elseif Dir == "down" then
  397.          
  398. if turtle.up() then
  399.            
  400. ycor = ycor - 1
  401.          
  402. end
  403.        
  404. end
  405.      
  406. end
  407.      
  408. turtle.turnRight()
  409.    
  410. end
  411.     if r == 1 then
  412.      
  413. turtle.turnRight()
  414.      
  415. while zcor > 1 do
  416.        
  417. if turtle.forward() then
  418.          
  419. zcor = zcor - 1
  420.        
  421. end
  422.      
  423. end
  424.      
  425. turtle.turnLeft()
  426.      
  427. while xcor > 1 do
  428.        
  429. if  turtle.forward() then
  430.          
  431. xcor = xcor - 1
  432.        
  433. end
  434.      
  435. end
  436.      
  437. turtle.turnRight()
  438.      
  439. turtle.turnRight()
  440.      
  441. while ycor > 1 do
  442.        
  443. if Dir == "up" then
  444.          
  445. if turtle.down() then
  446.            
  447. ycor = ycor - 1
  448.          
  449. end
  450.        
  451. elseif Dir == "down" then
  452.          
  453. if turtle.up() then
  454.            
  455. ycor = ycor - 1
  456.          
  457. end
  458.        
  459. end
  460.      
  461. end
  462.    
  463. end
  464.    
  465. turtle.back()
  466.    
  467. slotNum = 16
  468.    
  469. turtle.select(16)
  470.    
  471. turtle.dropUp()
  472.    
  473. while slotNum > 1 do
  474.      
  475. slotNum = slotNum - 1
  476.      
  477. turtle.select(slotNum)
  478.      
  479. turtle.dropUp()
  480.    
  481. end
  482.    
  483. turtle.forward()
  484.    
  485. while xcor < xlcor do
  486.      
  487.  turtle.dig()
  488.      
  489. if turtle.forward() then
  490.        
  491.  xcor = xcor + 1
  492.      
  493. end
  494.    
  495. end
  496.    
  497. turtle.turnRight()
  498.    
  499. while zcor < zlcor do
  500.      
  501. turtle.dig()
  502.        
  503. if turtle.forward() then
  504.        
  505. zcor = zcor + 1
  506.      
  507. end
  508.    
  509. end
  510.    
  511. if r == 0 then
  512.      
  513. turtle.turnLeft()
  514.    
  515. elseif r == 1 then
  516.      
  517. turtle.turnRight()
  518.    
  519. end
  520.    
  521. while ycor < ylcor do
  522.      
  523. if Dir == "up" then
  524.        
  525. if turtle.up() then
  526.          
  527. ycor = ycor + 1
  528.        
  529. end
  530.      
  531. elseif Dir == "down" then
  532.        
  533. if turtle.down() then
  534.          
  535. ycor = ycor + 1
  536.        
  537. end
  538.      
  539. end
  540.    
  541. end
  542.  
  543. end
  544.  
  545. turtle.dig()
  546.  
  547. if ys - yd > 1 and xcor > 0 then
  548.    
  549. if  Dir == "up" then
  550.      
  551. turtle.digUp()
  552.    
  553. elseif Dir == "down" then
  554.      
  555. turtle.digDown()
  556.    
  557. end
  558.  
  559. end
  560.  
  561. monitor()
  562.  
  563. if finish == 0 and turtle.forward() then
  564.    
  565. monitor()
  566.    
  567. xd = xd + 1
  568.    
  569. if r == 0 then  
  570.      
  571. xcor = xcor + 1
  572.    
  573. elseif r == 1 then
  574.      
  575. xcor = xcor - 1
  576.    
  577. end
  578.  
  579. end
  580.  
  581. if zd + 1 == zs and xd == xs then
  582.    
  583. completed = 1
  584.  
  585. end
  586.  
  587. if completed == 1 then
  588.    
  589. if r == 0 then
  590.      
  591. turtle.turnLeft()
  592.      
  593. if ys - yd > 1 then
  594.        
  595. if Dir == "up" then
  596.          
  597. turtle.digUp()
  598.        
  599. elseif Dir == "down" then
  600.          
  601. turtle.digDown()
  602.        
  603. end
  604.      
  605. end
  606.      
  607. monitor()
  608.      
  609. while zcor > 1 do
  610.        
  611. turtle.dig()
  612.        
  613. if turtle.forward() then
  614.          
  615. zcor = zcor - 1
  616.        
  617. end
  618.      
  619. end
  620.      
  621. turtle.turnLeft()
  622.      
  623. while xcor > 1 do
  624.        
  625. turtle.dig()
  626.        
  627. if turtle.forward() then
  628.          
  629. xcor = xcor - 1
  630.        
  631. end
  632.      
  633. end
  634.      
  635. turtle.turnLeft()
  636.      
  637. turtle.turnLeft()
  638.    
  639. end    
  640.    
  641. if r == 1 then
  642.      
  643. r = 0
  644.      
  645. if ys - yd > 1 then
  646.        
  647. if  Dir == "up" then
  648.          
  649. turtle.digUp()
  650.        
  651. elseif Dir == "down" then
  652.          
  653. turtle.digDown()
  654.        
  655. end
  656.      
  657. end
  658.      
  659.  turtle.turnRight()
  660.      
  661. while zcor > 1 do
  662.        
  663. if turtle.forward() then
  664.          
  665. zcor = zcor - 1
  666.        
  667. end
  668.      
  669. end
  670.      
  671. turtle.turnRight()
  672.    
  673. end      
  674.    
  675. if ys - yd > 1 then
  676.      
  677. yd = yd + 2
  678.    
  679. elseif ys - yd == 1 then
  680.      
  681. yd = yd + 1
  682.    
  683. end
  684.  
  685. end
  686.  
  687. monitor()
  688.  
  689. if completed == 1 and yd < ys then
  690.    
  691. xd = 1
  692.    
  693. zd = 0
  694.    
  695. zcor = 1
  696.    
  697. xcor = 1
  698.    
  699. completed = 0
  700.    
  701. ycor = ycor + 2
  702.    
  703. A8 = 1
  704.    
  705. if Dir == "up" then
  706.      
  707. while A8 == 1 do
  708.        
  709. turtle.digUp()
  710.        
  711. if turtle.up() then
  712.          
  713. A8 = 0
  714.        
  715. end
  716.      
  717. end
  718.      
  719. A8 = 1
  720.      
  721. while A8 == 1 do
  722.        
  723. turtle.digUp()
  724.        
  725. if turtle.up() then
  726.          
  727. A8 = 0
  728.        
  729. end
  730.      
  731. end
  732.    
  733. elseif Dir == "down" then
  734.      
  735. while A8 == 1 do
  736.        
  737. turtle.digDown()
  738.        
  739. if turtle.down() then
  740.          
  741. A8 = 0
  742.        
  743. end
  744.      
  745. end
  746.      
  747. A8 = 1
  748.      
  749. while A8 == 1 do
  750.        
  751. turtle.digDown()
  752.        
  753. if turtle.down() then
  754.          
  755. A8 = 0
  756.        
  757. end
  758.      
  759. end
  760.    
  761. end
  762.  
  763. end
  764.  
  765. monitor()
  766.  
  767. if completed == 1 and yd == ys then
  768.    
  769. print("completed!")
  770.    
  771. while ycor > 1 do
  772.      
  773. if Dir == "up" then
  774.        
  775. turtle.digUp()
  776.        
  777. if turtle.down() then
  778.          
  779. ycor = ycor - 1
  780.        
  781. end
  782.      
  783. elseif Dir == "down" then
  784.        
  785. turtle.digDown()
  786.        
  787.  if turtle.up() then
  788.          
  789. ycor = ycor - 1
  790.        
  791. end
  792.      
  793. end
  794.    
  795. end
  796.    
  797. finish = 1
  798.  
  799. end
  800.  
  801. if completed == 0 and xd == xs and r == 0 and zd<zs then
  802.    
  803. if ys - yd > 1 then
  804.      
  805. if Dir == "down" then
  806.        
  807. turtle.digDown()
  808.      
  809. elseif Dir == "up" then
  810.        
  811. turtle.digUp()
  812.      
  813. end
  814.    
  815. end
  816.    
  817. A4 = 1
  818.    
  819. xd = 1
  820.    
  821. r = 1
  822.    
  823. zd = zd + 1
  824.    
  825. zcor = zcor + 1
  826.    
  827. turtle.turnRight()
  828.    
  829. while A4 == 1 do
  830.      
  831. turtle.dig()
  832.      
  833. if turtle.forward() then
  834.        
  835. A4 = 0
  836.      
  837. end
  838.    
  839. end
  840.    
  841. turtle.turnRight()
  842.  
  843. end
  844.  
  845. if completed == 0 and xd == xs and r == 1 and zd < zs then
  846.    
  847. if ys - yd > 1 then  
  848.      
  849. if Dir == "up" then
  850.        
  851. turtle.digUp()
  852.      
  853. elseif  Dir == "down" then
  854.        
  855. turtle.digDown()
  856.      
  857. end
  858.    
  859. end
  860.    
  861. A5 = 1
  862.    
  863. xd = 1
  864.    
  865. r = 0
  866.    
  867. zd = zd + 1
  868.    
  869. zcor = zcor + 1
  870.    
  871. turtle.turnLeft()
  872.    
  873. while A5 == 1 do
  874.      
  875. turtle.dig()
  876.      
  877. if turtle.forward() then
  878.        
  879. A5 = 0
  880.      
  881. end
  882.    
  883. end
  884.    
  885. turtle.turnLeft()
  886.  
  887. end
  888.  
  889. monitor()
  890.  
  891. end
  892.  
  893. monitor()
  894.  
  895. print("Completed!")
Add Comment
Please, Sign In to add comment