libraryaddict

Untitled

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