megadeth9001

Soon to be Smart trutle [WIP]

Dec 10th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.93 KB | None | 0 0
  1. local fcount = 0  
  2. local mcount = 0  
  3. local lcount = 0    
  4. local SRcount = 0
  5. local SLcount = 0
  6. local SFcount = 0
  7. local fuellevel = turtle.getFuelLevel()
  8. local procends = 0
  9.  
  10. function getcoal() ---Refueling funciton--
  11. turtle.select(1)
  12. fuellevel = turtle.getFuelLevel()
  13. Local I2count = turtle.getItemCount()
  14.     if fuellevel < 1000 then   
  15.         I3count = 64 - I2count
  16.         turtle.suckUp( I3count )
  17. turtle.refuel( 1,5 )
  18. end
  19.  
  20. function ymine1()
  21.     turtle.turnLeft()
  22.     turtle.dig()
  23.     turtle.digUp()
  24.     turtle.digDown()
  25.     turtle.forward()
  26.     turtle.dig
  27.     turtle.digUp()
  28.     turtle.digDown()
  29.     turtle.forward()
  30. end
  31.  
  32. function Ymine()
  33.     turtle.dig()
  34.     turtle.forward()
  35.     turtle.turnLeft()
  36.     turtle.dig()
  37.     turtle.forward()
  38.     ymine1()
  39.     ymine1()
  40.     turtle.turnLeft()
  41.     turtle.dig()
  42.     turtle.forward()
  43.     turtle.turnRight()
  44. end
  45.  
  46.  
  47. function Downmine()
  48. Dcount = Dcount + 1
  49. turtle.select(16)
  50. local Icount = turtle.getItemCount()
  51.     if Icount == 0 then
  52.         turtle.select(16)
  53.         Icount = turtle.getItemCount()
  54.         turtle.select(1)
  55.         turtle.Down()
  56.         tutle.digDown()
  57.         turtle.Down()
  58.         tutle.digDown()
  59.         turtle.Down()
  60.         tutle.digDown()
  61.         Ymine()
  62.     end
  63. end
  64.  
  65. function Inventory() ---Tier 1 Mining Function---
  66. turtle.select(16)
  67.         local Icount = turtle.getItemCount()
  68.             if Icount == 0 then
  69.                 turtle.select(16)
  70.                 Icount = turtle.getItemCount()
  71.                 turtle.select(1)
  72.                 fcount = fcount + 1
  73.                 turtle.turnLeft()
  74.                 Dig()
  75.                 turtle.back()
  76.                 turtle.turnRight()
  77.                 turtle.turnRight()
  78.                 Dig()
  79.                 turtle.back()
  80.                 turtle.turnLeft()
  81.                 turtle.digUp()
  82.                 turtle.digDown()
  83.                 turtle.dig()
  84.                 turtle.forward()
  85.             end
  86. end
  87.  
  88. function home()
  89.     repeat
  90.                 turtle.back()
  91.                 fcount = fcount - 1
  92.                 until fcount == 0
  93. end    
  94.  
  95. function Dropoff()
  96.     for I= 2, 16, 1 do
  97.         turtle.select(I)
  98.         turtle.dropDown()
  99.     end
  100. end    
  101.  
  102. function fuel()
  103.     local fuellevel = turtle.getFuelLevel()
  104.         if fuellevel < fcount + 5 then
  105.             turtle.select(1)
  106.             turtle.refuel( 1, 10 )
  107.         end
  108.         if fuellevel < fcount + 10 then
  109.             local procends = 1
  110.             repeat
  111.                 turtle.back()
  112.                 fcount = fcount - 1
  113.                 until fcount == 0
  114.             Dropoff()
  115.         end
  116. end
  117.  
  118.  
  119. function Dig()
  120.     if turtle.detect() then
  121.         repeat
  122.         turtle.dig()
  123.         local gravel = turtle.detect()
  124.             until gravel == false
  125.         end
  126.         turtle.forward()
  127.             if turtle.detectUp() then
  128.                 turtle.digUp()
  129.                 if turtle.detectDown() then
  130.                     turtle.digDown()
  131.                 end
  132.             end
  133.         end
  134.    
  135.  
  136. function miningJobF()
  137.     while Icount == 0 and procends == 0 do
  138.         Inventory()
  139.         SFcount = SFcount +1
  140.         fuel()  
  141.     end
  142. home()    
  143. end
  144.  
  145. function miningJobR()
  146.     while Icount == 0 and procends == 0 do
  147.         Inventory()
  148.         fuel()  
  149.     end
  150. home()
  151. SRcount = SRcount + 3    
  152. end
  153.  
  154. function miningJobL()
  155.     while Icount == 0 and procends == 0 do
  156.         Inventory()
  157.         fuel()  
  158.     end
  159. home()
  160. SLcount = SLcount +3  
  161. end
  162.  
  163. function movement()
  164.     repeat
  165.         if turtle.detect() == false then
  166.             turtle.forward()
  167.             fcount = fcount + 1
  168.         end
  169.     until turtle.detect() == true
  170.    
  171. end
  172.  
  173. function NewtunnelFOW()
  174.     TSF = SFcount
  175.     repeat
  176.         turtle.dig()
  177.         turtle.forward()
  178.         TSF = TSF - 1
  179.     until TSF == SFcount or TSF < 0 or turtle.detect() == true
  180.    
  181. end
  182.  
  183. function NewtunnelLEF()
  184.     TSL = SLcount
  185.     repeat
  186.         turtle.forward()
  187.         lcount = lcount + 1
  188.         TSL = TSL - 1
  189.     until TSL == SLcount or TSL < 0  or turtle.detect() == true
  190.         turtle.turnLeft()
  191.        movement()
  192. end
  193.  
  194. function NewtunnelRIG()
  195.     TSR = SRcount
  196.     repeat
  197.         turtle.forward()
  198.         lcount = lcount + 1
  199.         TSR = TSR - 1
  200.     until TSR == SRcount or TSR < 0  or turtle.detect() == true  
  201.         turtle.turnRight()
  202.     movement()
  203. end
  204.  
  205. function Straight()
  206.     getcoal()
  207.     procends = 0
  208.     Icount = 0
  209.     NewtunnelFOW()
  210.     miningJobF()
  211. end
  212.  
  213. function Lefttime()
  214.     getcoal()
  215.     procends = 0
  216.     Icount = 0
  217.     NewtunnelLEF()
  218.     miningJobL()
  219. end
  220.  
  221. function Righttime()
  222.     getcoal()  
  223.     procends = 0
  224.     Icount = 0
  225.     NewtunnelRIG()
  226.     miningJobR()
  227. end
  228.  
  229. function logicish()
  230.     if SFcount == 0 then
  231.         Straight()
  232.     end
  233.     if SRcount == SFcount then
  234.         if SFcount == SLcount then
  235.             local function RN()
  236.                 local rand = math.random(1,3)
  237.                 return rand
  238.             end
  239.             local num = RN()
  240.         end
  241.     end
  242.     if num == 1 then
  243.         Stright()
  244.     end
  245.     if num == 2 then
  246.         Righttime()
  247.     end
  248.     if num == 3 then
  249.         Lefttime()
  250.     end
  251.     if SFcount < SRcount and SFcount < SLcount then
  252.         Stright()
  253.     end
  254.     if SRcount < SFcount and SRcount < SLcount then
  255.         Righttime()
  256.     end
  257.     if SLcount < SFcount and SLcount < SRcount then
  258.         Lefttime()
  259.     end
  260.     if SLcount == SRcount and SLcount < SFcount then
  261.         local  function RN()
  262.             local rand = math.random(1,2)
  263.             return rand
  264.         end
  265.         local num = RN()
  266.     end
  267.     if num == 1 then
  268.         Lefttime()
  269.     end
  270.     if num == 2 then
  271.         Righttime()
  272.     end
  273.     if SFcount == SRcount and SRcount < SFcount then
  274.         local  function RN()
  275.             local rand = math.random(1,2)
  276.             return rand
  277.         end
  278.         local num = RN()
  279.     end
  280.     if num == 1 then
  281.         Stright()
  282.     end
  283.     if num == 2 then
  284.         Righttime()
  285.     end
  286.     if SFcount == SLcount and SLcount < SRcount then
  287.         local  function RN()
  288.             local rand = math.random(1,2)
  289.             return rand
  290.         end
  291.         local num = RN()
  292.     end
  293.     if num == 1 then
  294.         Lefttime()
  295.     end
  296.     if num == 2 then
  297.         Stright()
  298.     end
  299. end
  300.  
  301. local X = 1
  302.  
  303. while X == 1 do
  304.     logicish()
  305. end
Advertisement
Add Comment
Please, Sign In to add comment