Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Yellow sticky piston
- -- Green placer
- -- Orange Piston
- BLOCK_STRENGHT = 0.8
- DOOR_HEIGHT = 5
- BUNDLE_SIDE = "bottom"
- CLOSE_DELAY = 10
- CURRENT_REDSTONE_STATE = 0
- settings.define("door_state", {default = "unknown"})
- settings.load()
- while (settings.get("door_state") == "unknown") do
- print("Unknown door position!")
- print("Is the door currently open or closed? [open/closed]")
- write("> ")
- local answer = read()
- if answer == "open" or answer == "closed" then
- settings.set("door_state", answer)
- end
- settings.save()
- end
- term.clear()
- print("Door control script active!")
- function disableAll()
- redstone.setBundledOutput(BUNDLE_SIDE, 0)
- CURRENT_REDSTONE_STATE = 0
- end
- function enableRed(color)
- CURRENT_REDSTONE_STATE = colors.combine(CURRENT_REDSTONE_STATE, color)
- redstone.setBundledOutput(BUNDLE_SIDE, CURRENT_REDSTONE_STATE)
- end
- function disableRed(color)
- CURRENT_REDSTONE_STATE = colors.subtract(CURRENT_REDSTONE_STATE, color)
- redstone.setBundledOutput(BUNDLE_SIDE, CURRENT_REDSTONE_STATE)
- end
- function placeRow()
- enableRed(colors.orange)
- sleep(0.2)
- disableRed(colors.orange)
- end
- function close()
- disableAll()
- enableRed(colors.yellow)
- sleep(0.2)
- for i = 1, DOOR_HEIGHT+1, 1
- do
- sleep(1.1)
- placeRow()
- end
- sleep(0.2)
- disableAll();
- settings.set("door_state", "closed")
- end
- function open()
- disableAll()
- enableRed(colors.orange)
- sleep(0.5)
- enableRed(colors.blue)
- sleep(BLOCK_STRENGHT*DOOR_HEIGHT+1)
- disableAll()
- enableRed(colors.yellow)
- sleep(1.1)
- placeRow()
- sleep(0.2)
- disableAll()
- settings.set("door_state", "open")
- end
- rednet.open("left")
- local timer_id = -1
- while true do
- local event = {os.pullEvent()}
- local state = settings.get("door_state")
- if ((event[1] == "redstone" and redstone.testBundledInput(BUNDLE_SIDE, colors.lime)) or (event[1] == "rednet_message" and event[3] == "doit")) then
- if (state == "closed") then
- open()
- end
- if timer_id ~= -1 then
- os.cancelTimer(timer_id)
- end
- timer_id = os.startTimer(CLOSE_DELAY)
- elseif (event[1] == "timer" and state == "open")
- then
- close()
- end
- settings.save();
- end
Add Comment
Please, Sign In to add comment