Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ComputerCraft Turtle Program: Ultra Stairs v.2
- pastebin get WTXCeWQM
- .....................EDIT LOG.......................
- EDITED: 14, Nov. 2014. Reason: Added a return to start position function called back().
- EDITED: 31, March 2015. Reason: Fixed so gravel/sand doesn't break the turtle's groove. Also changed name to match
- the other secondary program.
- EDITED: 31, March 2015. cont. Also added the cleanup program functionality to this code.
- digs out and places stairs
- EDITED: 18, September 2015. Reason: Added the ability to make stairs up or down. Also, fixed some things in the EDIT LOG.
- pastebin for my orginal stairs program: pastebin get t6kdBeq0
- EDITED: 21, Jan. 2016. Reason: Added the ability to make stairs in mid air without the stairs placing upside down. See airStairsUp, airStairsDown for the code.
- ]]
- fuelType = {
- coal = 80
- }
- local block = 1
- local stairs = 9
- local fuelUsed = 0
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: Stairs <amount>" )
- return
- end
- local amount = tonumber( tArgs[1] )
- function aboutFace()
- turtle.turnRight()
- turtle.turnRight()
- end
- function placeStair()--place Stair
- turtle.select(stairs)
- aboutFace()
- turtle.place()
- aboutFace()
- end
- function digOut()--moves to position next stair
- turtle.select(block)
- turtle.digDown()
- while not
- turtle.forward() do
- turtle.dig()
- end
- turtle.digDown()
- turtle.dig()
- turtle.down()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- placeStair()
- turtle.dig()
- end
- ---------------------------------STAIRS DOWN START---------------------------------------
- function stairsDown()
- --print("distance Down?")
- --amount = io.read()
- for i = 1, amount do
- digOut()
- end
- turtle.forward()
- function back()
- turtle.up()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- turtle.digUp()
- turtle.back()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- end
- for z = 1, amount + 1 do
- back()
- end
- end
- ---------------------------------STAIRS DOWN END---------------------------------------
- ---------------------------------STAIRS UP START---------------------------------------
- function digOutUp()
- turtle.digUp()
- turtle.dig()
- turtle.forward()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- turtle.select(stairs)
- turtle.placeDown()
- turtle.up()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- end
- function back()
- turtle.digUp()
- turtle.down()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- turtle.back()
- end
- function stairsUp()
- for i = 1, amount do
- digOutUp()
- end
- turtle.back()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- turtle.down()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- turtle.back()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- for i = 1, amount - 1 do
- back()
- end
- end
- ---------------------------------STAIRS UP END---------------------------------------
- function airBackUp()
- turtle.back()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- turtle.down()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- end
- ---------------------------------AIR STAIRS UP START---------------------------------------
- local t = turtle
- function airStairsUp()
- for i = 1, amount do
- t.select(block)
- t.place()
- t.turnLeft()
- t.place()
- t.turnRight()
- t.turnRight()
- t.place()
- t.up()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- t.place()
- t.turnLeft()
- t.turnLeft()
- t.place()
- t.turnRight()
- t.select(stairs)
- t.placeDown()
- t.forward()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- end
- for i = 1, amount do
- airBackUp()
- end
- end
- ---------------------------------AIR STAIRS UP END---------------------------------------
- function airBackDown()
- turtle.up()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- turtle.forward()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- end
- ---------------------------------AIR STAIRS DOWN START---------------------------------------
- function airStairsDown()
- aboutFace()
- for i = 1, amount do
- t.turnLeft() -- turn left
- t.select(block)
- t.place() -- place left
- aboutFace() -- turn right
- t.place() -- place right
- t.turnLeft()-- back to start position
- t.back()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- t.select(stairs)
- t.place()
- t.turnLeft() -- turn left
- t.select(block)
- t.place() -- place left
- aboutFace() -- turn right
- t.place() -- place right
- t.turnLeft()-- back to start position
- t.down()
- fuelUsed = fuelUsed + 1
- print(fuelUsed)
- t.placeDown()
- end
- for z = 1, amount + 1 do
- airBackDown()
- end
- end
- ---------------------------------AIR STAIRS DOWN END---------------------------------------
- function refuel()
- local fuelLvl = turtle.getFuelLevel()
- local fuelDistance = amount * 2
- local fuelNeeded = (fuelDistance - fuelLvl) / fuelType.coal
- print("Fuel level is " ..fuelLvl)
- if fuelNeeded > 0 then
- for i=1,16 do
- turtle.select(i)
- turtle.refuel(math.ceil(fuelNeeded))
- end
- else print("No fuel needed.")
- end
- end
- function clearTerm()
- term.clear()
- term.setCursorPos(1,1)
- end
- print("Up or Down?")
- direction = io.read()
- function mainProg()
- if direction == "up" then
- print("Dig yes or no?")
- dig = io.read()
- if dig == "yes" then
- clearTerm()
- repeat
- print("Be sure to place the turtle at head level." )
- print("")
- print("Place stairs in slot " .. stairs)
- print("")
- print("Press any key to continue.")
- until os.pullEvent("char")
- clearTerm()
- stairsUp()
- elseif dig == "no" then
- clearTerm()
- repeat
- print("Place the turtle on ground level.")
- print("")
- print("Place blocks in slot " .. block)
- print("")
- print("Place stairs in slot " .. stairs)
- print("")
- print("Press any key to continue.")
- until os.pullEvent("char")
- clearTerm()
- airStairsUp()
- end
- elseif direction == "down" then
- print("Dig yes or no?")
- dig = io.read()
- if dig == "yes" then
- clearTerm()
- repeat
- print("Be sure to place the turtle at ground level." )
- print("")
- print("Place stairs in slot " .. stairs)
- print("")
- print("Press any key to continue.")
- until os.pullEvent("char")
- clearTerm()
- stairsDown()
- elseif dig == "no" then
- clearTerm()
- repeat
- print("Place the turtle on ground level.")
- print("")
- print("Place blocks in slot " .. block)
- print("")
- print("Place stairs in slot " .. stairs)
- print("")
- print("Press any key to continue.")
- until os.pullEvent("char")
- clearTerm()
- airStairsDown()
- end
- end
- end
- refuel()
- mainProg()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement