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(said, sizeof(said) - 1);
remove_quotes(said);
if( !IsValidMessage(said) ) return PLUGIN_HANDLED;
new name[32];
get_user_name(client, name, sizeof(name) - 1);
new alive = is_user_alive(client);
new tag[9];
if( cs_get_user_team(client) == CS_TEAM_SPECTATOR )
{
copy(tag, sizeof(tag) - 1, "*SPEC* ");
}
else if( !alive )
{
copy(tag, sizeof(tag) - 1, "*DEAD* ");
}
new say_all = get_pcvar_num(cvar_say_all);
new message[192];
formatex(message, sizeof(message) - 1, "^x01%s %s^x03 %s^x01 : %s", g_country_code[client], tag, name, said);
for( new i = 1; i <= g_max_clients; i++ )
{
if( i == client
|| !is_user_connected(i)
|| say_all
|| is_user_alive(i) != alive ) continue;
message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, i);
write_byte(client);
write_string(message);
message_end();
}
return PLUGIN_HANDLED;
}
public CmdTeamSay(client)
{
new said[192];
read_args(said, sizeof(said) - 1);
remove_quotes(said);
if( !IsValidMessage(said) ) return PLUGIN_HANDLED;
new name[32];
get_user_name(client, name, sizeof(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(message, sizeof(message) - 1, "^x01%s (%s)^x03 %s^x01 : %s", g_country_code[client], g_team_names[team], name, said);
for( new i = 1; i <= g_max_clients; i++ )
{
if( i == client
|| !is_user_connected(i)
|| cs_get_user_team(i) != team
|| sayteam_all
|| is_user_alive(i) != alive ) continue;
message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, i);
write_byte(client);
write_string(message);
message_end();
}
return PLUGIN_HANDLED;
}
bool:IsValidMessage(const said[])
{
for( new i = 0; said[i]; i++ )
{
if( said[i] != ' ' )
{
return true;
}
}
return false;
}
GetCountryCode(client)
{
new ip[64];
get_user_ip(client, ip, sizeof(ip) - 1, 1);
new code[3];
if( !geoip_code2_ex(ip, code) )
{
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( (1 <= client <= g_max_clients)
&& code[0] == g_country_code[0][1]
&& code[1] == g_country_code[0][2] )
{
g_country_code[client][0] = 0;
}
}
__________________