Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- When this program gets a redstone signal, it
- -- scans for players. It continues scanning until
- -- the redstone has been off for the configured
- -- number of seconds.
- --
- -- While scanning, users on the whitelist will
- -- cause a redstone signal to be emitted. Users on
- -- the blacklist will prevent the redstone from
- -- activating, even when whitelisted players are
- -- near.
- --
- -- Author: MyrddinE
- -- 2013-10-16
- -- Configuration
- local side = {sensor="bottom",input="right",output="back"}
- local active_when = true
- local open_emit = false
- local continue_for = 30 -- seconds
- local file = fs.open("whitelist.dat","r")
- local whitelist = textutils.unserialize(file.readAll())
- file.close()
- file = fs.open("blacklist.dat","r")
- local blacklist = textutils.unserialize(file.readAll())
- file.close()
- function roomOpen(open)
- if open then
- print("Opening door.")
- else
- print("Closing door.")
- end
- -- The '(open == open_emit)' is a logical filter, setting
- -- the output based on whether open = true, or open = false.
- rs.setOutput(side.output,(open == open_emit))
- end
- -- Load sensor api, and connect to it.
- os.loadAPI("ocs/apis/sensor")
- local players = sensor.wrap(side.sensor)
- roomOpen(false)
- -- Infinite loop waiting for redstone change.
- while true do
- os.pullEvent("redstone")
- -- Initially just wait for 1 second when it
- -- detects a redstone change on any side.
- local stopTime = os.clock() + 1
- while os.clock() < stopTime do
- -- If the input side is in 'on mode' (as defined
- -- by the active_when var) then set the end time
- -- to be now + continue_for seconds (default of
- -- 30 seconds).
- if rs.getInput(side.input) == active_when then stopTime = os.clock() + continue_for end
- -- Compare all the names of nearby players to the
- -- lists.
- good = false
- bad = false
- targets = players.getTargets()
- for username,_ in pairs(targets) do
- write(username.." is ")
- if whitelist[username] then
- write("whitelisted. ")
- good = true
- elseif blacklist[username] then
- write("blacklisted. ")
- bad = true
- else
- write("unknown player. ")
- end
- end
- -- Open/close the door based on nearby listed
- -- players
- if bad then
- roomOpen(false)
- elseif good then
- roomOpen(true)
- else
- roomOpen(false)
- end
- write(os.time().." ")
- sleep(1)
- end
- -- Rebooting when the detection turns off allows dynamic
- -- re-loading of the software when updated.
- os.reboot()
- end
Add Comment
Please, Sign In to add comment