Raised This Month: $ Target: $400
 0% 

CountryChat error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lashsh
BANNED
Join Date: Jun 2010
Location: Georgia, Tbilisi
Old 06-24-2010 , 09:31   CountryChat error
Reply With Quote #1

Code:
/*
*  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;}


Code:
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


CountryChat.amxx debug
Code:
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
Code:
  geoip_country(SzIP[id], SzCountry[id]);
line 69
Code:
  geoip_code3(SzIP[id], SzGeoIP3[id]);
please help.
lashsh is offline
Send a message via Skype™ to lashsh
Owner123
Member
Join Date: Jun 2010
Old 06-24-2010 , 12:18   Re: CountryChat error
Reply With Quote #2

PHP Code:
new SzIP[33][16];
new 
szGeoIP[33][4]; 
__________________
Sorry for my bad english !
Owner123 is offline
lashsh
BANNED
Join Date: Jun 2010
Location: Georgia, Tbilisi
Old 06-24-2010 , 12:38   Re: CountryChat error
Reply With Quote #3

Quote:
Originally Posted by Owner123 View Post
PHP Code:
new SzIP[33][16];
new 
szGeoIP[33][4]; 
So?
PHP Code:
#include <amxmodx>
#include <geoip>

#define VERSION    "2.4"

new SzCountryLengthSzMaxPlayersSzSayText;
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",    VERSIONFCVAR_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(Messages191);
    
remove_quotes(Messages);
    
get_user_name(idSzName[id], 31);
    
get_user_ip(idSzIP[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(Messages191"^4[%s] ^3%s : ^1%s"SzCountry[id], SzName[id], Messages) : format(Messages191"^1*DEAD* ^4[%s] ^3%s : ^1%s"SzCountry[id], SzName[id], Messages)); }
        case 
2: { (SzAlive format(Messages191"^4[%s] ^3%s : ^1%s"SzGeoIP2[id], SzName[id], Messages) : format(Messages191"^1*DEAD* ^4[%s] ^3%s : ^1%s"SzGeoIP2[id], SzName[id], Messages)); }
        case 
3: { (SzAlive format(Messages191"^4[%s] ^3%s : ^1%s"SzGeoIP3[id], SzName[id], Messages) : format(Messages191"^1*DEAD* ^4[%s] ^3%s : ^1%s"SzGeoIP3[id], SzName[id], Messages)); }}
    
    for(new 
1<= SzMaxPlayersi++){
        if(!
is_user_connected(i))
            continue;
        if(
SzAlive && is_user_alive(i) || !SzAlive && !is_user_alive(i)){
            
message_begin(MSG_ONESzSayText, {000}, 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(Messages191);
    
remove_quotes(Messages);
    
get_user_name(idSzName[id], 31);
    
get_user_ip(idSzIP[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(Messages191"^1(%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages) : format(Messages191"^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages)); }
        case 
2: { (SzAlive format(Messages191"^1(%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages) : format(Messages191"^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages)); } 
        case 
3: { (SzAlive format(Messages191"^1(%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], Messages) : format(Messages191"^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], Messages)); } }
    
    for(new 
1<= SzMaxPlayersi++){
        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_ONESzSayText, {000}, 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

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

#define VERSION    "2.4" 

new SzCountryLengthSzMaxPlayersSzSayText
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",    VERSIONFCVAR_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(Messages191); 
    
remove_quotes(Messages); 
    
get_user_name(idSzName[id], 31); 
    
get_user_ip(idSzIP[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(Messages191"^4[%s] ^3%s : ^1%s"SzCountry[id], SzName[id], Messages) : format(Messages191"^1*DEAD* ^4[%s] ^3%s : ^1%s"SzCountry[id], SzName[id], Messages)); } 
        case 
2: { (SzAlive format(Messages191"^4[%s] ^3%s : ^1%s"SzGeoIP2[id], SzName[id], Messages) : format(Messages191"^1*DEAD* ^4[%s] ^3%s : ^1%s"SzGeoIP2[id], SzName[id], Messages)); } 
        case 
3: { (SzAlive format(Messages191"^4[%s] ^3%s : ^1%s"SzGeoIP3[id], SzName[id], Messages) : format(Messages191"^1*DEAD* ^4[%s] ^3%s : ^1%s"SzGeoIP3[id], SzName[id], Messages)); }} 
     
    for(new 
1<= SzMaxPlayersi++){ 
        if(!
is_user_connected(i)) 
            continue; 
        if(
SzAlive && is_user_alive(i) || !SzAlive && !is_user_alive(i)){ 
            
message_begin(MSG_ONESzSayText, {000}, 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(Messages191); 
    
remove_quotes(Messages); 
    
get_user_name(idSzName[id], 31); 
    
get_user_ip(idSzIP[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(Messages191"^1(%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages) : format(Messages191"^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzCountry[id], SzName[id], Messages)); } 
        case 
2: { (SzAlive format(Messages191"^1(%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages) : format(Messages191"^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzGeoIP2[id], SzName[id], Messages)); }  
        case 
3: { (SzAlive format(Messages191"^1(%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], Messages) : format(Messages191"^1*DEAD* (%s) ^4[%s] ^3%s : ^1%s"SzGTeam[SzPlayerTeam], SzGeoIP3[id], SzName[id], Messages)); } } 
     
    for(new 
1<= SzMaxPlayersi++){ 
        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_ONESzSayText, {000}, 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;} 

Last edited by lashsh; 06-24-2010 at 12:43.
lashsh is offline
Send a message via Skype™ to lashsh
Owner123
Member
Join Date: Jun 2010
Old 06-24-2010 , 12:42   Re: CountryChat error
Reply With Quote #4

Yes

Edit.
Change this:
PHP Code:
new SzGeoIP2[4][3]; 
new 
SzGeoIP3[5][4]; 
To:
PHP Code:
new SzGeoIP2[33][3]; 
new 
SzGeoIP3[33][4]; 
</span></span>
__________________
Sorry for my bad english !
Owner123 is offline
lashsh
BANNED
Join Date: Jun 2010
Location: Georgia, Tbilisi
Old 06-24-2010 , 12:45   Re: CountryChat error
Reply With Quote #5

(
Attached Thumbnails
Click image for larger version

Name:	untitled.JPG
Views:	118
Size:	95.3 KB
ID:	68304  
lashsh is offline
Send a message via Skype™ to lashsh
Owner123
Member
Join Date: Jun 2010
Old 06-24-2010 , 12:47   Re: CountryChat error
Reply With Quote #6

Ignore this. This shouldn't return any error.
__________________
Sorry for my bad english !
Owner123 is offline
lashsh
BANNED
Join Date: Jun 2010
Location: Georgia, Tbilisi
Old 06-24-2010 , 12:49   Re: CountryChat error
Reply With Quote #7

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

Last edited by lashsh; 06-24-2010 at 13:07.
lashsh is offline
Send a message via Skype™ to lashsh
Owner123
Member
Join Date: Jun 2010
Old 06-24-2010 , 12:52   Re: CountryChat error
Reply With Quote #8

Change:
PHP Code:
new SzIP[17][16]; 
To:
PHP Code:
new SzIP[33][16]; 
__________________
Sorry for my bad english !
Owner123 is offline
lashsh
BANNED
Join Date: Jun 2010
Location: Georgia, Tbilisi
Old 06-24-2010 , 12:57   Re: CountryChat error
Reply With Quote #9

Thanks

Last edited by lashsh; 06-24-2010 at 13:01.
lashsh is offline
Send a message via Skype™ to lashsh
lashsh
BANNED
Join Date: Jun 2010
Location: Georgia, Tbilisi
Old 06-24-2010 , 13:19   CountryChat
Reply With Quote #10

Description:
When writing in chat plugin will add name of your country. See of the picture.





Cvars:

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

Modules:
Code:
#include <geoip>
Changelog:
Code:
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
Attached Files
File Type: sma Get Plugin or Get Source (CountryChat.sma - 574 views - 5.2 KB)

Last edited by lashsh; 06-25-2010 at 20:53.
lashsh is offline
Send a message via Skype™ to lashsh
Reply



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 14:50.


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