Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Basic keycard lock by Lymia
- -- Released to the public domain
- -- Clears the terminal
- term.clear()
- term.setCursorPos(1,1)
- -- What file to look for the password in
- local keyFile = "lockFile"
- -- The password to look for
- local keyContents = "12345"
- -- What side to output the door signal to
- local outputSide = "left"
- while true do
- -- Get raw event data
- local rawEvent = {coroutine.yield()}
- local event = rawEvent[1]
- if event == "disk" then
- local side = rawEvent[2]
- -- Check if this is a data disk
- if disk.isPresent(side) and disk.hasData(side) then
- -- And if so, try to open the lock file
- local file = "/"..disk.getMountPath(side).."/"..keyFile
- file = fs.open(file,"r")
- if file then
- file = file.readAll()
- if file == keyContents then
- print("Keyfile accepted!")
- -- Send the door signal...
- rs.setOutput(outputSide,true)
- -- Send a "timer" event after 4 seconds
- -- I could use sleep here, but, this way, I can still process disk
- -- events while the redstone signal is on.
- os.startTimer(4)
- else
- print("Invalid keyfile")
- end
- else
- -- Guess the lockfile's not there
- print("Keyfile not found")
- end
- else
- print("Keyfile not found")
- end
- -- And now, eject the disk
- disk.eject(side)
- elseif event == "timer" then
- -- This follows the timer set up in the lock checking code.
- -- Unset the door signal.
- rs.setOutput(outputSide,false)
- elseif event == "terminate" then
- -- Prevents Ctrl-T (It would be ignored otherwise anyways, but...)
- print("[termination intercepted]")
- end
- end
Add Comment
Please, Sign In to add comment