Thread: Country Chat
View Single Post
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-30-2009 , 14:13   Re: Country Chat
Reply With Quote #11

Your code is actually bad.

Here is a better version of the old one I made.

It now has cvars for allchat and such.

cc_say_all <0|1>
0 = Only use say to players that are alive/dead status same as yours
1 = Use say to everyone

cc_sayteam_all <0|1>
0 = Only use sayteam to teammates that are alive/dead status same as yours
1 = Use sayteam to all teammates

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

new const g_team_names[CsTeams][] =
{
    
"Spectator",
    
"Terrorist",
    
"Counter-Terrorist",
    
"Spectator"
};

new 
g_country_code[33][5];

new 
cvar_say_all;
new 
cvar_sayteam_all;

new 
g_msgid_SayText;

new 
g_max_clients;

public 
plugin_init()
{
    
register_plugin("Country Chat""0.1""Exolent");
    
    
register_clcmd("say""CmdSay");
    
register_clcmd("say_team""CmdTeamSay");
    
    
cvar_say_all register_cvar("cc_say_all""0");
    
cvar_sayteam_all register_cvar("cc_sayteam_all""0");
    
    
g_msgid_SayText get_user_msgid("SayText");
    
    
g_max_clients get_maxplayers();
    
    
GetCountryCode(0);
}

public 
client_putinserver(client)
{
    
GetCountryCode(client);
}

public 
CmdSay(client)
{
    new 
said[192];
    
read_args(saidsizeof(said) - 1);
    
remove_quotes(said);
    
    if( !
IsValidMessage(said) ) return PLUGIN_HANDLED;
    
    new 
name[32];
    
get_user_name(clientnamesizeof(name) - 1);
    
    new 
alive is_user_alive(client);
    
    new 
tag[9];
    if( 
cs_get_user_team(client) == CS_TEAM_SPECTATOR )
    {
        
copy(tagsizeof(tag) - 1"*SPEC* ");
    }
    else if( !
alive )
    {
        
copy(tagsizeof(tag) - 1"*DEAD* ");
    }
    
    new 
say_all get_pcvar_num(cvar_say_all);
    
    new 
message[192];
    
formatex(messagesizeof(message) - 1"^x01%s %s^x03 %s^x01 :  %s"g_country_code[client], tagnamesaid);
    
    for( new 
1<= g_max_clientsi++ )
    {
        if( 
== client
        
|| !is_user_connected(i)
        || 
say_all
        
|| is_user_alive(i) != alive ) continue;
        
        
message_begin(MSG_ONE_UNRELIABLEg_msgid_SayText_i);
        
write_byte(client);
        
write_string(message);
        
message_end();
    }
    
    return 
PLUGIN_HANDLED;
}

public 
CmdTeamSay(client)
{
    new 
said[192];
    
read_args(saidsizeof(said) - 1);
    
remove_quotes(said);
    
    if( !
IsValidMessage(said) ) return PLUGIN_HANDLED;
    
    new 
name[32];
    
get_user_name(clientnamesizeof(name) - 1);
    
    new 
alive is_user_alive(client);
    
    new 
CsTeams:team cs_get_user_team(client);
    
    new 
sayteam_all get_pcvar_num(cvar_sayteam_all);
    
    new 
message[192];
    
formatex(messagesizeof(message) - 1"^x01%s (%s)^x03 %s^x01 :  %s"g_country_code[client], g_team_names[team], namesaid);
    
    for( new 
1<= g_max_clientsi++ )
    {
        if( 
== client
        
|| !is_user_connected(i)
        || 
cs_get_user_team(i) != team
        
|| sayteam_all
        
|| is_user_alive(i) != alive ) continue;
        
        
message_begin(MSG_ONE_UNRELIABLEg_msgid_SayText_i);
        
write_byte(client);
        
write_string(message);
        
message_end();
    }
    
    return 
PLUGIN_HANDLED;
}

bool:IsValidMessage(const said[])
{
    for( new 
0said[i]; i++ )
    {
        if( 
said[i] != ' ' )
        {
            return 
true;
        }
    }
    
    return 
false;
}

GetCountryCode(client)
{
    new 
ip[64];
    
get_user_ip(clientipsizeof(ip) - 11);
    
    new 
code[3];
    
    if( !
geoip_code2_ex(ipcode) )
    {
        
code[0] = '-';
        
code[1] = '-';
    }
    
    
g_country_code[client][0] = '[';
    
g_country_code[client][1] = code[0];
    
g_country_code[client][2] = code[1];
    
g_country_code[client][3] = ']';
    
    if( (
<= client <= g_max_clients)
    && 
code[0] == g_country_code[0][1]
    && 
code[1] == g_country_code[0][2] )
    {
        
g_country_code[client][0] = 0;
    }

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline