AndyE7

cc password door v2

Oct 8th, 2024 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3.  
  4. local code
  5. local counter
  6. local userInput = ""
  7. local userBkp = ""
  8.  
  9.  
  10. local save = function(data, name)
  11. if not fs.exists('/data') then
  12. fs.makeDir('/data')
  13. end
  14. local file = fs.open('/data/'..name, 'w')
  15. file.write(textutils.serialize(data))
  16. file.close()
  17. end
  18.  
  19. local load = function(name)
  20. if fs.exists('/data/'..name) then
  21. local file = fs.open('/data/'..name, 'r')
  22. data = textutils.unserialize(file.readAll())
  23. file.close()
  24. end
  25. return data
  26. end
  27.  
  28.  
  29. if not fs.exists('/data/door') then
  30.  
  31. print("Enter New Door Code Below: ")
  32. code = read()
  33. save(code,"door")
  34. shell.run("pastebin run AUgEmXrk")
  35.  
  36. else
  37.  
  38. code = load('door')
  39.  
  40. end
  41.  
  42. if not fs.exists('/data/door') then
  43.  
  44. print("Enter New Door Code Below: ")
  45. code = read()
  46. save(code,"door")
  47.  
  48. else
  49.  
  50. code = load('door')
  51.  
  52. end
  53.  
  54. if not fs.exists('/data/tries') then
  55.  
  56. print("Enter New Door Code Below: ")
  57. counter = 0
  58. save(counter,"tries")
  59.  
  60. else
  61.  
  62. counter = load('tries')
  63.  
  64. end
  65.  
  66.  
  67. while true do
  68.  
  69. if counter >= 3 then
  70.  
  71. term.setCursorPos(1, 1)
  72.  
  73. term.clear()
  74. print("Door Protected by BandyB7 Lock V2.0")
  75. print("ATTEMPTED ENTRY DETECTED")
  76. while true do
  77.  
  78. local event, char = os.pullEvent("char")
  79.  
  80. if event == "terminate" then
  81. term.clear()
  82. term.setCursorPos(1, 1)
  83. print("Terminating...")
  84. os.sleep(1)
  85. term.clear()
  86. term.setCursorPos(1, 1)
  87. os.sleep(2)
  88. print("Just Kidding.")
  89. print("Door STILL Protected by BandyB7 Lock V2.0")
  90. print("ATTEMPTED ENTRY DETECTED")
  91. userBkp = ""
  92.  
  93. end
  94.  
  95. if char ~= nil then
  96.  
  97. userBkp = userBkp .. char
  98.  
  99. if #userBkp == 19 then
  100. break
  101. end
  102. end
  103. end
  104.  
  105. if userBkp == load("bkp") then
  106. save(0, "tries")
  107. os.reboot()
  108. end
  109. userBkp = ""
  110.  
  111. else
  112.  
  113. term.setCursorPos(1, 1)
  114.  
  115. term.clear()
  116. print("Door Protected by BandyB7 Lock V2.0")
  117. print("Enter Code Below: ")
  118. while true do
  119.  
  120. local event, char = os.pullEvent("char")
  121.  
  122. if event == "terminate" then
  123. term.clear()
  124. term.setCursorPos(1, 1)
  125. print("Terminating...")
  126. os.sleep(1)
  127. term.clear()
  128. term.setCursorPos(1, 1)
  129. os.sleep(2)
  130. print("Just Kidding.")
  131. print("Door STILL Protected by BandyB7 Lock V2.0")
  132. print("Enter Code Below: ")
  133.  
  134. end
  135.  
  136. if char ~= nil then
  137. userInput = userInput .. char
  138.  
  139. term.write("*")
  140.  
  141. if #userInput == #code then
  142. break
  143. end
  144. end
  145. end
  146.  
  147. if userInput == code then
  148. print("\nWelcome")
  149. save(0, "tries")
  150. redstone.setOutput("bottom", true)
  151. sleep(3)
  152. redstone.setOutput("bottom", false)
  153.  
  154. else
  155.  
  156. print("\nIncorrect Password")
  157. sleep(1)
  158. counter = counter + 1
  159. save(counter, "tries")
  160.  
  161. end
  162.  
  163. userInput = ""
  164.  
  165. end
  166. end
  167.  
Advertisement
Add Comment
Please, Sign In to add comment