Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 4.99 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. IDs = {124,125,126}
  2. Turtles = 2
  3. Roof = 3
  4.  
  5.  
  6. Height = 1
  7. rednet.open("right")
  8. shell.run("clear")
  9. print("Press M to mine")
  10. Roof = Roof-1
  11. function compare()
  12.   if turtle.getItemCount(9) ~= 0 then
  13.     shell.run("clear")
  14.     print("Need to empty slot number 9!")
  15.     repeat
  16.       sleep(1)
  17.     until turtle.getItemCount(9) == 0
  18.   end
  19.   for n=1,3 do
  20.     turtle.select(n)
  21.     if turtle.compare() then
  22.       turtle.select(1)
  23.       return true
  24.     end
  25.   end
  26.   turtle.select(9)
  27.   if turtle.compare() then
  28.     turtle.select(1)
  29.     return true
  30.   end
  31.   return false
  32. end
  33.    
  34. function Mine()
  35.   if Status ~= "Stuck" then
  36.     shell.run("clear")
  37.     print("Mining")
  38.     Times = 0
  39.     if Height == 1 then
  40.       Dir = "turtle.up()"
  41.     else
  42.       Dir = "turtle.down()"
  43.     end
  44.     for n=1,Roof do
  45.       if compare() then
  46.         turtle.dig()
  47.         repeat
  48.           if Height ~= 1 then
  49.             turtle.digDown()
  50.           end
  51.           if loadstring("return "..Dir)() then
  52.             Yes = true
  53.             if Dir == "turtle.up()" then
  54.               Height = Height+1
  55.             else
  56.               Height = Height-1
  57.               if Height > 1 then
  58.                 turtle.digDown()
  59.               end
  60.             end
  61.           end
  62.         until Yes
  63.         Yes = nil        
  64.       else
  65.         Status = "Stuck"
  66.         break
  67.       end
  68.     end
  69.     if Status ~= "Stuck" then
  70.       if compare() then
  71.         turtle.dig()
  72.       else
  73.         Status = "Stuck"
  74.       end
  75.       if Height == 1 then
  76.         turtle.select(4)
  77.         turtle.placeDown()
  78.         turtle.select(1)
  79.       end
  80.       Check = os.startTimer(0.1)
  81.     end
  82.   end
  83. end
  84. Moved = "no"
  85. function prepare()
  86.   if Moved == "no" then
  87.     shell.run("clear")
  88.     print("Waiting for you to press B so we can return to work")
  89.     Status = "Stuck"
  90.     while Height < Roof+1 do
  91.     turtle.up()
  92.     Height = Height+1
  93.     end
  94.     turtle.back()
  95.     turtle.back()
  96.     Check = os.startTimer(0)
  97.     Moved = "yes"
  98.   end
  99.   Prepare = os.startTimer(1)
  100. end
  101. Times = 0
  102. Status = "idle"
  103. Comps = {}
  104. Comp = {}
  105. function checkID(id)
  106.   for n=1,#IDs do
  107.     if IDs[n] == id then
  108.       return true
  109.     end
  110.   end
  111.   return false
  112. end
  113. while true do
  114.   event,param1,param2 = os.pullEvent()
  115.   if event == "rednet_message" then
  116.     if checkID(param1) then
  117.       if param2 == "Checked In" and Status == "Mining" then
  118.         if Comps[param1] == nil then
  119.           Comps[param1] = "Hello"
  120.           rednet.send(param1, "Checked")
  121.         end
  122.         rednet.send(param1, "Checked In")
  123.       elseif param2 == "Checked" and Status == "Mining" then
  124.         if Comp[param1] == nil then
  125.           Comp[param1] = "Hey"
  126.           Times = Times+1
  127.         end
  128.         if Times == Turtles then
  129.           rednet.send(ID, "Checked In")
  130.           rednet.send(ID1, "Checked In")
  131.           Times = 0
  132.           Comps = {}
  133.           Comp = {}
  134.           if Height == 1 then
  135.             turtle.select(4)
  136.             turtle.placeDown()
  137.             turtle.select(1)
  138.           end
  139.           if turtle.forward() then
  140.             Mine()
  141.             Check = os.startTimer(0.1)
  142.           else
  143.             repeat
  144.               if Height == 1 then
  145.                 turtle.select(4)
  146.                 turtle.placeDown()
  147.                 turtle.select(1)
  148.               end
  149.               turtle.dig()
  150.               sleep(0.1)
  151.             until turtle.forward()
  152.             Mine()
  153.           end
  154.         end
  155.       elseif param2 == "Mine" then
  156.         Status = "Mining"
  157.         shell.run("clear")
  158.         print("Mining")
  159.         Mine()
  160.         Check = os.startTimer(0.1)
  161.       elseif param2 == "Resume" then
  162.         turtle.forward()
  163.         turtle.forward()
  164.         Status = "Mining"
  165.         shell.run("clear")
  166.         print("Mining")
  167.         Mine()
  168.         Check = os.startTimer(0.1)
  169.         Moved = "no"
  170.       elseif param2 == "Prepare" and Status ~= "Stuck" then
  171.         prepare()
  172.       end
  173.     end
  174.   elseif event == "timer" and param1 == Check and Times < Turtles and Status == "Mining"  then
  175.     rednet.send(ID, "Checked In")
  176.     rednet.send(ID1, "Checked In")
  177.     Check = os.startTimer(0.1)
  178.   elseif event == "timer" and param1 == Check and Status == "Stuck" then
  179.     rednet.send(ID, "Prepare")
  180.     rednet.send(ID1, "Prepare")
  181.     prepare()
  182.     Prepare = os.startTimer(1)
  183.   elseif event == "timer" and param1 == Prepare then
  184.     rednet.send(ID, "Prepare")
  185.     rednet.send(ID1, "Prepare")
  186.     Prepare = os.startTimer(1)
  187.   elseif event == "char" then
  188.     if param1 == "m" then
  189.       if Status == "idle" then
  190.         rednet.send(ID, "Mine")
  191.         rednet.send(ID1, "Mine")
  192.         Status = "Mining"
  193.         Mine()
  194.       else
  195.         Status = "idle"
  196.       end
  197.     elseif param1 == "b" and Status == "Stuck" then
  198.       turtle.forward()
  199.       turtle.forward()
  200.       rednet.send(ID, "Resume")
  201.       rednet.send(ID1, "Resume")
  202.       Status = "Mining"
  203.       shell.run("clear")
  204.       Moved = "no"
  205.       print("Mining")
  206.       Mine()
  207.     end
  208.   end
  209. end