geech6

Tunnel

Dec 31st, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. local tArgs = {...}
  2. local numMove = tArgs[1] --
  3. local numRow = tArgs[2] --not implemented function. ignore if not causing problems, comment out if causing problems
  4. print("Moving: "..tArgs[1].." Blocks Forward")
  5.  
  6. --Check fuel level and refuel
  7. function fuel()
  8.    turtle.select( 1 )
  9.    while turtle.getFuelLevel() < 10 do
  10.       if(turtle.refuel(1)) then
  11.          print("Refueled...")
  12.       else
  13.          print("Could not refuel...")
  14.          print("Operation Terminated...")
  15.          exit()
  16.       end
  17.    end
  18. end
  19.  
  20. --Drop when inventory full
  21. function drop()
  22.    if turtle.getItemCount(2) > 1 then
  23.       shell.run("goto", tostring(x), tostring(y), tostring(z))
  24.       for i=2,16 do
  25.          turtle.select(i)
  26.          turtle.drop(64)
  27.          print("Dropping")
  28.       end
  29.    else
  30.       sleep(0.1)
  31.       print("Nothing To Drop")
  32.    end
  33. end
  34.  
  35. --Check for gravel
  36. function gCheck()
  37.    if turtle.detect() then
  38.       turtle.dig()
  39.       sleep(0.5)
  40.    end
  41. end
  42.  
  43. --move forward and dig a 2 tall tunnel
  44. function frwd()
  45.    turtle.dig()
  46.    turtle.forward()
  47.    turtle.digUp()
  48. end
  49.  
  50. --check for lava and move away from it
  51. --I've lost many a turtle without this function
  52. function lava()
  53.    while turtle.detectUp(10) do
  54.       if frwd() then
  55.          print("Detecting Magma like substance...")
  56.          print("Moving Forward...")
  57.       end
  58.    end
  59. end
  60.  
  61. --find turtle's current location
  62. function gpsFind()
  63.    return gps.locate(1)
  64. end
  65.  
  66. --startprogram:
  67.  
  68. rednet.open("right")
  69. gpsFind() --find current location before turtle moves
  70. local x, y, z = gpsFind()
  71. print(gpsFind())
  72.  
  73. for i = 1, tArgs[1] do
  74.    fuel()
  75.    gCheck()
  76.    frwd()
  77.    lava()
  78. end
  79. drop()
  80. rednet.close("right")
Advertisement
Add Comment
Please, Sign In to add comment