Advertisement
MintTheFox

CC password door lock

Sep 26th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. local pullEvent = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3. --to restore keyboard commands--
  4. --os.pullEvent = pullEvent--
  5.  
  6. local pass = "bacon"
  7. local admin = "waffleiron"
  8. local state = 0
  9. local errornum = 0
  10.  
  11. while true do
  12.  
  13. while state == 0 do
  14.   term.clear()
  15.   term.setCursorPos(1,1)
  16.   print("Please enter password")
  17.   input = read("x")
  18.  
  19.     if input == pass then
  20.       redstone.setOutput("left", true)
  21.       sleep(5)
  22.       redstone.setOutput("left", false)
  23.     end
  24.  
  25.     if input == admin
  26.       print("Key commands enabled")
  27.       os.pullEvent = pullEvent
  28.     end
  29.  
  30.     if input ~= pass then
  31.       state = 1
  32.       errornum = errornum + 1
  33.     break
  34.    end
  35. end
  36.  
  37. while state == 1 do
  38.   if errornum ~= 3 then
  39.     term.clear()
  40.     term.setCursorPos(1,1)
  41.     print("Wrong password!")
  42.    
  43.       if errornum == 1 then
  44.         print("Lockout in 2 tries!")
  45.  
  46.       else
  47.         print("Lockout in 1 try!")
  48.       end
  49.  
  50.     input = read("x")
  51.      
  52.       if input ~= pass then
  53.         errornum = errornum + 1
  54.       end
  55.  
  56.       if input == admin
  57.         print("Key commands enabled")
  58.         os.pullEvent = pullEvent
  59.       end
  60.  
  61.       if input == pass then
  62.         redstone.setOutput("left", true)
  63.         sleep(5)
  64.         redstone.setOutput("left", false)
  65.         state = 0
  66.         errornum = 0
  67.       break
  68.      end
  69.   elseif errornum == 3 then
  70.     term.clear()
  71.     term.setCursorPos(1,1)
  72.     print("Terminal lockout!")
  73.     print("Waiting for reset...")
  74.     state = 2
  75.   break
  76.  end
  77. end
  78.  
  79. while state == 2 do
  80.   reset = rs.getInput("back")
  81.  
  82.    if reset == true then
  83.       state = 0
  84.       errornum = 0
  85.    
  86.    else
  87.      sleep(1)
  88.    end
  89.   end
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement