libraryaddict

Untitled

May 1st, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 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("Now 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. end
  58. function prepare()
  59.   shell.run("clear")
  60.   print("Waiting for you to press B so we can return to work")
  61.   Status = "Stuck"
  62.   while Height < 3 do
  63.   turtle.up()
  64.   Height = Height+1
  65.   end
  66.   turtle.back()
  67.   turtle.back()
  68. end
  69. Times = 0
  70. Status = "idle"
  71. while true do
  72.   event,param1,param2 = os.pullEvent()
  73.   if event == "rednet_message" then
  74.     if param1 == ID1 or param1 == ID then
  75.       if param2 == "Checked In" then
  76.         Times = Times+1
  77.         if Times == 2 then
  78.           rednet.send(ID, "Checked In")
  79.           rednet.send(ID1, "Checked In")
  80.           Times = 0
  81.           if turtle.forward() then
  82.             Mine()
  83.           else
  84.             repeat
  85.               turtle.dig()
  86.               sleep(0.1)
  87.             until turtle.forward()
  88.             Mine()
  89.           end
  90.         end
  91.       elseif param2 == "Mine" then
  92.         Status = "Mining"
  93.         shell.run("clear")
  94.         print("Now mining")
  95.         Mine()
  96.         Check = os.startTimer(0.1)
  97.       end
  98.     end
  99.   elseif event == "timer" and param1 == Check and Times < 2 then
  100.     rednet.send(ID, "Checked In")
  101.     rednet.send(ID1, "Checked In")
  102.     Check = os.startTimer(0.1)
  103.   elseif event == "char" then
  104.     if param1 == "m" then
  105.       rednet.send(ID, "Mine")
  106.       rednet.send(ID1, "Mine")
  107.       Status = "Mining"
  108.       Mine()
  109.     elseif param1 == "b" and Status == "Stuck" then
  110.       turtle.forward()
  111.       turtle.forward()
  112.       shell.run("clear")
  113.       print("Now mining")
  114.       Mine()
  115.     end
  116.   end
  117. end
Advertisement
Add Comment
Please, Sign In to add comment