Output Steam ID on leave.

I’m confused on how to do this.

Any help? I just need a simple code to say NICK - STEAM_0:XXX_XXX_XXX

So far…



hook.Add("PlayerDisconnect","What",function(ply,reason)


[lua]print(ply:Name()…" - “…ply:SteamID())
ServerLog(ply:Name()…” - "…ply:SteamID()) – If you want it to show up in logs and HLSW[/lua]

Also the hook is actually **[Gamemode.PlayerDisconnected

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerDisconnected)** and it doesn’t take a reason as a parameter.

[lua]
hook.Add(“PlayerDisconnected”, “PlayerDisconnect”, function(ply)
for _, v in pairs(player.GetAll()) do
v:ChatPrint(ply:Nick()…" - "…ply:SteamID())
end
end)
[/lua]

There is one problem left still, PlayerDisconnect is NOT reliable.

You may want to add a second hook.

[lua]hook.Add(“ChatText”, “DisconnectSteamID”,function(ply, _, _, type)
if(type == “joinleave”) then
for _, v in pairs(player.GetAll()) do
v:ChatPrint(ply:Nick()…" - "…ply:SteamID())
end
end
end);
[/lua]

What? You got it reverse, joinleave is the thing thats not reliable. It’s only called sometimes when the player disconnects, other times its not called at all and some player left without anyone noticing. The only thing that’s bad with PlayerDisconnected is that it’s impossible to find out the reason without another module (sourcenet for example).

I know this because I had to replace the disconnect messages with my own PlayerDisconnected hook since the default source one is not called all the time, with the disadvantage of not being able to tell the exact reason for disconnecting though.

[lua]
hook.Add(“EntityRemoved”, “show_steamid”, function(ent)
if ent:IsPlayer() then
chat.AddText(Color(255, 255, 255), string.format(“player %s left ( %s )”, ent:Nick(), ent:SteamID()))
end
end)
[/lua]

clientside

[editline]20th October 2011[/editline]

would only work if the player was in the server as an entity