Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inputPos = "bottom" --redstone input
- delayTime = 10 --Delay in seconds
- opStatus = {["on"] = false, --turtle should attack when true
- ["off"] = false, --turtle should NOT attack when true
- ["delayedOff"] = false --turtle should attack when true
- }
- function attack()
- while true do
- if opStatus.on or opStatus.delayedOff then turtle.attack() end
- end
- end
- --[[
- TODO: dropAll is too slow!!!
- ]]--
- function dropAll()
- while true do
- if opStatus.on or opStatus.delayedOff then
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- sleep(5)
- end
- end
- end
- --Displays statuses and warning.
- function display()
- term.clear()
- term.setCursorPos(2,2)
- print("I'm operating.")
- term.setCursorPos(2,4)
- for status,state in pairs (opStatus) do
- if state then
- print ("I'm in '".. status .."' state.")
- if not status == "off" then
- term.setCursorPos(2,5)
- print ("Don't go in front of me!")
- end
- end
- end
- end
- function main()
- --Main starts here
- --[[Filling up opStatus table.
- If redstone is active (mobspawner is off) upon load the turtle
- stays on for delayTime seconds since it cannot be known if there
- are any mobs in front of it.
- --]]
- if rs.getInput(inputPos) then
- os.startTimer(delayTime)
- opStatus.on = false
- opStatus.off = false
- opStatus.delayedOff = true
- else
- opStatus.on = true
- opStatus.off = false
- opStatus.delayedOff = false
- end
- while true do
- display()
- event = os.pullEvent()
- if event == "redstone" then
- if rs.getInput(inputPos) then
- --[[when rs input is active: delayedOff and
- start the delayTimer
- ]]--
- os.startTimer(delayTime)
- opStatus.on = false
- opStatus.off = false
- opStatus.delayedOff = true
- else
- --when rs input is inactive: turn on
- opStatus.on = true
- opStatus.off = false
- opStatus.delayedOff = false
- end
- elseif event == "timer" then
- --when delayTimer is up: turn off
- opStatus.on = false
- opStatus.off = true
- opStatus.delayedOff = false
- end
- end
- end
- parallel.waitForAny(main,attack,dropAll)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement