Guest User

scan

a guest
May 27th, 2015
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. scanner = peripheral.wrap("left")
  2. timeInterval = 1
  3. logOutputFile = "playerLog"
  4. newLogTitle = "New logging session started."
  5.  
  6. time = {m = -timeInterval, h = 0, d = 0}
  7.  
  8. while true do
  9.  
  10.   players = scanner.getPlayers()
  11.   time.m = time.m + timeInterval
  12.  
  13.   if time.m > 60 then time.m = time.m - 60 time.h = time.h + 1 end
  14.  
  15.   if time.h > 24 then time.h = time.h - 24 time.d = time.d + 1 end
  16.  
  17.   function logger(input, title)
  18.  
  19.     logFile = fs.open(logOutputFile,"a")
  20.     log = input
  21.    
  22.     if title == false then
  23.       log = "[" .. tostring(time.m) .. "/" .. tostring(time.h) .. "/" .. tostring(time.d) .. "] " .. input
  24.     end
  25.    
  26.     print(log)
  27.     logFile.writeLine(log)
  28.     logFile.close()
  29.   end
  30.  
  31.   if players[1] == nil and time.m == 0 then logger("Nobody is here.", false) end
  32.  
  33.   if time.m == 0 and time.h == 0 and time.d == 0 then logger("\n" .. newLogTitle, true) end
  34.  
  35.   for i=1,#players do
  36.     for key,value in pairs(players[i]) do
  37.       if key == "name" and value ~= nil then
  38.  
  39.         logger(value, false)
  40.      
  41.       end
  42.     end
  43.   end
  44.   sleep(timeInterval * 60)
  45. end
Advertisement
Add Comment
Please, Sign In to add comment