Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- 7/1/2014 Created Stairs
- Logic borrowed from http://turtlescripts.com/project/gjdh4w-Staircases
- - by johncena1469
- Inspiration: everyone who has built turtle staircases
- --]]
- function pauseAnyKey()
- -- if event == "key" and p1 == keys.q then
- while true do
- local event, p1,p2,p3 = os.pullEvent()
- if event == "key" then
- return p1
- end
- sleep(0.5)
- end
- end
- function refuel()
- --Check fuel and refuel if nessesary
- --Code source: sethbling http://www.youtube.com/watch?v=DSsx4VSe-Uk&feature=share&list=SP2Qvl4gaBge02Eh4AqtDSWg3sojt3jeRO
- while turtle.getFuelLevel() < 200 do
- turtle.select(16)
- if turtle.getItemCount() < 1 then
- print("Turtle is out of fuel, please add fuel to slot 16")
- print("then press any key to continue")
- pauseAnyKey()
- end
- turtle.refuel(1)
- end
- end
- function nextInventory()
- for i=1,15 do
- turtle.select(i)
- if turtle.getItemCount() > 0 then
- return i
- end
- end
- return false
- end
- function getInventory()
- slot = nextInventory()
- if slot == false then
- print("Out of inventory")
- print("Please reload inventory")
- print("Then press any key")
- pauseAnyKey()
- slot = nextInventory()
- if slot == false then
- print("Looks like you've given up!")
- return
- end
- end
- turtle.select(slot)
- end
- function digFront()
- while turtle.detect() do
- turtle.dig()
- turtle.attack()
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- turtle.attackUp()
- end
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- turtle.attackDown()
- end
- end
- function putDown()
- if not turtle.detectDown() then
- turtle.placeDown()
- end
- end
- function buildDown(height)
- refuel()
- for i=1, height do
- digFront()
- turtle.forward()
- digUp()
- digDown()
- turtle.up()
- digUp()
- turtle.down()
- turtle.down()
- getInventory()
- putDown()
- end
- for i=1, height do
- digUp()
- turtle.up()
- turtle.back()
- getInventory()
- putDown()
- end
- end
- function buildUp(height)
- refuel()
- for i=1, height do
- digFront()
- digUp()
- getInventory()
- turtle.up()
- turtle.forward()
- putDown()
- end
- for i=1, height do
- turtle.back()
- digDown()
- turtle.down()
- getInventory()
- putDown()
- end
- end
- args = { ... }
- if #args ~= 2 then
- print("Usage:")
- print("")
- print(" stairs <up|down> <height>")
- return
- end
- test = string.sub( args[1], 1, 1)
- test = string.lower( test )
- if string.find("du",test) == nil then
- print("Direction must be one of 'up' or 'down'")
- return
- end
- direction = test
- h = tonumber(args[2])
- if h == nil or h < 0 then
- print("Height must be a real number higher than 0")
- return
- end
- if refuel == false then
- print("The turtle needs fuel, please put fuel in slot 16")
- return
- end
- if direction == "u" then
- buildUp(h)
- else
- buildDown(h)
- end
Add Comment
Please, Sign In to add comment