Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Path to the ID file
- local idPath = "/Disk/ID"
- -- Function to check if ID matches
- local function checkID()
- -- Check if the ID file exists
- if fs.exists(idPath) then
- -- Read the ID from the file
- local file = fs.open(idPath, "r")
- local idFromFile = file.readAll()
- file.close()
- -- Check if the ID on the bottom drive matches
- local bottomDrive = peripheral.wrap("bottom")
- local diskID = bottomDrive.getDiskID()
- if diskID == idFromFile then
- -- ID is valid
- print("ID is valid")
- -- Open the door on the left
- peripheral.call("left", "open")
- -- Display success message on the monitor on the right
- local monitor = peripheral.wrap("right")
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Success!")
- monitor.setCursorPos(1, 2)
- monitor.write("Door opened.")
- -- Wait for 3 seconds
- sleep(3)
- -- Close the door
- peripheral.call("left", "close")
- -- Eject the disk
- bottomDrive.ejectDisk()
- else
- -- ID is not valid
- print("ID is not valid")
- -- Display error message on the monitor on the right
- local monitor = peripheral.wrap("right")
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Error: Invalid ID")
- end
- else
- -- ID file not found
- print("ID file not found")
- -- Display default message on the monitor on the right
- local monitor = peripheral.wrap("right")
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("DOGGY OS Enterprise Security")
- monitor.setCursorPos(1, 2)
- monitor.write("Insert valid ID Card")
- end
- end
- -- Main loop
- while true do
- -- Check the ID
- checkID()
- -- Wait for the disk to be inserted again
- while not peripheral.wrap("bottom").isDiskPresent() do
- sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement