Advertisement
DOGGYWOOF

Untitled

Jul 30th, 2024 (edited)
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. local cardDriveSide = "bottom" -- side where the card reader is connected
  2. local monitorSide = "right" -- side where the monitor is connected
  3. local doorSide = "left" -- side where the door is connected
  4.  
  5. -- Wrap peripherals
  6. local cardDrive = peripheral.wrap(cardDriveSide)
  7. local monitor = peripheral.wrap(monitorSide)
  8.  
  9. -- Function to display a message on the monitor
  10. local function displayMessage(line, message)
  11. monitor.setCursorPos(1, line)
  12. monitor.clearLine()
  13. monitor.write(message)
  14. end
  15.  
  16. -- Function to display a detailed message about the access card status
  17. local function displayAccessCardMessage(status)
  18. monitor.clear()
  19. if status == "insert" then
  20. displayMessage(1, "Doggy OS Enterprise Security")
  21. displayMessage(2, "============================")
  22. displayMessage(4, "Welcome to Doggy OS Enterprise Security System.")
  23. displayMessage(6, "Please insert your access card to proceed.")
  24. elseif status == "valid" then
  25. displayMessage(1, "Access Granted")
  26. displayMessage(2, "============================")
  27. displayMessage(4, "Welcome, authorized user!")
  28. displayMessage(6, "Access has been granted.")
  29. sleep(3) -- Display message for 3 seconds
  30. elseif status == "invalid" then
  31. displayMessage(1, "Access Denied")
  32. displayMessage(2, "============================")
  33. displayMessage(4, "Invalid or unauthorized card.")
  34. displayMessage(6, "Access denied. Please contact")
  35. displayMessage(7, "security for assistance.")
  36. sleep(3) -- Display message for 3 seconds
  37. elseif status == "manager" then
  38. displayMessage(1, "Loading Disk Manager")
  39. displayMessage(2, "============================")
  40. displayMessage(4, "Please wait while the disk")
  41. displayMessage(5, "manager is loaded.")
  42. end
  43. end
  44.  
  45. -- Function to check the inserted card and control the door
  46. function checkCard()
  47. displayAccessCardMessage("insert") -- Initial message to insert card
  48.  
  49. while true do
  50. if cardDrive.isDiskPresent() then
  51. local diskID = cardDrive.getDiskID()
  52. local cardPathID = "/disk/Cards/"..diskID..".ID"
  53. local cardPathAuth = "/disk/Cards/"..diskID..".auth"
  54.  
  55. if fs.exists(cardPathID) then
  56. displayAccessCardMessage("valid")
  57. redstone.setOutput(doorSide, true) -- Open door
  58. sleep(1) -- Ensure door is fully open before ejecting
  59.  
  60. -- Eject the card
  61. cardDrive.ejectDisk()
  62. sleep(2) -- Keep door open for 2 seconds after ejecting
  63. redstone.setOutput(doorSide, false) -- Close door
  64.  
  65. break -- Exit loop after valid card action
  66. elseif fs.exists(cardPathAuth) then
  67. displayAccessCardMessage("manager")
  68. shell.run("monitor right disk.manager")
  69. sleep(5) -- Display message for 5 seconds or adjust as needed
  70.  
  71. -- Eject the card
  72. cardDrive.ejectDisk()
  73. sleep(2) -- Keep door open for 2 seconds after ejecting
  74. redstone.setOutput(doorSide, false) -- Close door
  75.  
  76. break -- Exit loop after manager action
  77. else
  78. displayAccessCardMessage("invalid")
  79. break -- Exit loop after invalid card action
  80. end
  81. else
  82. -- No card inserted, continue checking
  83. sleep(1) -- Wait briefly before checking again
  84. end
  85. end
  86. end
  87.  
  88. -- Main loop to continuously check for the card
  89. while true do
  90. checkCard()
  91. end
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement