Advertisement
DOGGYWOOF

security

Jan 7th, 2024
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. local sensorSide = "side_of_sensor" -- Replace with the side the sensor is connected to
  2. local keycardSide = "side_of_keycard_reader" -- Replace with the side the keycard reader is connected to
  3. local speakerSide = "side_of_speaker" -- Replace with the side the speaker is connected to
  4. local monitorSide = "side_of_monitor" -- Replace with the side the monitor is connected to
  5.  
  6. local sensor = peripheral.wrap(sensorSide)
  7. local keycard = peripheral.wrap(keycardSide)
  8. local speaker = peripheral.wrap(speakerSide)
  9. local monitor = peripheral.wrap(monitorSide)
  10.  
  11. local authorizedCards = {"CardID1", "CardID2"} -- Add authorized card IDs
  12.  
  13. local function activateAlarm()
  14. speaker.playSound("entity.enderman.stare", 1.0, 1.0) -- Adjust sound as needed
  15. monitor.clear()
  16. monitor.setTextColor(colors.red)
  17. monitor.setCursorPos(1, 1)
  18. monitor.write("INTRUDER ALERT!")
  19. -- Add more actions like notifying via chat or sending a redstone signal
  20. end
  21.  
  22. while true do
  23. local event, side, xPos, yPos, player = os.pullEvent()
  24.  
  25. if event == "keypad" and side == keycardSide then
  26. for _, id in ipairs(authorizedCards) do
  27. if player == id then
  28. print("Access granted for " .. player)
  29. break -- Authorized card detected, no need to check further
  30. else
  31. print("Unauthorized access attempt by " .. player)
  32. activateAlarm()
  33. end
  34. end
  35. elseif event == "motion" and side == sensorSide then
  36. print("Motion detected!")
  37. activateAlarm()
  38. end
  39. end
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement