Guest User

Untitled

a guest
May 1st, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. -- the table below stores a list of players to allow access to
  2. -- make sure that all usernames in this list are LOWERCASE!
  3. local whitelist = {
  4.   ['plazter'] = true,
  5.   ['hybridanden'] = true,
  6.   ['alternatelogic'] = true,
  7.   ['theoriginalbit'] = true,
  8.   ['randomguy123'] = true,
  9.   ['suicidalstdz'] = true,
  10. }
  11.  
  12. -- a file stored on the computer so you can check out activity of people coming and going, make sure you put a disk drive so it can save it out
  13. local logFile = fs.open('/disk/log', 'w')
  14. -- the side to output the redstone
  15. local rsSide = 'bottom'
  16.  
  17. -- a log function, this prints to the screen and also writes to the file.
  18. local function log(msg)
  19.   print(msg)
  20.   logFile.write(msg..'\n')
  21.   logFile.flush()
  22. end
  23.  
  24. -- clear the screen
  25. term.clear()
  26. term.setCursorPos(1,1)
  27.  
  28. -- start a new log, so you can easily tell when the computer has been restarted or whatever
  29. log('======== New Log - Day: '..os.day()..' Time: '..textutils.formatTime(os.time())..' ========')
  30.  
  31. while true do
  32.   -- wait for the player event
  33.   local event, p1 = os.pullEvent('player')
  34.   -- make the player name lowercase for checking if it exists in the whitelist table
  35.   if whitelist[ p1:lower() ] then
  36.     -- log the player has entered
  37.     log('Player: '..p1..' entered!')
  38.     -- open the door
  39.     rs.setOutput(rsSide, true)
  40.     -- this line and the line below are a termination safe sleep call
  41.     os.startTimer(2)
  42.     os.pullEvent('timer')
  43.     -- close the door
  44.     rs.setOutput(rsSide, false)
  45.   else
  46.     -- log that it was unauthorized and their name
  47.     log('Unauthorized player attempted access: '..p1)
  48.   end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment