AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CountryChat error (https://forums.alliedmods.net/showthread.php?t=130483)

lashsh 06-24-2010 09:31

CountryChat error
 
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.

Owner123 06-24-2010 12:18

Re: CountryChat error
 
PHP Code:

new SzIP[33][16];
new 
szGeoIP[33][4]; 


lashsh 06-24-2010 12:38

Re: CountryChat error
 
Quote:

Originally Posted by Owner123 (Post 1218375)
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;} 


Owner123 06-24-2010 12:42

Re: CountryChat error
 
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>

lashsh 06-24-2010 12:45

Re: CountryChat error
 
1 Attachment(s)
:((

Owner123 06-24-2010 12:47

Re: CountryChat error
 
Ignore this. This shouldn't return any error.

lashsh 06-24-2010 12:49

Re: CountryChat error
 
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

Re: CountryChat error
 
Change:
PHP Code:

new SzIP[17][16]; 

To:
PHP Code:

new SzIP[33][16]; 


lashsh 06-24-2010 12:57

Re: CountryChat error
 
Thanks

lashsh 06-24-2010 13:19

CountryChat
 
1 Attachment(s)
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:
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


All times are GMT -4. The time now is 14:50.

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