Raised This Month: $51 Target: $400
 12% 

Solved [L4D2] disconnect message


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tank Rush
Senior Member
Join Date: May 2019
Location: Argentina
Old 10-09-2021 , 14:44   [L4D2] disconnect message
Reply With Quote #1

What this plugin does is print a message in the chat when the player leaves the server.
The problem is that when a player connects to the server and takes control of a surviving bot, the message is printed as if the bot had left the game, the same happens when you are on the infected team and you switch to survivors.

Here is a video demonstration

Here the source code
How can i repair it?
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <multicolors>

public Plugin:myinfo 
{
    
name         "New Disconnect Message",
    
author         "Leonardo",
    
description "N/A",
    
version     "1.1",
    
url         "https://forums.alliedmods.net/showpost.php?p=1424584&postcount=7"
};

public 
OnPluginStart()
{
    
HookEvent("player_disconnect"PlayerDisconnect_EventEventHookMode_Pre);
}

public 
Action:PlayerDisconnect_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client;
    new 
clientid;
    new 
String:nick[64];
    
clientid GetEventInt(event,"userid");
    
client GetClientOfUserId(clientid);
    if(
client <= || client MaxClients || !IsClientInGame(client) || !GetClientName(clientnicksizeof(nick)))
        
Format(nick,sizeof(nick),"%d",clientid);
        
    new 
String:reason[64];
    new 
String:message[64];
    
GetEventString(event"reason"reasonsizeof(reason));
    
//PrintToServer("%s - %s",nick,reason);
    
    
if(StrContains(reason"connection rejected"false) != -1)
    {
        
Format(message,sizeof(message),"connection rejected");
    }
    else if(
StrContains(reason"timed out"false) != -1)
    {
        
Format(message,sizeof(message),"timed out");
    }
    else if(
StrContains(reason"by console"false) != -1)
    {
        
Format(message,sizeof(message),"console");
    }
    else if(
StrContains(reason"by user"false) != -1)
    {
        
Format(message,sizeof(message),"disconnect by user");
    }
    else if(
StrContains(reason"ping is too high"false) != -1)
    {
        
Format(message,sizeof(message),"ping is too high");
    }
    else if(
StrContains(reason"No Steam logon"false) != -1)
    {
        
Format(message,sizeof(message),"no steam logon");
    }
    else if(
StrContains(reason"Steam account is being used in another"false) != -1)
    {
        
Format(message,sizeof(message),"steam account is being used");
    }
    else if(
StrContains(reason"Steam Connection lost"false) != -1)
    {
        
Format(message,sizeof(message),"steam connection lost");
    }
    else if(
StrContains(reason"This Steam account does not own this game"false) != -1)
    {
        
Format(message,sizeof(message),"does not own this game");
    }
    else if(
StrContains(reason"Validation Rejected"false) != -1)
    {
        
Format(message,sizeof(message),"validation rejected");
    }
    else if(
StrContains(reason"Certificate Length"false) != -1)
    {
        
Format(message,sizeof(message),"certificate length");
    }
    else if(
StrContains(reason"Pure server"false) != -1)
    {
        
Format(message,sizeof(message),"pure server");
    }
    else
    {
        
message reason;
        
// ReplaceString(message,sizeof(message),"chr(10)","",false);
    
}
    
    
CPrintToChatAll("{red}[«] {green}%s {default}left the game - reason: [{red}%s{default}]"nickmessage);
    return 
Plugin_Handled;

__________________
Sorry i don't speak english very well

--->My name is Source and I'm on Steam<---
Discord: Source#9382

Last edited by Tank Rush; 10-09-2021 at 20:49.
Tank Rush is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-09-2021 , 17:05   Re: [L4D2] disconnect message
Reply With Quote #2

Try the following code:

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <multicolors>

public Plugin:myinfo =
{
    
name         "New Disconnect Message",
    
author         "Leonardo",
    
description "N/A",
    
version     "1.1",
    
url         "https://forums.alliedmods.net/showpost.php?p=1424584&postcount=7"
};

public 
OnPluginStart()
{
    
HookEvent("player_disconnect"PlayerDisconnect_EventEventHookMode_Pre);
}

public 
Action:PlayerDisconnect_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event,"userid"));

    if (!(
<= client <= MaxClients))
        return 
Plugin_Handled;

    if (!
IsClientInGame(client))
        return 
Plugin_Handled;

    if (
IsFakeClient(client))
        return 
Plugin_Handled;

    new 
String:reason[64];
    new 
String:message[64];
    
GetEventString(event"reason"reasonsizeof(reason));

    if(
StrContains(reason"connection rejected"false) != -1)
    {
        
Format(message,sizeof(message),"connection rejected");
    }
    else if(
StrContains(reason"timed out"false) != -1)
    {
        
Format(message,sizeof(message),"timed out");
    }
    else if(
StrContains(reason"by console"false) != -1)
    {
        
Format(message,sizeof(message),"console");
    }
    else if(
StrContains(reason"by user"false) != -1)
    {
        
Format(message,sizeof(message),"disconnect by user");
    }
    else if(
StrContains(reason"ping is too high"false) != -1)
    {
        
Format(message,sizeof(message),"ping is too high");
    }
    else if(
StrContains(reason"No Steam logon"false) != -1)
    {
        
Format(message,sizeof(message),"no steam logon");
    }
    else if(
StrContains(reason"Steam account is being used in another"false) != -1)
    {
        
Format(message,sizeof(message),"steam account is being used");
    }
    else if(
StrContains(reason"Steam Connection lost"false) != -1)
    {
        
Format(message,sizeof(message),"steam connection lost");
    }
    else if(
StrContains(reason"This Steam account does not own this game"false) != -1)
    {
        
Format(message,sizeof(message),"does not own this game");
    }
    else if(
StrContains(reason"Validation Rejected"false) != -1)
    {
        
Format(message,sizeof(message),"validation rejected");
    }
    else if(
StrContains(reason"Certificate Length"false) != -1)
    {
        
Format(message,sizeof(message),"certificate length");
    }
    else if(
StrContains(reason"Pure server"false) != -1)
    {
        
Format(message,sizeof(message),"pure server");
    }
    else
    {
        
message reason;
    }

    
CPrintToChatAll("{red}[«] {green}%N {default}left the game - reason: [{red}%s{default}]"clientmessage);
    return 
Plugin_Handled;

Attached Files
File Type: sp Get Plugin or Get Source (newdisconnect2.sp - 102 views - 2.8 KB)
__________________

Last edited by Marttt; 10-09-2021 at 20:30.
Marttt is offline
Tank Rush
Senior Member
Join Date: May 2019
Location: Argentina
Old 10-09-2021 , 20:49   Re: [L4D2] disconnect message
Reply With Quote #3

Thanks Marttt, this works
__________________
Sorry i don't speak english very well

--->My name is Source and I'm on Steam<---
Discord: Source#9382
Tank Rush is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:23.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode