/* * Link to the plugin: http://virtual.new.bg/forum/viewtopic.php?f=125&t=1864 *===================================================================================== * Country Chat plugin by Virtual.New.BG Version 2.1 Made in Bulgaria *===================================================================================== * Change Log: * v1.0 = Initial release * v1.1 = Correction Code * v2.0 = Fixed all possible bugs * v2.1 = Fixed bug with the quote where country is not shown * Fixed bug with logging the chat in the console * Fixed bug where the players see team chat of the other team * v2.2 = Added Cvar how to print name the country - full or short name *===================================================================================== * Tests: * Under Windows 4554 platform with AmxModx 1.8.1 - Work * Under Linux 4617 platform with AmxModx 1.8.1 - Work *===================================================================================== */ #include #include #define VERSION "2.2" new SzCountryLength, SzMaxPlayers, SzSayText; new SzGTeam[3][] = { "Spectator", "Terrorist", "Counter-Terrorist" } public plugin_init() { register_plugin("Country Chat", VERSION, "Virtual.New.BG"); register_clcmd("say", "hook_say"); register_clcmd("say_team", "hook_say_team"); SzCountryLength = register_cvar("country_chat_length", "1"); register_cvar("country_chat_version", VERSION, FCVAR_SERVER|FCVAR_SPONLY); set_cvar_string("country_chat_version", VERSION); SzSayText = get_user_msgid ("SayText"); SzMaxPlayers = get_maxplayers(); register_message(SzSayText, "MsgDuplicate"); } public MsgDuplicate(id){ return PLUGIN_HANDLED; } public hook_say(id){ new Messages[192], SzName[32], SzIP[16], SzShortCountry[3]; static SzCountry[32]; new SzAlive = is_user_alive(id); read_args(Messages, 191); remove_quotes(Messages); get_user_name(id, SzName, 31); get_user_ip(id, SzIP, 15); geoip_country(SzIP, SzCountry); geoip_code2(SzIP, SzShortCountry); if(!is_valid_msg(Messages)) return PLUGIN_CONTINUE; switch(get_pcvar_num(SzCountryLength)){ case 1: { (SzAlive ? format(Messages, 191, "^2[%s] %s: %s", SzCountry, SzName, Messages) : format(Messages, 191, "^2*DEAD* [%s] %s: %s", SzCountry, SzName, Messages)); } case 2: { (SzAlive ? format(Messages, 191, "^2[%s] %s: %s", SzShortCountry, SzName, Messages) : format(Messages, 191, "^2*DEAD* [%s] %s: %s", SzShortCountry, SzName, Messages)); }} for(new i = 1; i <= SzMaxPlayers; i++){ if(!is_user_connected(i)) continue; if(SzAlive && is_user_alive(i) || !SzAlive && !is_user_alive(i)){ message_begin(MSG_ONE, SzSayText, {0, 0, 0}, i); write_byte(id); write_string(Messages); message_end();} } return PLUGIN_CONTINUE; } public hook_say_team(id){ new Messages[192], SzName[32], SzIP[16], SzShortCountry[3]; static SzCountry[32]; new SzPlayerTeam = get_user_team(id); new SzAlive = is_user_alive(id); read_args(Messages, 191); remove_quotes(Messages); get_user_name(id, SzName, 31); get_user_ip(id, SzIP, 15) geoip_country(SzIP, SzCountry); geoip_code2(SzIP, SzShortCountry); if(!is_valid_msg(Messages)) return PLUGIN_CONTINUE; switch(get_pcvar_num(SzCountryLength)){ case 1: { (SzAlive ? format(Messages, 191, "^2(%s) [%s] %s: %s", SzGTeam[SzPlayerTeam], SzCountry, SzName, Messages) : format(Messages, 191, "^2*DEAD* (%s) [%s] %s: %s", SzGTeam[SzPlayerTeam], SzCountry, SzName, Messages)); } case 2: { (SzAlive ? format(Messages, 191, "^2(%s) [%s] %s: %s", SzGTeam[SzPlayerTeam], SzShortCountry, SzName, Messages) : format(Messages, 191, "^2*DEAD* (%s) [%s] %s: %s", SzGTeam[SzPlayerTeam], SzShortCountry, SzName, Messages)); } } for(new i = 1; i <= SzMaxPlayers; i++){ if(!is_user_connected(i)) continue; if(get_user_team(i) != SzPlayerTeam) continue; if(SzAlive && is_user_alive(i) || !SzAlive && !is_user_alive(i)){ message_begin(MSG_ONE, SzSayText, {0, 0, 0}, i); write_byte(id); write_string(Messages); message_end();} } return PLUGIN_CONTINUE; } bool:is_valid_msg(const Messages[]){ if( Messages[0] == '@' || !strlen(Messages)){ return false; } return true;}