Advertisement
william200027

Detect

May 13th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. scanner = peripheral.wrap("left")
  2.  
  3. timeInterval = 1
  4.  
  5. logOutputFile = "playerLog"
  6.  
  7. newLogTitle = "New logging session started."
  8.  
  9.  
  10.  
  11. time = {m = -timeInterval, h = 0, d = 0}
  12.  
  13.  
  14.  
  15. while true do
  16.  
  17.  
  18.  
  19.   players = scanner.getPlayers()
  20.  
  21.   time.m = time.m + timeInterval
  22.  
  23.  
  24.  
  25.   if time.m >= 60 then
  26.  
  27.     time.m = time.m - 60
  28.  
  29.     time.h = time.h + 1
  30.  
  31.     if players[1] == nil then logger("Nobody is here.", false) end
  32.  
  33.   end
  34.  
  35.  
  36.  
  37.   if time.h >= 24 then time.h = time.h - 24 time.d = time.d + 1 end
  38.  
  39.  
  40.  
  41.   function logger(input, title)
  42.  
  43.  
  44.  
  45.     logFile = fs.open(logOutputFile,"a")
  46.  
  47.     log = input
  48.  
  49.    
  50.  
  51.     if title == false then
  52.  
  53.       log = "[" .. tostring(time.m) .. "/" .. tostring(time.h) .. "/" .. tostring(time.d) .. "] " .. input
  54.  
  55.     end
  56.  
  57.    
  58.  
  59.     print(log)
  60.  
  61.     logFile.writeLine(log)
  62.  
  63.     logFile.close()
  64.  
  65.   end
  66.  
  67.  
  68.  
  69.   if time.m == 0 and time.h == 0 and time.d == 0 then logger("\n" .. newLogTitle, true) end
  70.  
  71.  
  72.  
  73.   for i=1,#players do
  74.  
  75.     for key,value in pairs(players[i]) do
  76.  
  77.       if key == "name" and value ~= nil then
  78.  
  79.  
  80.  
  81.         logger(value, false)
  82.  
  83.      
  84.  
  85.       end
  86.  
  87.     end
  88.  
  89.   end
  90.  
  91.   print("------------------------")
  92.  
  93.   sleep(timeInterval * 10)
  94.  
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement