Raised This Month: $209 Target: $400
 52% 

Disconnect Reason


Post New Thread Reply   
 
Thread Tools Display Modes
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 01-08-2020 , 11:22   Re: Disconnect Reason
Reply With Quote #91

Quote:
Originally Posted by LithuanianJack View Post
How can I do that only admins (ADMIN_BAN) would be notified about player's disconnect?
Unrelated, but try this:
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <geoip>

// DON'T INCLUDE EXTENSION IN FILE NAME FOR WAV FILES !!!
new const g_szConnectSound[] = "sound/buttons/blip1";
//new g_szConnectSoundV[] = "sound/buttons/bell1";
new const g_szDisconnectSound[] = "sound/buttons/blip2";

new 
g_bConnectSoundIsMp3g_bDisconnectSoundIsMp3;//, g_bConnectSoundVIsMp3

new g_iMaxPlayersFloat:g_fTimeConnect[33], g_szIP[33][16], g_szName[33][31], g_szAuthID[33][45], g_szCountry[33][46], g_szShortCountry[33][4];

// Determine whether we're using new geoip with cities or not
#if defined SYSTEM_METRIC
new g_szCity[33][64];
#endif

#if AMXX_VERSION_NUM <= 182
enum (+= 33)
{
    
g_iIDTaskCheckConnected 32
}
#endif

public plugin_precache()
{
    new 
szTemp[128];
    
    if (
containi(g_szConnectSound".mp3") == -1)
    {
        
formatex(szTempcharsmax(szTemp), "%s.wav"g_szConnectSound)
        
precache_generic(szTemp)
    }
    else
    {
        
g_bConnectSoundIsMp3 1;
        
precache_generic(g_szConnectSound)
    }
/*    
    if (containi(g_szConnectSoundV, ".mp3") == -1)
    {
        formatex(szTemp, charsmax(szTemp), "%s.wav", g_szConnectSoundV)
        precache_generic(szTemp)
    }
    else
    {
        g_bConnectSoundVIsMp3 = 1;
        precache_generic(g_szConnectSoundV)
    }*/
    
    
if (containi(g_szDisconnectSound".mp3") == -1)
    {
        
formatex(szTempcharsmax(szTemp), "%s.wav"g_szDisconnectSound)
        
precache_generic(szTemp)
    }
    else
    {
        
g_bDisconnectSoundIsMp3 1;
        
precache_generic(g_szDisconnectSound)
    }
}

public 
plugin_init()
{
    
register_plugin("D7 Connect Messages""1.3.9""D i 5 7 i n c T")
    
    
register_forward(FM_ClientUserInfoChanged"fwFmClientUserInfoChanged"1)
    
    
g_iMaxPlayers get_maxplayers()
}

public 
client_connect(iID)
{
    
g_szIP[iID] = "";
    
    if (
is_user_bot(iID))
        return;
    
    
g_fTimeConnect[iID] = get_gametime();
}

#if AMXX_VERSION_NUM <= 182
public fwTaskCheckConnected(iID)
{
    
iID -= g_iIDTaskCheckConnected;
    
    if (!
is_user_connected(iID))//!is_user_connecting(iID) && 
    
{
        
client_disconnect(iID)
        
        return;
    }
}
#endif

public client_putinserver(iID)
{
    if (
is_user_bot(iID))
        return;
    
    
get_user_name(iIDg_szName[iID], charsmax(g_szName[]))
    
get_user_ip(iIDg_szIP[iID], charsmax(g_szIP[]), 1)
    
get_user_authid(iIDg_szAuthID[iID], charsmax(g_szAuthID[]))
    
geoip_country(g_szIP[iID], g_szCountry[iID])
    
geoip_code3_ex(g_szIP[iID], g_szShortCountry[iID])
    
    
#if defined SYSTEM_METRIC
    
geoip_city(g_szIP[iID], g_szCity[iID], charsmax(g_szCity[]))
    
    if (!
g_szCity[iID][0] || equali(g_szCity[iID], "error"))
        
g_szCity[iID] = "?";
    
    
#endif
    
if (!g_szCountry[iID][0] || equali(g_szCountry[iID], "error"))
    {
        
g_szCountry[iID] = "?";
        
g_szShortCountry[iID] = "?";
    }
    
    
g_fTimeConnect[iID] = get_gametime() - g_fTimeConnect[iID];
    
    
remove_task(iID)
    
set_task(3.0"fwTaskShowConnectMessage"iID)
    
    
#if AMXX_VERSION_NUM <= 182
    
set_task(0.1"fwTaskCheckConnected"iID g_iIDTaskCheckConnected__"b")
    
#endif
}

public 
fwFmClientUserInfoChanged(const iID)//, const iIDBuffer
{
    if (!(
<= iID <= g_iMaxPlayers) || !g_szIP[iID][0])
        return;
    
    
get_user_name(iIDg_szName[iID], charsmax(g_szName[]))
}

public 
fwTaskShowConnectMessage(const iID)
{
    
//new iVIP = (get_user_flags(iID) & read_flags("v"))
    
    //for (new i = 1; i <= g_iMaxPlayers; i++)
    //{
    #if defined SYSTEM_METRIC
    
ftClientPrintChatColor(0iID"^3%s ^1connected in ^4%.2f^1 seconds from ^4%s^1, ^4%s^1(^4%s^1)",//"%s
    
g_szName[iID], g_fTimeConnect[iID], g_szCity[iID], g_szCountry[iID], g_szShortCountry[iID])//!iVIP ? "" : "^4VIP ", 
    
client_cmd(0"%s ^"%s^""g_bConnectSoundIsMp3 "mp3 play" "spk"g_szConnectSound)//, !iVIP ? g_szConnectSound : g_szConnectSoundV
    #else
    
ftClientPrintChatColor(0iID"^3%s ^1connected in ^4%.2f^1 seconds from ^4%s^1(^4%s^1)",//"%s
    
g_szName[iID], g_fTimeConnect[iID], g_szCountry[iID], g_szShortCountry[iID])//!iVIP ? "" : "^4VIP ", 
    
client_cmd(0"%s ^"%s^""g_bConnectSoundIsMp3 "mp3 play" "spk"g_szConnectSound)//, !iVIP ? g_szConnectSound : g_szConnectSoundV
    #endif
    //}
}

#if AMXX_VERSION_NUM <= 182
public client_disconnect(iID)
#else
public client_disconnected(iID)
#endif
{
    
remove_task(iID)
    
    if (
is_user_bot(iID) || !g_szIP[iID][0])
        return;
    
    
//new iVIP = (get_user_flags(iID) & read_flags("v"))
    
    //ftClientPrintChatColor(0, iID, "^3%s ^1[^4%s^1][^4%s^1][^4%s^1] dropped(^3%s^1)",
    //g_szName[iID], szAuthID, g_szIP[iID], g_szCountry[iID], g_szActions[g_iAction[iID]]) //, g_szAuthID[iID]
    //%s , !iVIP ? "" : "^4VIP "
    
    #if defined SYSTEM_METRIC
    
ftClientPrintChatColor(0iID"^3%s ^1from ^4%s^1, ^4%s^1(^4%s^1) disconnected."g_szName[iID], g_szCity[iID], g_szCountry[iID], g_szShortCountry[iID])
    
#else
    
ftClientPrintChatColor(0iID"^3%s ^1from ^4%s^1(^4%s^1) disconnected."g_szName[iID], g_szCountry[iID], g_szShortCountry[iID])
    
#endif
    
    
for (new 1<= g_iMaxPlayersi++)
    {
        
client_cmd(i"%s ^"%s^""g_bDisconnectSoundIsMp3 "mp3 play" "spk"g_szDisconnectSound)
        
        if (
get_user_flags(i) & ADMIN_BAN)
        {
            
client_print(iprint_console"---------------------------------------------------------------------------")
            
            
#if defined SYSTEM_METRIC
            
client_print(iprint_console"^"%s^" ^"%s^" ^"%s^" ^"%s, %s(%s)^" disconnected."g_szName[iID],
            
g_szAuthID[iID], g_szIP[iID], g_szCity[iID], g_szCountry[iID], g_szShortCountry[iID])
            
#else
            
client_print(iprint_console"^"%s^" ^"%s^" ^"%s^" ^"%s(%s)^" disconnected."g_szName[iID],
            
g_szAuthID[iID], g_szIP[iID], g_szCountry[iID], g_szShortCountry[iID])
            
#endif
            
            
client_print(iprint_console"---------------------------------------------------------------------------")
        }
    }
    
    
g_szIP[iID] = "";
    
    
#if AMXX_VERSION_NUM <= 182
    
remove_task(iID g_iIDTaskCheckConnected)
    
#endif
}

ftClientPrintChatColor(const iIDTarget 0, const iIDSender 0, const szMessage[], any:...)
{
    if (
iIDTarget && !is_user_connected(iIDTarget))
        return;
    
    static 
szBuffer[192];
    
vformat(szBuffercharsmax(szBuffer), szMessage4)
    
    static const 
szChatTag[] = "^1[^4D7^1] ";
    
format(szBuffercharsmax(szBuffer), "%s%s"szChatTagszBuffer)
    
    static 
iIDMsgSayText;
    if (!
iIDMsgSayText)
        
iIDMsgSayText get_user_msgid("SayText");
    
    if (
iIDTarget)
        
message_begin(MSG_ONEiIDMsgSayText_iIDTarget)
    else
        
message_begin(MSG_ALLiIDMsgSayText)
    
    
write_byte(!iIDSender iIDTarget iIDSender)
    
write_string(szBuffer)
    
message_end()

Attached Files
File Type: sma Get Plugin or Get Source (D7(Dis)connectMessages.sma - 39 views - 6.4 KB)
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-08-2020 , 21:12   Re: Disconnect Reason
Reply With Quote #92

This plugin is no longer needed if you are running AMX-X 1.9. client_disconnected() provides the same functionality.

PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init() 
{
    
register_plugin"Notify Admin on Disconnect" "0.1" "bugsy" );
}

public 
client_disconnectedid bool:bDrop , const szMsg[] , )
{
    new 
iPlayers32 ] , iNum iPlayer szName32 ];
    
    
get_players_exiPlayers iNum GetPlayers_ExcludeBots GetPlayers_ExcludeHLTV );
    
get_user_nameid szName charsmaxszName ) );
    
    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        if ( 
get_user_flagsiPlayer ) & ADMIN_BAN )
        {
            
client_printiPlayer print_chat "* %s disconnected [%s]" szName szMsg] == EOS "N\A" szMsg );
        }
    }

If you do not want to run 1.9
PHP Code:
#include <amxmodx>

new const Version[] = "0.1";

public 
plugin_init() 
{
    
register_plugin"Disconnect Reason Example" Version "bugsy" );
}

public 
client_disconnect_reasonid ReasonCodes:drReason , const szReason[] )
{
    new 
iPlayers32 ] , iNum iPlayer szName32 ];
    
    
get_playersiPlayers iNum "ch" );
    
get_user_nameid szName charsmaxszName ) );
    
    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        if ( 
get_user_flagsiPlayer ) & ADMIN_BAN )
        {
            
client_printiPlayer print_chat "* %s disconnected [%s]" szName szReason] == EOS "N\A" szReason );
        }
    }
    

__________________

Last edited by Bugsy; 01-08-2020 at 22:13.
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 01-08-2020 , 22:02   Re: Disconnect Reason
Reply With Quote #93

Quote:
Originally Posted by Bugsy View Post
This plugin is no longer needed if you are running AMX-X 1.9. client_disconnected() provides the same functionality.
In some tests performed the disconnect message is only written when the bool:drop is true, so I think there should be a check before.
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-08-2020 , 22:07   Re: Disconnect Reason
Reply With Quote #94

Quote:
Originally Posted by iceeedr View Post
In some tests performed the disconnect message is only written when the bool:drop is true, so I think there should be a check before.
Can do

client_print( iPlayer , print_chat , "* %s disconnected [%s]" , szName , szReason[ 0 ] == EOS ? "N\A" : szReason );
__________________
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 01-08-2020 , 22:09   Re: Disconnect Reason
Reply With Quote #95

Of course! I'm just punctuating a situation. Thank's.
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 01-14-2020 , 12:50   Re: Disconnect Reason
Reply With Quote #96

