Advertisement
theinsekt

mydoorlock

Sep 8th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. --simple door lock
  2. --pastebin get NV4DJYdf startup
  3. --change the values under the comment "change these values"
  4. --name this program startup, then restart the computer
  5.  
  6. --inspired/copied by/from
  7. --http://computercraft.info/wiki/Making_a_Password_Protected_Door
  8.  
  9. --"change these values"
  10. local side = "default1"
  11. local password = "password1"
  12. local openTime = 5
  13. local adminPassword="admin1"
  14. local adminTime= 10
  15.  
  16. --make copy of os.pullevent
  17. local pullEventCopy = os.pullEvent
  18.  
  19. --make it so that the program can't be terminated by
  20. -- holding ctrl-t
  21. os.pullEvent = os.pullEventRaw
  22.  
  23. --check that adminPassword and password aren't the same
  24. --and aren't the default values
  25. local hasErrors=false
  26. if(adminPassword==password) then
  27.  print("Unresolved: The adminPassword can't be the same as the password")
  28.  hasErrors=true
  29. end
  30. if(adminPassword=="admin") then
  31.  print("Unresolved: The adminPassword has to be changed")
  32.  hasErrors=true
  33. end
  34. if(password=="password") then
  35.  print("Unresolved: The password has to be changed")
  36.  hasErrors=true
  37. end
  38. if(side=="default") then
  39.  print("Unresolved: The side hasn't been configured")
  40.  hasErrors=true
  41. end
  42. if hasErrors then
  43.  print("edit the file to change these values.")
  44.  error("Exited")
  45. end
  46.  
  47.  
  48.  
  49.  
  50. while true do
  51.  term.clear()
  52.  term.setCursorPos(1, 1)
  53.  print("Password:")
  54.  input = read("*")
  55.  if input == password then --password
  56.   print("Correct!")
  57.   redstone.setOutput(side, true)
  58.   sleep(openTime)
  59.   redstone.setOutput(side, false)
  60.  elseif input==adminPassword then --admin
  61.   os.pullEvent = pullEventCopy--enable ctrl-t
  62.   print("Hold ctrl-t to enter admin mode.")
  63.   sleep(adminTime)
  64.   os.pullEvent = os.pullEventRaw--disable ctrl-t
  65.  else --fail
  66.   print("Incorrect!")
  67.   sleep(2)
  68.  end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement