ErolDude

ssdsdsdsdsdds

Apr 15th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. -- Basic keycard lock by Lymia
  2. -- Released to the public domain
  3.  
  4. -- Clears the terminal
  5. term.clear()
  6. term.setCursorPos(1,1)
  7.  
  8. -- What file to look for the password in
  9. local keyFile = "lockFile"
  10. -- The password to look for
  11. local keyContents = "12345"
  12. -- What side to output the door signal to
  13. local outputSide = "left"
  14.  
  15. while true do
  16. -- Get raw event data
  17. local rawEvent = {coroutine.yield()}
  18. local event = rawEvent[1]
  19. if event == "disk" then
  20. local side = rawEvent[2]
  21.  
  22. -- Check if this is a data disk
  23. if disk.isPresent(side) and disk.hasData(side) then
  24. -- And if so, try to open the lock file
  25. local file = "/"..disk.getMountPath(side).."/"..keyFile
  26. file = fs.open(file,"r")
  27. if file then
  28. file = file.readAll()
  29.  
  30. if file == keyContents then
  31. print("Keyfile accepted!")
  32. -- Send the door signal...
  33. rs.setOutput(outputSide,true)
  34. -- Send a "timer" event after 4 seconds
  35. -- I could use sleep here, but, this way, I can still process disk
  36. -- events while the redstone signal is on.
  37. os.startTimer(4)
  38. else
  39. print("Invalid keyfile")
  40. end
  41. else
  42. -- Guess the lockfile's not there
  43. print("Keyfile not found")
  44. end
  45. else
  46. print("Keyfile not found")
  47. end
  48.  
  49. -- And now, eject the disk
  50. disk.eject(side)
  51. elseif event == "timer" then
  52. -- This follows the timer set up in the lock checking code.
  53. -- Unset the door signal.
  54. rs.setOutput(outputSide,false)
  55. elseif event == "terminate" then
  56. -- Prevents Ctrl-T (It would be ignored otherwise anyways, but...)
  57. print("[termination intercepted]")
  58. end
  59. end
Add Comment
Please, Sign In to add comment