Joshalot

CC - vaultDoor

Feb 27th, 2021 (edited)
343
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --pastebin get M50BPAxc vaultDoor
  2. --------------------------------------------------
  3.  
  4. local pullEvent = os.pullEvent
  5. os.pullEvent = os.pullEventRaw
  6.  
  7. m = peripheral.find('modem')
  8. if m ~= nil then
  9.     m.open(69)
  10. end
  11. open = colors.lightBlue
  12. close = colors.white
  13. side = 'back'
  14. time = 0.5
  15. doorName = 'doorNAME'
  16.  
  17. --------------------------------------------------
  18.  
  19. function clear()
  20.     term.clear()
  21.     term.setCursorPos(1,1)
  22.     term.setTextColor(colors.yellow)
  23.     print("Vault.OS")
  24.     term.setTextColor(colors.white)
  25. end
  26.  
  27. function door(colour)
  28.     for i = 1, 3 do
  29.         rs.setBundledOutput(side, colour)
  30.         sleep(time)
  31.         rs.setBundledOutput(side, 0)
  32.         sleep(time)
  33.     end
  34. end
  35.  
  36.  
  37. function checkPassword()
  38.     if not fs.exists('/os/user') then
  39.         while true do
  40.             shell.run('clear')
  41.  
  42.             print('Please input password.')
  43.             write('> ')
  44.             password1 = read('*')
  45.  
  46.             print('Please re-enter your password.')
  47.             write('> ')
  48.             password2 = read('*')
  49.  
  50.             if password1 == password2 then
  51.                 break
  52.             else
  53.                 print('The passwords do not match.')
  54.                 sleep(1)
  55.             end
  56.         end
  57.  
  58.         f = fs.open('/os/user', 'w')
  59.         f.writeLine(password1)
  60.         f.close()
  61.     end
  62. end
  63.  
  64. --------------------------------------------------
  65.  
  66. function input()
  67.     while true do
  68.         clear()
  69.         print("Password:")
  70.         answer = read("*")
  71.         if answer == password then
  72.             clear()
  73.             textutils.slowPrint("Door Opening...")
  74.             door(open)
  75.             sleep(2)
  76.             clear()
  77.             textutils.slowPrint("Door Closing...")
  78.             door(close)
  79.         elseif answer == '123456789' then
  80.             error('Program Terminated')
  81.         else
  82.             term.setTextColor(colors.red)
  83.             textutils.slowPrint("Incorrect...")
  84.             sleep(2)
  85.         end
  86.     end
  87. end
  88.  
  89. function listen()
  90.     while true do
  91.         local event, side, frequency, replyFrequency, message, distance = os.pullEvent('modem_message')
  92.         if message == doorName then
  93.             door(open)
  94.             sleep(2)
  95.             door(close)
  96.         end
  97.     end
  98. end
  99.  
  100. -----------------------------------------------------------------------
  101.  
  102.  
  103. checkPassword()
  104.  
  105. f = fs.open('/os/user', 'r')
  106. password = f.readLine()
  107. f.close()
  108.  
  109.  
  110. parallel.waitForAll(input, listen)
RAW Paste Data