Can someone help me with my logging script?

Page:1  

  • Forsaken

    I'm trying to create a plugin that logs players on connect. This is what I have, but I'm just starting out with this... xD function LogPlayer_OnClientConnect(player,name,reset,channelId) local player=g_gameRules.game:GetPlayerByChannelId(tonumber(channelId)); local profileId=player.profile; local host=player.host; if(player)then if(profileId~=nil)then local f,err=io.open(SafeWriting.GlobalStorageFolder.."PlayerLog.txt","a+"); if(f)then f:seek("end"); f:write("Connection: "..player:GetName().."["..player.profile..","..player.host.."] \n"); for i,v in pairs({profileId})do f:write(" "..i..". - "..tostring(v).."\n"); end f:close(); end end end end SafeWriting.FuncContainer:AddFunc(LogPlayer_OnClientConnect,"ClientConnect");

    ❤️ 0
  • Forsaken

    Here's the plugin, Enjoy! (and thanks to the people who helped) I hope someone else can find this useful. This script does log player connections on map change, not sure how I can fix that... However I haven't tested if it logs disconnects on map change. LogConnections={Enabled=true;}; LogDisconnect={Enabled=true;}; if LogConnections.Enabled then function LogConnections:CheckPlayer(player) local f,err=io.open(SafeWriting.GlobalStorageFolder.."PlayerConnections.txt","a+"); if(f)then f:seek("end"); f:write("Connection: "..player:GetName().."["..os.date("%d.%m.%Y-%H:%M:%S")..","..player.profile..","..player.host..","..player.ip.."] n"); f:close(); end end end if LogDisconnect.Enabled then function LogDisconnect:OnClientDisconnect(player) local f,err=io.open(SafeWriting.GlobalStorageFolder.."PlayerConnections.txt","a+"); if(f)then f:seek("end"); f:write("Disconnect: "..player:GetName().."["..os.date("%d.%m.%Y-%H:%M:%S")..","..player.profile..","..player.ip.."] n"); f:close(); end end end SafeWriting.FuncContainer:LoadPlugin(LogConnections); SafeWriting.FuncContainer:LoadPlugin(LogDisconnect); AddChatCommand("connections",function(self,player) local f,err= io.open(SafeWriting.GlobalStorageFolder.."PlayerConnections.txt","r") for line in f:lines() do Console:SendToTarget(player, line) end f:close() end,{PLAYER,TEXT},{AdminModOnly=true;},"Shows connection log");

    ❤️ 0
Page:1