libraryaddict

Untitled

May 1st, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. ID = 1
  2. ID1 = 1
  3.  
  4.  
  5. Height = 1
  6. rednet.open("right")
  7. shell.run("clear")
  8. print("Press M to mine")
  9. function compare()
  10.   if turtle.getItemCount(9) ~= 0 then
  11.     shell.run("clear")
  12.     print("Need to empty slot number 9!")
  13.     repeat
  14.       sleep(1)
  15.     until turtle.getItemCount(9) == 0
  16.   end
  17.   for n=1,3 do
  18.     turtle.select(n)
  19.     if turtle.compare() then
  20.       return true
  21.     end
  22.   end
  23.   turtle.select(9)
  24.   if turtle.compare() then
  25.     return true
  26.   end
  27.   return false
  28. end
  29.    
  30. function Mine()
  31.   shell.run("clear")
  32.   print("Mining")
  33.   Times = 0
  34.   if Height == 1 then
  35.     Dir = "turtle.up()"
  36.   else
  37.     Dir = "turtle.down()"
  38.   end
  39.   for n=1,2 do
  40.     if compare() then
  41.       turtle.dig()
  42.       loadstring(Dir)()
  43.       if Dir == "turtle.up()" then
  44.         Height = Height+1
  45.       else
  46.         Height = Height-1
  47.       end
  48.     else
  49.       prepare()
  50.     end
  51.   end
  52.   if compare() then
  53.     turtle.dig()
  54.   else
  55.     prepare()
  56.   end
  57.   Check = os.startTimer(0.1)
  58. end
  59. function prepare()
  60.   shell.run("clear")
  61.   print("Waiting for you to press B so we can return to work")
  62.   Status = "Stuck"
  63.   while Height < 3 do
  64.   turtle.up()
  65.   Height = Height+1
  66.   end
  67.   turtle.back()
  68.   turtle.back()
  69. end
  70. Times = 0
  71. Status = "idle"
  72. while true do
  73.   event,param1,param2 = os.pullEvent()
  74.   if event == "rednet_message" then
  75.     if param1 == ID1 or param1 == ID then
  76.       if param2 == "Checked In" then
  77.         if ID == param1 and not OD then
  78.           OD = "yes"
  79.           Times = Times+1
  80.         elseif ID1 == param2 and not OS then
  81.           OS = "yes"
  82.           Times = Times+1
  83.         end
  84.         if Times == 2 then
  85.           rednet.send(ID, "Checked In")
  86.           rednet.send(ID1, "Checked In")
  87.           Times = 0
  88.           OS = false
  89.           OD = false
  90.           if turtle.forward() then
  91.             Mine()
  92.             Check = os.startTimer(0.1)
  93.           else
  94.             repeat
  95.               turtle.dig()
  96.               sleep(0.1)
  97.             until turtle.forward()
  98.             Mine()
  99.           end
  100.         end
  101.       elseif param2 == "Mine" then
  102.         Status = "Mining"
  103.         shell.run("clear")
  104.         print("Mining")
  105.         Mine()
  106.         Check = os.startTimer(0.1)
  107.       end
  108.     end
  109.   elseif event == "timer" and param1 == Check and Times < 2 and Status ~= "idle"  then
  110.     rednet.send(ID, "Checked In")
  111.     rednet.send(ID1, "Checked In")
  112.     Check = os.startTimer(0.1)
  113.   elseif event == "char" then
  114.     if param1 == "m" then
  115.       if Status == "idle" then
  116.         rednet.send(ID, "Mine")
  117.         rednet.send(ID1, "Mine")
  118.         Status = "Mining"
  119.         Mine()
  120.       else
  121.         Status = "idle"
  122.       end
  123.     elseif param1 == "b" and Status == "Stuck" then
  124.       turtle.forward()
  125.       turtle.forward()
  126.       shell.run("clear")
  127.       print("Mining")
  128.       Mine()
  129.     end
  130.   end
  131. end
Advertisement
Add Comment
Please, Sign In to add comment