Advertisement
DOGGYWOOF

Untitled

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