megadeth9001

WIP SetnForget turtle

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