macol11_PLAY

Door Password System

May 4th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. function save(text,name)
  2. local file = fs.open(name,"w")
  3. file.write(text)
  4. file.close()
  5. end
  6. function load(name)
  7. local file = fs.open(name,"r")
  8. local data = file.readAll()
  9. file.close()
  10. return data
  11. end
  12.  
  13. term.clear()
  14. term.setCursorPos(1,2)
  15. local ch1
  16. local ch2
  17.  
  18. if fs.exists("pass") then
  19. ch1 = true
  20. else
  21. print("Please enter a password for your doors:")
  22. print()
  23. p1 = read("*")
  24. print()
  25. print("Please repeat your password:")
  26. print()
  27. p2 = read("*")
  28. print()
  29. if p1 ~= p2 then
  30. print("Password and repeated password doesn't match.")
  31. sleep(3)
  32. os.reboot()
  33. else
  34. save(p1, "pass")
  35. os.reboot()
  36. end
  37. end
  38.  
  39. if fs.exists("l") then
  40. ch2 = true
  41. else
  42. print("Please tell me where are your doors. (left / right / front / back / top / bottom)")
  43. print()
  44. l = read()
  45. print()
  46. if l == "left" or l == "right" or l == "front" or l == "back" or l == "top" or l == "bottom" then
  47. term.clear()
  48. term.setCursorPos(1,2)
  49. save(l, "l")
  50. print("Thank you for setting up system. rebooting in 5 secounds.")
  51. sleep(5)
  52. os.reboot()
  53. else
  54. print()
  55. print("Use left / right / front / back / top / bottom!")
  56. sleep(3)
  57. os.reboot()
  58. end
  59. end
  60.  
  61. if ch1 and ch2 then
  62. print("Please enter password to open door (or enter '*YOURPASSWORD*edit' ex. 'exampleedit' to setup doors system again):")
  63. print()
  64. input = read("*")
  65. if input == load("pass") then
  66. term.clear()
  67. term.setCursorPos(1,2)
  68. print("Correct password.")
  69. redstone.setOutput(load("l"), true)
  70. sleep(3)
  71. redstone.setOutput(load("l"), false)
  72. os.reboot()
  73. elseif input == load("pass") .. "edit" then
  74. term.clear()
  75. term.setCursorPos(1,2)
  76. print("You can setup your doors system again in 3 secounds.")
  77. shell.run("delete pass")
  78. shell.run("delete l")
  79. sleep(2)
  80. os.reboot()
  81. else
  82. term.clear()
  83. term.setCursorPos(1,2)
  84. print("Wrong password!")
  85. sleep(3)
  86. os.reboot()
  87. end
  88. end
Add Comment
Please, Sign In to add comment