PDA

View Full Version : CountryChat error


lashsh
06-24-2010, 09:31
/*
* 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 out how to name the country - full or short name
* v2.3 = Now plugin replace error message
* v2.4 = Added GeoIP Code3. To display three characters from the Country
*============================================ =========================================
* Tests:
* Under Windows 4554 platform with AmxModx 1.8.1 - Work
* Under Linux 4617 platform with AmxModx 1.8.1 - Work
*============================================ =========================================
*/

#include <amxmodx>
#include <geoip>

#define VERSION "2.4"

new SzCountryLength, SzMaxPlayers, SzSayText;
new SzName[33][32];
new SzIP[17][16];
new SzGeoIP2[4][3];
new SzGeoIP3[5][4];
new SzCountry[33][46];

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];
new SzAlive = is_user_alive(id);

read_args(Messages, 191);
remove_quotes(Messages);
get_user_name(id, SzName[id], 31);
get_user_ip(id, SzIP[id], 15);
geoip_country(SzIP[id], SzCountry[id]);
geoip_code2(SzIP[id], SzGeoIP2[id]);
geoip_code3(SzIP[id], SzGeoIP3[id]);

if(!is_valid_msg(Messages))
return PLUGIN_CONTINUE;

switch(get_pcvar_num(SzCountryLength)){
case 1: { (SzAlive ? format(Messages, 191, "^4[%s] ^3%s : ^1%s", SzCountry[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", SzCountry[id], SzName[id], Messages)); }
case 2: { (SzAlive ? format(Messages, 191, "^4[%s] ^3%s : ^1%s", SzGeoIP2[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", SzGeoIP2[id], SzName[id], Messages)); }
case 3: { (SzAlive ? format(Messages, 191, "^4[%s] ^3%s : ^1%s", SzGeoIP3[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", SzGeoIP3[id], SzName[id], 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];
new SzPlayerTeam = get_user_team(id);
new SzAlive = is_user_alive(id);

read_args(Messages, 191);
remove_quotes(Messages);
get_user_name(id, SzName[id], 31);
get_user_ip(id, SzIP[id], 15)
geoip_country(SzIP[id], SzCountry[id]);
geoip_code2(SzIP[id], SzGeoIP2[id]);
geoip_code3(SzIP[id], SzGeoIP3[id]);

if(!is_valid_msg(Messages))
return PLUGIN_CONTINUE;

switch(get_pcvar_num(SzCountryLength)){
case 1: { (SzAlive ? format(Messages, 191, "^1(%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages)); }
case 2: { (SzAlive ? format(Messages, 191, "^1(%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages)); }
case 3: { (SzAlive ? format(Messages, 191, "^1(%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], 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;}



L 06/24/2010 - 14:19:27: [AMXX] Run time error 4 (plugin "CountryChat.amxx") - debug not enabled!
L 06/24/2010 - 14:19:27: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).


original plug-in (http://forums.alliedmods.net/showthread.php?t=124688)


CountryChat.amxx debug
L 06/24/2010 - 16:57:20: [AMXX] Displaying debug trace (plugin "CountryChat.amxx")
L 06/24/2010 - 16:57:20: [AMXX] Run time error 4: index out of bounds
L 06/24/2010 - 16:57:20: [AMXX] [0] CountryChat.sma::hook_say (line 69)
L 06/24/2010 - 16:57:21: [AMXX] Displaying debug trace (plugin "CountryChat.amxx")
L 06/24/2010 - 16:57:21: [AMXX] Run time error 4: index out of bounds
L 06/24/2010 - 16:57:21: [AMXX] [0] CountryChat.sma::hook_say (line 67)


line 67
geoip_country(SzIP[id], SzCountry[id]);

line 69
geoip_code3(SzIP[id], SzGeoIP3[id]);

please help.

Owner123
06-24-2010, 12:18
new SzIP[33][16];
new szGeoIP[33][4];

lashsh
06-24-2010, 12:38
new SzIP[33][16];
new szGeoIP[33][4];


So?

#include <amxmodx>
#include <geoip>

#define VERSION "2.4"

new SzCountryLength, SzMaxPlayers, SzSayText;
new SzName[33][32];
new SzIP[33][16];
new szGeoIP[33][4];
new SzGeoIP2[4][3];
new SzGeoIP3[5][4];
new SzCountry[33][46];

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];
new SzAlive = is_user_alive(id);

read_args(Messages, 191);
remove_quotes(Messages);
get_user_name(id, SzName[id], 31);
get_user_ip(id, SzIP[id], 15);
geoip_country(SzIP[id], SzCountry[id]);
geoip_code2(SzIP[id], SzGeoIP2[id]);
geoip_code3(SzIP[id], SzGeoIP3[id]);

if(!is_valid_msg(Messages))
return PLUGIN_CONTINUE;

switch(get_pcvar_num(SzCountryLength)){
case 1: { (SzAlive ? format(Messages, 191, "^4[%s] ^3%s : ^1%s", SzCountry[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", SzCountry[id], SzName[id], Messages)); }
case 2: { (SzAlive ? format(Messages, 191, "^4[%s] ^3%s : ^1%s", SzGeoIP2[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", SzGeoIP2[id], SzName[id], Messages)); }
case 3: { (SzAlive ? format(Messages, 191, "^4[%s] ^3%s : ^1%s", SzGeoIP3[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", SzGeoIP3[id], SzName[id], 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];
new SzPlayerTeam = get_user_team(id);
new SzAlive = is_user_alive(id);

read_args(Messages, 191);
remove_quotes(Messages);
get_user_name(id, SzName[id], 31);
get_user_ip(id, SzIP[id], 15)
geoip_country(SzIP[id], SzCountry[id]);
geoip_code2(SzIP[id], SzGeoIP2[id]);
geoip_code3(SzIP[id], SzGeoIP3[id]);

if(!is_valid_msg(Messages))
return PLUGIN_CONTINUE;

switch(get_pcvar_num(SzCountryLength)){
case 1: { (SzAlive ? format(Messages, 191, "^1(%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages)); }
case 2: { (SzAlive ? format(Messages, 191, "^1(%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages)); }
case 3: { (SzAlive ? format(Messages, 191, "^1(%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], 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;}


If so


#include <amxmodx>
#include <geoip>

#define VERSION "2.4"

new SzCountryLength, SzMaxPlayers, SzSayText;
new SzName[33][32];
new SzGeoIP2[4][3];
new SzGeoIP3[5][4];
new SzCountry[33][46];

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];
new SzAlive = is_user_alive(id);

read_args(Messages, 191);
remove_quotes(Messages);
get_user_name(id, SzName[id], 31);
get_user_ip(id, SzIP[id], 15);
geoip_country(SzIP[id], SzCountry[id]);
geoip_code2(SzIP[id], SzGeoIP2[id]);
geoip_code3(SzIP[id], SzGeoIP3[id]);

if(!is_valid_msg(Messages))
return PLUGIN_CONTINUE;

switch(get_pcvar_num(SzCountryLength)){
case 1: { (SzAlive ? format(Messages, 191, "^4[%s] ^3%s : ^1%s", SzCountry[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", SzCountry[id], SzName[id], Messages)); }
case 2: { (SzAlive ? format(Messages, 191, "^4[%s] ^3%s : ^1%s", SzGeoIP2[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", SzGeoIP2[id], SzName[id], Messages)); }
case 3: { (SzAlive ? format(Messages, 191, "^4[%s] ^3%s : ^1%s", SzGeoIP3[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* ^4[%s] ^3%s : ^1%s", SzGeoIP3[id], SzName[id], 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];
new SzPlayerTeam = get_user_team(id);
new SzAlive = is_user_alive(id);

read_args(Messages, 191);
remove_quotes(Messages);
get_user_name(id, SzName[id], 31);
get_user_ip(id, SzIP[id], 15)
geoip_country(SzIP[id], SzCountry[id]);
geoip_code2(SzIP[id], SzGeoIP2[id]);
geoip_code3(SzIP[id], SzGeoIP3[id]);

if(!is_valid_msg(Messages))
return PLUGIN_CONTINUE;

switch(get_pcvar_num(SzCountryLength)){
case 1: { (SzAlive ? format(Messages, 191, "^1(%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages)); }
case 2: { (SzAlive ? format(Messages, 191, "^1(%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages)); }
case 3: { (SzAlive ? format(Messages, 191, "^1(%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], Messages) : format(Messages, 191, "^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s", SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], 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;}

Owner123
06-24-2010, 12:42
Yes

Edit.
Change this:new SzGeoIP2[4][3];
new SzGeoIP3[5][4];To:new SzGeoIP2[33][3];
new SzGeoIP3[33][4];</span></span>

lashsh
06-24-2010, 12:45
:((

Owner123
06-24-2010, 12:47
Ignore this. This shouldn't return any error.

lashsh
06-24-2010, 12:49
L 06/24/2010 - 20:49:13: [AMXX] Run time error 4 (plugin "CountryChat.amxx") - debug not enabled!
L 06/24/2010 - 20:49:13: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini

Owner123
06-24-2010, 12:52
Change:new SzIP[17][16];
To: new SzIP[33][16];

lashsh
06-24-2010, 12:57
Thanks

lashsh
06-24-2010, 13:19
Description:
When writing in chat plugin will add name of your country. See of the picture.
http://amxmodxbg.org/upload/images/1269544404.png
http://i.imagehost.org/0113/123.png
http://prikachi.com/files/1563150V.png


Cvars:

country_chat_length - How to print name of the country?
1 = full name.
2 = short name.
3 = three character country code.

Modules:
#include <geoip>

Changelog:
1.0 - First version.
1.1 - Correction code.
2.0 - Fixed all possible bugs.
2.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.
2.2 - Added Cvar how to print name the country - full or short
name.
2.3 - Now plugin replace error message
2.4 - Added GeoIP Code3. To display three characters from the Country
2.6 - Bugs fixed.


Credits


Plugin Author
Virtual.New.BG

Bugs fixed
LaSsHhH & Owner123

drekes
06-24-2010, 13:50
remove the .amxx file, you can't upload it.