Advertisement
LDDestroier

Simple Door Lock

Mar 21st, 2015
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. local defaultInfo = {}
  2. --Prevents CTRL+T from terminating the program.
  3. --os.pullEvent = os.pullEventRaw
  4. --Reads the pconf file for info.
  5. function readpconf()
  6.     file = fs.open("/.pconf", "r")
  7.   ts = file.readAll()
  8.   tss = textutils.unserialize(ts)
  9.     file.close()
  10. end
  11.  
  12. --Checks password file. If it doesn't exist, it will create one and prompt for a password.
  13. function check()
  14.     if not fs.exists("/.pconf") then
  15.         print("Config file not found.")
  16.         print("Enter new password:")
  17.         temp1 = tostring(read("*"))
  18.         print("Enter output side:")
  19.         temp2 = tostring(read())
  20.         print("Enter open time:")
  21.         temp3 = tonumber(read())
  22.         print("Enter wrong password timeout:")
  23.         temp4 = tonumber(read())
  24.         table.insert(defaultInfo, temp1)
  25.         table.insert(defaultInfo, temp2)
  26.         table.insert(defaultInfo, temp3)
  27.         table.insert(defaultInfo, temp4)
  28.         file = fs.open("/.pconf", "w")
  29.         ts = textutils.serialize(defaultInfo)
  30.         file.write(ts)
  31.         file.close()
  32.         check()
  33.     end
  34. end
  35.  
  36. local function passwordCorrect()
  37.     print("Password is correct.")
  38.     redstone.setOutput(tss[2], true)
  39.     sleep(tss[3])
  40.     redstone.setOutput(tss[2], false)
  41. end
  42.  
  43. local function passwordIncorrect()
  44.     print("Password is INCORRECT.")
  45.     sleep(tss[4])
  46. end
  47.  
  48. local function prompt()
  49.     term.clear()
  50.     term.setCursorPos(1,1)
  51.     print("Enter password:")
  52.     attempt = tostring(read("*"))
  53.     if attempt == tss[1] then
  54.         passwordCorrect()
  55.     else
  56.         passwordIncorrect()
  57.     end
  58. end
  59.  
  60. check()
  61.  
  62. readpconf()
  63.  
  64. while true do
  65.     prompt()
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement