Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the side of the door and the correct password
- local doorSide = "left"
- local correctPassword = "testing"
- -- Variable to track if the door was opened by the computer
- local doorOpenedByComputer = false
- -- Function to check the door state
- local function isDoorOpen()
- return redstone.getInput(doorSide)
- end
- -- Function to unlock the door
- local function unlockDoor()
- redstone.setOutput(doorSide, true)
- doorOpenedByComputer = true -- Mark that the computer is opening the door
- sleep(2) -- Keep the door unlocked for 2 seconds
- redstone.setOutput(doorSide, false)
- doorOpenedByComputer = false -- Reset after closing the door
- end
- -- Main program loop
- while true do
- -- Prompt for the password
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter password to unlock the door:")
- local inputPassword = read("*") -- Hide input for security
- -- Check if the password is correct
- if inputPassword == correctPassword then
- unlockDoor()
- print("Door unlocked!")
- sleep(3) -- Wait before clearing the message
- else
- print("Incorrect password!")
- sleep(3)
- end
- -- Check for unauthorized door openings
- if isDoorOpen() and not doorOpenedByComputer then
- term.clear()
- term.setCursorPos(1, 1)
- print("ALERT: Unauthorized door opening detected!")
- sleep(5) -- Keep the alert message for 5 seconds
- end
- sleep(0.5) -- Short delay to avoid excessive CPU usage
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement