Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Keycard system with monitor display and specific passkeys for override and owner in ComputerCraft
- -- Keycard IDs
- local ownerKeycardPath = "/disk/ownerKeycard.txt"
- local overrideKeycardPath = "/disk/overrideKeycard.txt"
- -- Function to check if the keycard is valid
- local function isValidKeycard(keycardID, passkey)
- local file = nil
- if keycardID == "owner" then
- file = fs.open(ownerKeycardPath, "r")
- elseif keycardID == "override" then
- file = fs.open(overrideKeycardPath, "r")
- end
- if file then
- local storedPasskey = file.readAll()
- file.close()
- return passkey == storedPasskey
- end
- return false
- end
- -- Function to grant access if the keycard is valid
- local function grantAccess()
- print("Access granted!")
- -- Perform actions for granting access (e.g., opening a door, enabling a system)
- -- For monitor display
- term.redirect(peripheral.wrap("right")) -- Redirect output to the monitor on the right
- print("Access granted!") -- Display on the monitor
- term.restore() -- Restore output to the terminal
- end
- -- Function to deny access if the keycard is invalid
- local function denyAccess()
- print("Access denied!")
- -- Perform actions for denying access (e.g., display a message, close a door)
- -- For monitor display
- term.redirect(peripheral.wrap("right")) -- Redirect output to the monitor on the right
- print("Access denied!") -- Display on the monitor
- term.restore() -- Restore output to the terminal
- end
- -- Main program
- while true do
- -- Read input from the user
- print("Please swipe your keycard:")
- local keycardID = read()
- local passkey = ""
- if keycardID == "owner" or keycardID == "override" then
- print("Enter passkey:")
- passkey = read("*")
- end
- -- Check if the keycard is valid
- if isValidKeycard(keycardID, passkey) then
- grantAccess()
- else
- denyAccess()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement