Advertisement
DOGGYWOOF

Untitled

Jul 22nd, 2024 (edited)
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. -- Define the side of the door and the correct password
  2. local doorSide = "left"
  3. local correctPassword = "testing"
  4.  
  5. -- Variable to track if the door was opened by the computer
  6. local doorOpenedByComputer = false
  7.  
  8. -- Function to check the door state
  9. local function isDoorOpen()
  10. return redstone.getInput(doorSide)
  11. end
  12.  
  13. -- Function to unlock the door
  14. local function unlockDoor()
  15. redstone.setOutput(doorSide, true)
  16. doorOpenedByComputer = true -- Mark that the computer is opening the door
  17. sleep(2) -- Keep the door unlocked for 2 seconds
  18. redstone.setOutput(doorSide, false)
  19. doorOpenedByComputer = false -- Reset after closing the door
  20. end
  21.  
  22. -- Main program loop
  23. while true do
  24. -- Prompt for the password
  25. term.clear()
  26. term.setCursorPos(1, 1)
  27. print("Enter password to unlock the door:")
  28. local inputPassword = read("*") -- Hide input for security
  29.  
  30. -- Check if the password is correct
  31. if inputPassword == correctPassword then
  32. unlockDoor()
  33. print("Door unlocked!")
  34. sleep(3) -- Wait before clearing the message
  35. else
  36. print("Incorrect password!")
  37. sleep(3)
  38. end
  39.  
  40. -- Check for unauthorized door openings
  41. if isDoorOpen() and not doorOpenedByComputer then
  42. term.clear()
  43. term.setCursorPos(1, 1)
  44. print("ALERT: Unauthorized door opening detected!")
  45. sleep(5) -- Keep the alert message for 5 seconds
  46. end
  47.  
  48. sleep(0.5) -- Short delay to avoid excessive CPU usage
  49. end
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement