DiabolusNeil

[DiabolusNeil] Player Detector Activated Door

Jun 22nd, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. -- DiabolusNeil's Player Detected Door Lock | CC 1.53
  2. -- Requires MiscPeripherals Player Detector touching the computer
  3.  
  4. local player
  5. local event
  6. local state
  7.  
  8. -- Changeable variables
  9. local dside = "left" -- Door Side
  10. local dtime = 4 -- Seconds door is open
  11. local reference = "permissions" -- Name of program that holds all allowed names
  12.  
  13. function clear()
  14.     term.clear()
  15.     term.setCursorPOs(1,1)
  16. end
  17.  
  18. function reset()
  19.     player = ""
  20.     state = false
  21. end
  22.  
  23. function openDoor(side, time)
  24.     rs.setOutput(fside, true)
  25.     sleep(ftime)
  26.     rs.setOutput(fside, false)
  27. end
  28.  
  29. function wait()
  30.     event, player = os.pullEvent("player")
  31.     print(player)
  32. end
  33.  
  34. function interpet(refer)
  35.     file = io.open(refer, "r")
  36.     if file ~= null then
  37.         for line in file:lines() do
  38.             if name == line then
  39.                 state = true
  40.             end
  41.         end
  42.     end
  43. end
  44.  
  45. function run()
  46.     if state == true then
  47.         print("You are allowed to enter.\n")
  48.         openDoor(dside, dtime)
  49.     else
  50.         print("You are not allowed to enter.\n")
  51.         sleep(2)
  52.     end
  53. end
  54.  
  55. -- Actual Program
  56. clear()
  57. while true do
  58.     write("Player Detected: ")
  59.     reset()
  60.     wait()
  61.     interpet(reference)
  62.     run()
  63. end
Advertisement
Add Comment
Please, Sign In to add comment