Garry's Mod Wiki

player_disconnect

Description

Called when a player disconnects from the server.

This is also called when a player cancels connecting to the server.
This is not called clientside for the local player or in single-player.
When this gameevent is called on the client side, the player will be NULL!. so you cannot use Player(data.userid)!

Members

number bot
0 if the player isn't a bot, 1 if they are.
string networkid
The SteamID the player has. Will be BOT for bots and STEAM_0:0:0 in single-player.
string name
The name the player has.
number userid
The UserID the player has.
string reason
The disconnect reason.

Examples

Example

This is a basic template with the purpose of including all arguments / table variables to make it easily known which values can be accessed.

gameevent.Listen( "player_disconnect" ) hook.Add( "player_disconnect", "player_disconnect_example", function( data ) local name = data.name // Same as Player:Nick() local steamid = data.networkid // Same as Player:SteamID() local id = data.userid // Same as Player:UserID() local bot = data.bot // Same as Player:IsBot() local reason = data.reason // Text reason for disconnected such as "Kicked by console!", "Timed out!", etc... // Player has disconnected - this is more reliable than PlayerDisconnect end )