GraySloth

ComputerCraft: 'stairs' Digs stairs up or down

Feb 6th, 2013
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. --v2.1 by GraySloth 2013-Feb-23
  2. --here is an old video demonstration of my scripts, it is almost good. http://youtu.be/9vhl7dSENs8
  3. local tArgs = { ... }
  4. if #tArgs ~= 2 then
  5.     print( "Usage: stairs [up|down] <#height>" )
  6.     return
  7. end
  8.  
  9.  
  10. local size = tonumber( tArgs[2] )
  11. if size < 1 then
  12.     print( "stairs height must be positive" )
  13.     return
  14. end
  15.  
  16. --functions
  17. function fuelCheck()
  18.     if turtle.getFuelLevel() == "unlimited" then
  19.     return true
  20.     elseif turtle.getFuelLevel() < 2 then
  21.       print("Traveled "..dist.." of "..tArgs[2]..", Need more fuel")
  22.       print("Searching for fuel hold ctrl+t to stop")
  23.       while turtle.getFuelLevel() < 10 do
  24.          for n=1,16 do
  25.             if turtle.getFuelLevel() < 10 then
  26.                turtle.select(n)
  27.                turtle.refuel(1)
  28.             end
  29.          end
  30.       end
  31.       print("Refueled: "..turtle.getFuelLevel())
  32.    end
  33. end
  34.  
  35. local dist = 0
  36. function count()
  37. dist = dist + 1
  38.    if (math.fmod( dist, 8 ) == 0) or (math.fmod( dist, tArgs[2] ) == 0) then
  39.       print("Traveled "..dist.." of "..tArgs[2]..", Fuel: "..turtle.getFuelLevel())
  40.    end
  41. end
  42. --Main
  43. local stop = 0
  44. print("Fuel level: "..turtle.getFuelLevel())
  45. if (tArgs[1] == ("down")) or (tArgs[1] == ("dn")) then
  46.    for i = 1, size do
  47.       fuelCheck()
  48.       if turtle.digDown() then
  49.             stop = 0
  50.          else
  51.             stop = stop + 1
  52.          end
  53.       turtle.down()
  54.       turtle.dig()
  55.           while not turtle.forward() do
  56.             turtle.dig()
  57.           end
  58.       turtle.digUp()
  59.       count()
  60.       if stop == 4 then
  61.             print("Traveled "..dist.." of "..tArgs[2]..", Fuel: "..turtle.getFuelLevel())
  62.             print("stopped")
  63.             return
  64.          end
  65.     end
  66. elseif tArgs[1] == ("up") then
  67.       for i = 1, size do
  68.          fuelCheck()
  69.          turtle.dig()
  70.           while not turtle.forward() do
  71.             turtle.dig()
  72.           end
  73.          if turtle.digUp() then
  74.             stop = 0
  75.          else
  76.             stop = stop + 1
  77.          end
  78.          turtle.up()
  79.          turtle.digUp()
  80.          count()
  81.          if stop == 4 then
  82.             print("Traveled "..dist.." of "..tArgs[2]..", Fuel: "..turtle.getFuelLevel())
  83.             print("stopped")
  84.             return
  85.          end
  86.        end
  87. else
  88.    print( "Usage: stairs <up|down> <height>" )
  89.    return
  90. end
  91. print("Done")
Advertisement
Add Comment
Please, Sign In to add comment