Quote:
Originally Posted by Bugsy View Post
This plugin is no longer needed if you are running AMX-X 1.9. client_disconnected() provides the same functionality.

PHP Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init() 
{
    
register_plugin"Notify Admin on Disconnect" "0.1" "bugsy" );
}

public 
client_disconnectedid bool:bDrop , const szMsg[] , )
{
    new 
iPlayers32 ] , iNum iPlayer szName32 ];
    
    
get_players_exiPlayers iNum GetPlayers_ExcludeBots GetPlayers_ExcludeHLTV );
    
get_user_nameid szName charsmaxszName ) );
    
    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        if ( 
get_user_flagsiPlayer ) & ADMIN_BAN )
        {
            
client_printiPlayer print_chat "* %s disconnected [%s]" szName szMsg] == EOS "N\A" szMsg );
        }
    }

If you do not want to run 1.9
PHP Code:
#include <amxmodx>

new const Version[] = "0.1";

public 
plugin_init() 
{
    
register_plugin"Disconnect Reason Example" Version "bugsy" );
}

public 
client_disconnect_reasonid ReasonCodes:drReason , const szReason[] )
{
    new 
iPlayers32 ] , iNum iPlayer szName32 ];
    
    
get_playersiPlayers iNum "ch" );
    
get_user_nameid szName charsmaxszName ) );
    
    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        if ( 
get_user_flagsiPlayer ) & ADMIN_BAN )
        {
            
client_printiPlayer print_chat "* %s disconnected [%s]" szName szReason] == EOS "N\A" szReason );
        }
    }
    

Tried to use second code on server with 1.8.3 version, but it's not printing to admins.
LithuanianJack is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-14-2020 , 17:26   Re: Disconnect Reason
Reply With Quote #97

@LithuanianJack - you can probably still use the first code in 1.8.3. The 1.9 version is just a newer build of 1.8.3, so you should update it either way.

The second code is missing the forward declaration.

Code:
enum ReasonCodes {     DR_TIMEDOUT,     DR_DROPPED,     DR_KICKED,     DR_LEVELCHANGE,     DR_OTHER } forward client_disconnect_reason( id , ReasonCodes:drReason , const szReason[] )
__________________

Last edited by OciXCrom; 01-14-2020 at 17:28.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
666
Senior Member
Join Date: Mar 2015
Old 01-22-2020 , 12:11   Re: Disconnect Reason
Reply With Quote #98

I want to send a message to all players, but the message is not sent and this error comes out: (Run time error 5: memory access)

ERROR LINE
PHP Code:
client_print_color(Player,print_team_red,"%s Disconnected [%s]",Namemessage] == EOS "N\A" message); 
USE AMX 190
PHP Code:
public client_disconnected(idbool:dropmessage[], maxlen)
{
    new 
Name[MAX_NAME_LENGTH];
    
get_user_name(id,Name,charsmax(Name));
    
    new 
Players[MAX_PLAYERS],Player,Num;
    
get_players_ex(Players,Num,GetPlayers_ExcludeBots|GetPlayers_ExcludeHLTV);
    
    for (new 
i;Numi++)
    {
        
Player Players[i];
        
        
client_print_color(Player,print_team_red,"%s Disconnected [%s]",Namemessage] == EOS "N\A" message);
    }

__________________
666 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-22-2020 , 18:57   Re: Disconnect Reason
Reply With Quote #99

Try this
PHP Code:
client_print_color(Player,print_team_red,"%s Disconnected [%s]",Name, !strlenmessage ) ? "N\A" message); 
__________________
Bugsy is offline
666
Senior Member
Join Date: Mar 2015
Old 01-22-2020 , 19:42   Re: Disconnect Reason
Reply With Quote #100

Quote:
Originally Posted by Bugsy View Post
Try this
PHP Code:
client_print_color(Player,print_team_red,"%s Disconnected [%s]",Name, !strlenmessage ) ? "N\A" message); 
Now no error occurs but the message is displayed like this, as incomplete

PHP Code:
666 Disconnected 
__________________
666 is offline
Reply


Thread Tools
Display Modes

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 07:08.


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