libraryaddict

Untitled

May 1st, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 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.         if ID == param1 and not OD then
  77.           OD = "yes"
  78.           Times = Times+1
  79.         elseif ID == param2 and not OS then
  80.           OS = "yes"
  81.           Times = Times+1
  82.         end
  83.         if Times == 2 then
  84.           rednet.send(ID, "Checked In")
  85.           rednet.send(ID1, "Checked In")
  86.           Times = 0
  87.           OS = false
  88.           OD = false
  89.           if turtle.forward() then
  90.             Mine()
  91.             Check = os.startTimer(0.1)
  92.           else
  93.             repeat
  94.               turtle.dig()
  95.               sleep(0.1)
  96.             until turtle.forward()
  97.             Mine()
  98.           end
  99.         end
  100.       elseif param2 == "Mine" then
  101.         Status = "Mining"
  102.         shell.run("clear")
  103.         print("Mining")
  104.         Mine()
  105.         Check = os.startTimer(0.1)
  106.       end
  107.     end
  108.   elseif event == "timer" and param1 == Check and Times < 2 and Status ~= "idle"  then
  109.     rednet.send(ID, "Checked In")
  110.     rednet.send(ID1, "Checked In")
  111.     Check = os.startTimer(0.1)
  112.   elseif event == "char" then
  113.     if param1 == "m" then
  114.       if Status == "idle" then
  115.         rednet.send(ID, "Mine")
  116.         rednet.send(ID1, "Mine")
  117.         Status = "Mining"
  118.         Mine()
  119.       else
  120.         Status = "idle"
  121.       end
  122.     elseif param1 == "b" and Status == "Stuck" then
  123.       turtle.forward()
  124.       turtle.forward()
  125.       shell.run("clear")
  126.       print("Mining")
  127.       Mine()
  128.     end
  129.   end
  130. end
Advertisement
Add Comment
Please, Sign In to add comment