Is there an event for when a player drops his connection to the server?
3 replies, posted
Hey everyone,
I've gone through the wiki and I've looked for an event that is being called when a user decides to drop his connection to the server (clicking 'cancel' while connecting to the server). I've noticed there a GM:PlayerDisconnected event, however it only applies for when a user has disconnected from the server [U]after[/U] loading into it.
So I was wondering if there's any event I can hook to fetch if a user is no longer trying to connect to the server and has dropped his connection (like GM:PlayerConnect is being called when the user begins to connect to the server, despite not being fully loaded in). If not, if there's any way I could fetch that event in any other way?
You can try player_disconnect; not sure how it's triggered as compared to PlayerDisconnected: [url]http://wiki.garrysmod.com/page/Game_Events[/url]
afaik, no, you can only check if the player passed being authed/password, else I dont think so.
[editline]22nd August 2015[/editline]
Ninja >-<
[editline]22nd August 2015[/editline]
Wiki sez:
[B]This is a basic template for creating game_event listeners/hooks with the purpose of including all arguments / table variables for each game-event to make it easily known which values can be accessed and when: player_disconnect. player_disconnect is triggered at the exact moment they disconnect from the server and will ALWAYS trigger regardless of whether they time-out, are kick/banned, client crashes, they click the X, they type quit in console, etc...[/B]
[code]
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 )
[/code]
Awesome, thank you very much guys!
I've tested it and indeed player_disconnect gameevent is a lot more reliable than PlayerDisconnected.
Sorry, you need to Log In to post a reply to this thread.