Nyaar

[CC] Password Protected Door

Jun 6th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. local password=""  -- Change this to your password
  2. local side="right" -- Change this to the side the door is on
  3. local debugPass="" -- Change this to a password for getting into the OS
  4. local lockKey=38   -- This is the key pressed to lock the door, 38 = L
  5. local sLockKey="L" -- Displays the key you should press
  6. local title="Password Protected Door"     -- Change this to the name of the door (title)
  7.  
  8. -- PASSWORD PROTECTED DOOR
  9. -- Version: 1.6
  10. -- Code by: Nyaar
  11. -- Notes: Make sure you create a
  12. --        password but don't edit
  13. --        anything below this line.
  14.  
  15. local w,h = term.getSize()
  16.  
  17. function printC(str, y)
  18.  term.setCursorPos(1,y)
  19.  term.clearLine()
  20.  term.setCursorPos(w/2 - #str/2, y)
  21.  term.write(str)
  22. end
  23.  
  24. function printLR(str, y)
  25.  term.setCursorPos(1,y)
  26.  term.clearLine()
  27.  term.setCursorPos(w/2 - #str/2, y)
  28.  term.write(str)
  29.  term.setCursorPos(1,y)
  30.  write("|")
  31.  term.setCursorPos(w-1,y)
  32.  write("|")
  33. end
  34.  
  35. function printLB(str, y)
  36.  term.setCursorPos(1, y)
  37.  print(string.rep(str, w-1))
  38. end
  39.  
  40. term.clear()
  41. term.setCursorPos(1,1)
  42. printLB("=",1)
  43. printLR(" ",2)
  44. printLR(title,3)
  45. printLR("Status: Locked",4)
  46. printLR(" ",5)
  47. printLB("=",6)
  48. print("")
  49. write("            Password: ")
  50. local status, input = pcall(read,"*")
  51. if (input == password) then
  52.  rs.setOutput(side,true)
  53.  printLR("Status: Unlocked", 4)
  54.  printC("Press "..sLockKey.." to lock.", 8)
  55.  while(true) do
  56.   local sEvent, param = os.pullEventRaw("key")
  57.    if (sEvent == "key") then
  58.     if (param == lockKey) then
  59.      os.reboot()
  60.      break
  61.     end
  62.    end
  63.  end
  64. elseif (input == debugPass) then
  65.  term.clear()
  66.  term.setCursorPos(1,1)
  67.  print("CraftOS 1.3")
  68. else
  69.  os.reboot()
  70. end
Advertisement
Add Comment
Please, Sign In to add comment