Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. -- Advanced Key Card Lock with Override and Logs by Simsfreak63
  2.  
  3. term.clear()
  4.  
  5. redstoneoutputside = "top" -- change this to the side you the redstone signal to be sent to
  6. password = "offblast" -- change this to your password
  7. adminpassword = "afterban" -- change this to admin password. admin can override the lock and open the door, but only from inside
  8. location = "Front Door" -- change this to the location you want to appear in the log
  9. logger = 6 -- change this to the id of the computer keeping the log
  10.  
  11. redstone.setOutput(redstoneoutputside,true)
  12. rednet.open("left") -- change this to the position of your modem
  13. local w,h = term.getSize()
  14.  
  15. function lock()
  16. while true do
  17. term.clear()
  18. term.setCursorPos((w/2)-6, 2)
  19. print("Lock Engaged")
  20. while true do
  21. event, back = os.pullEvent("disk")
  22. if fs.exists("disk/password") == true then
  23. sFile = "disk/password"
  24. hRead = fs.open(sFile, "r")
  25. sPass = hRead.readLine()
  26. user = hRead.readLine()
  27. hRead.close()
  28. if sPass == password then
  29. redstone.setOutput(redstoneoutputside,false)
  30. rednet.send(logger,"log")
  31. rednet.send(logger,"User "..user.." entered ["..location.."] at "..textutils.formatTime(os.time(),false)..".",false)
  32. os.reboot()
  33. else
  34. sleep(3)
  35. os.reboot()
  36. end
  37. end
  38. end
  39. end
  40. end
  41.  
  42. local sOverride = false
  43.  
  44. local function passwordinput()
  45. while true do
  46. term.setCursorPos(w/2-15, h/2-1)
  47. print("Enter Passord to Override Lock")
  48. term.setCursorPos(w/2-3, h/2)
  49. local password = read("*")
  50. if password == adminpassword then
  51. term.clear()
  52. term.setCursorPos(2, h/2)
  53. print("Access Granted. Press Enter to override lock or")
  54. term.setCursorPos(w/2-10, h/2+1)
  55. print("Backspace to cancel.")
  56. keyboardinput()
  57. else
  58. term.clear()
  59. term.setCursorPos(w/2-15, h/2)
  60. print("Access Denied. Resetting Lock.")
  61. sleep(2)
  62. os.reboot()
  63. end
  64. end
  65. end
  66.  
  67. function keyboardinput()
  68. while true do
  69. local sEvent, param = os.pullEvent()
  70. if sEvent == "key" then
  71. if param == 28 then
  72. if sOverride == false then
  73. redstone.setOutput(redstoneoutputside, false)
  74. term.clear()
  75. term.setCursorPos(4, h/2)
  76. print("Door open. Press Enter again to Reset Lock.")
  77. sOverride = true
  78. else
  79. os.reboot()
  80. end
  81. elseif param == 14 then
  82. os.reboot()
  83. end
  84. end
  85. end
  86. end
  87.  
  88. parallel.waitForAll(lock,passwordinput)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement