FlaserDog

Door Lock System

Jun 12th, 2021 (edited)
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.87 KB | None | 0 0
  1. --[[
  2. The Programm is not working at the moment because it uses to much Resources
  3. and Crashes because of that Ingame. I will edit it in the near Future and also
  4. Make it more diverse.
  5.  
  6. Some Examples:
  7.   - Making it possible to change Color of the Messages
  8.   - Making Alarm System more Userfriendly. (Permanent Redstone Signal etc)
  9.   - Making LockDown Mode Saves failed tries after Shutdown and Reboot.
  10.   - Create an Dummy Password
  11.   - A Settings Menu <Maybe>
  12.   - more coming soon..
  13. ]]--
  14.  
  15.  
  16. -- Main Settings:
  17.  
  18. -- Password to open the Door.
  19. DoorPass    = "Password"
  20. -- Password to get into the Pc.
  21. MasterPass  = "Password"
  22. -- Side the Redstone should be Output to Activate the Door.
  23. DoorSide    = "Side"
  24. -- Amount of time the Door should be kept Open.
  25. rsTime      = "Amount"
  26. -- Amount of time befor the Door will Open.
  27. DoorDelay   = "Amount"
  28.  
  29.  
  30. -- Displayed Messages:
  31.  
  32. -- Message that appears when System Starts.
  33. StartMSG    = "Input Passwort: "
  34. -- Message that appears when Password was Correct.
  35. CorrectMSG  = "Access Granted"
  36. -- Message that appears when Password was Incorrect.
  37. WrongMSG    = "Access Denied"
  38. -- Message that appears when the MasterPassword is used.
  39. MasterMSG   = "Programm shutting down"
  40.  
  41.  
  42. -- Toggable Features:
  43.  
  44. -- Alarm System (SEPERAT Redstone Connection needed)
  45.  
  46. -- Toogles if the Alarm can be used.
  47. Alarm         = false
  48. -- Password to Deactivate the Alarm.
  49. AlarmOffPass  = "Password"
  50. -- Where the Connection of the Alarm Redstone is.
  51. AlarmSide     = "Side"
  52. -- Message that appears when the Alarm is Deactivated.
  53. AlarmMSG      = "Alarm deactivated"
  54.  
  55.  
  56. -- System with a fixed amount of tries.
  57.  
  58. -- Toggles if LockDown Mode works.
  59. LockSystem    = false
  60. -- Password to Deactivated LockDown Mode.
  61. SecurityPass  = "Password"
  62. -- Amount of tries a Player has befor SecurityMode will be activated.
  63. Tries         = 3
  64. -- Message that appears when LockDownMode is active.
  65. LockDownMSG   = "System is in Lockdown.\nInput Password: "
  66.  
  67.  
  68. -- Maintance System (As an way to save the entry to the redstone part of the build)
  69.  
  70. -- Toggles if Maintance can be used
  71. Maintance     = false
  72. -- Password to toggle the Maintance System
  73. MaintancePass = "Password"
  74. -- Side wherer the connection of the Maintance is
  75. MaintanceSide = "Side"
  76. -- Message that appears when Maintance is activated
  77. MaintanceMSG  = "Toggled MaintanceMode"
  78.  
  79.  
  80. -- Do not edit after this part, except you know what you are doing.
  81.  
  82. os.pullEvent = os.pullEventRaw
  83.  
  84. -- Counts the amount of failed tries made.
  85. CountTry = {}
  86.  
  87. -- Checks which Mode Maintance is.
  88. MaintanceMode = {}
  89.  
  90. -- Clears the Screen and Puts the Cursor to the Top Left.
  91. local function clear()
  92.     term.clear()
  93.     term.setCursorPos(1,1)
  94. end
  95.  
  96. -- Function to Activate the Redstone for the Door.
  97. local function rsDoor()
  98.     sleep(DoorDelay)
  99.     rs.setOutput(DoorSide, true)
  100.     sleep(rsTime)
  101.     rs.setOutput(DoorSide, false)
  102. end
  103.  
  104. -- Saves failed Tries
  105. local function SaveTries()
  106.     fs.makeDir("DoorLock")
  107.     fs.open("DoorLock/SaveData","w")
  108.     file.writeLine(CountTry)
  109.     file.close()
  110. end
  111.  
  112. -- Load failed tries
  113. local function LoadTries()
  114.     local Number = {}
  115.  
  116.     fs.open("DoorLock/SaveData","r")
  117.     file.readLine()
  118.     table.insert(Number,line)
  119.     file.close()
  120.     CountTry = CountTry + Number
  121. end
  122.  
  123. -- Saves Maintance Mode
  124. local function SaveMaintance()
  125.     fs.open("DoorLock/Maintance","w")
  126.     file.wirteLine(MaintanceMode)
  127.     file.close()
  128. end
  129.  
  130. -- Load Maintance Mode
  131. local function LoadMaintance()
  132.     local Mode = {}
  133.  
  134.     fs.open("DoorLock/Maintanc","r")
  135.     file.readLine()
  136.     table.insert(Mode,line)
  137.     file.close()
  138.     MaintanceMode = Mode
  139. end
  140.  
  141. -- Initiates the LockDown Mode.
  142. local function LockDown()
  143.     if CountTry >= Tries and LockSystem == true then
  144.         return true
  145.      end
  146. end
  147.  
  148.  
  149. -- Main Code:
  150.  
  151. -- Start Position of the Programm
  152. function Main()
  153.     print(StartMSG)
  154.     input = read("*")
  155.  
  156.     while true do
  157.  
  158.         LoadTries()
  159.         LoadMaintance()
  160.  
  161.         -- Compares Input to the given Situations
  162.         if input == DoorPass and LockDown() == false then
  163.             clear()
  164.             print(CorrectMSG)
  165.             rsDoor()
  166.             CountTry = CountTry - CountTry
  167.             clear()
  168.             SaveTries()
  169.             Main()
  170.         elseif input == SecurityPass and LockDown() == true then
  171.             clear()
  172.             print(CorrectMSG)
  173.             sleep(3)
  174.             CountTry = CountTry - CountTry
  175.             clear()
  176.             SaveTries()
  177.             Main()
  178.         elseif input == MasterPass then
  179.             clear()
  180.             print(MasterMSG)
  181.             sleep(2)
  182.             SaveTries()
  183.             Main()
  184.         elseif input == AlarmOffPass and Alarm == true then
  185.             clear()
  186.             print(AlarmMSG)
  187.             sleep(2)
  188.             rs.setOutput(AlarmSide, true)
  189.             clear()
  190.             SaveTries()
  191.             Main()
  192.         elseif input == MaintancePass and Maintance == true and MaintanceMode == false then
  193.             clear()
  194.             print(MaintanceMSG)
  195.             sleep(2)
  196.             rs.setOutput(MaintanceSide, true)
  197.             MaintanceMode = true
  198.             SaveMaintance()
  199.             clear()
  200.             SaveTries()
  201.             Main()
  202.         elseif input == MaintancePass and Maintanc == true and MaintanceMode == true then
  203.             clear()
  204.             print(MaintanceMSG)
  205.             sleep(2)
  206.             rs.setOutput(MaintanceSide, false)
  207.             MaintanceMode = false
  208.             SaveMaintance()
  209.             clear()
  210.             SaveTries()
  211.             Main()
  212.         else
  213.             clear()
  214.             if Alarm == true then
  215.                 rs.setOutput(AlarmSide, true)
  216.             end
  217.             print(WrongMSG)
  218.             sleep(3)
  219.             CountTry = CountTry + 1
  220.             clear()
  221.             SaveTries()
  222.             Main()
  223.         end
  224.     end
  225. end
Add Comment
Please, Sign In to add comment