AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Chat Prefixes (https://forums.alliedmods.net/showthread.php?t=135248)

GXLZPGX 08-14-2010 07:08

Chat Prefixes
 
Alright, I know its possible to add a prefix before a players name, for example:

Normal Chat:
GXLZPGX: Hey guys!

Prefix Chat:
[ADMIN] GXLZPGX: Hey guys!

I think it would be much easier for someone to give me an example than for me to look through 50 plugins just to find that I need to scramble through the code of another plugin to find out how to do this.

naven 08-14-2010 07:10

Re: Chat Prefixes
 
in init
PHP Code:

    gmsgSayText=get_user_msgid("SayText")//chattag
    
register_message(gmsgSayText,"messageSayText");//chattag
    
gcvarTag register_cvar("amx_chattag","*VIP*");//chattag
    
gcvarLock register_cvar("amx_chattag_lock","1");//chattag 

then
PHP Code:

public messageSayText(msg_idmsg_destmsg_entity){
new 
id get_msg_arg_int(1
if(
is_user_connected(id)){

new 
szBuffer[128];
get_msg_arg_string(2szBuffer127);

if(
contain(szBuffer"#Cstrike_Chat_")==0){
    
    new 
szName[50], szTag[18];
    
get_user_name(idszName31);
    
get_pcvar_string(gcvarTagszTag17);
    
    if(
get_user_flags(id) & TAG_ACCESS){
        
format(szName49,"%s %s"szTagszName);
        }else{
        if(
containi(szNameszTag)==&& get_pcvar_num(gcvarLock)){
            if(
id==msg_entity)
                
ColorChat(idRED,"Usun z nicku tag^x03 %s^x01, aby korzystac z chatu",szTag);
            return 
PLUGIN_HANDLED;
        }
    }
    
    new 
szBuffer2[192];
    
get_msg_arg_string(4szBuffer2191);
    
    
message_begin(MSG_ONEgmsgSayText,{0,0,0}, msg_entity);
    
write_byte(id);
    
write_string(szBuffer);
    
write_string(szName);
    
write_string(szBuffer2);
    
message_end();
    return 
PLUGIN_HANDLED;
}
}
return 
PLUGIN_CONTINUE;



GXLZPGX 08-14-2010 07:30

Re: Chat Prefixes
 
Quote:

Originally Posted by N A V E N (Post 1270454)
in init
PHP Code:

    gmsgSayText=get_user_msgid("SayText")//chattag
    
register_message(gmsgSayText,"messageSayText");//chattag
    
gcvarTag register_cvar("amx_chattag","*VIP*");//chattag
    
gcvarLock register_cvar("amx_chattag_lock","1");//chattag 

then
PHP Code:

public messageSayText(msg_idmsg_destmsg_entity){
new 
id get_msg_arg_int(1
if(
is_user_connected(id)){

new 
szBuffer[128];
get_msg_arg_string(2szBuffer127);

if(
contain(szBuffer"#Cstrike_Chat_")==0){
    
    new 
szName[50], szTag[18];
    
get_user_name(idszName31);
    
get_pcvar_string(gcvarTagszTag17);
    
    if(
get_user_flags(id) & TAG_ACCESS){
        
format(szName49,"%s %s"szTagszName);
        }else{
        if(
containi(szNameszTag)==&& get_pcvar_num(gcvarLock)){
            if(
id==msg_entity)
                
ColorChat(idRED,"Usun z nicku tag^x03 %s^x01, aby korzystac z chatu",szTag);
            return 
PLUGIN_HANDLED;
        }
    }
    
    new 
szBuffer2[192];
    
get_msg_arg_string(4szBuffer2191);
    
    
message_begin(MSG_ONEgmsgSayText,{0,0,0}, msg_entity);
    
write_byte(id);
    
write_string(szBuffer);
    
write_string(szName);
    
write_string(szBuffer2);
    
message_end();
    return 
PLUGIN_HANDLED;
}
}
return 
PLUGIN_CONTINUE;



Thank you for the quick reply but that is too sloppy to organize, I do not need cvars etc, I just want a simple way to change the message.

naven 08-14-2010 08:12

Re: Chat Prefixes
 
PHP Code:

new szName[50], szTag[18]; 
    
get_user_name(idszName31); 
    
get_pcvar_string("[Admin]"szTag17); 
     
    if(
get_user_flags(id) & TAG_ACCESS){ 
        
format(szName49,"%s %s"szTagszName); 
        }else{ 
        if(
containi(szNameszTag)==){ 
            if(
id==msg_entity
                
ColorChat(idRED,"Usun z nicku tag^x03 %s^x01, aby korzystac z chatu",szTag); 
            return 
PLUGIN_HANDLED
        } 
    } 
     
    new 
szBuffer2[192]; 
    
get_msg_arg_string(4szBuffer2191); 
     
    
message_begin(MSG_ONEgmsgSayText,{0,0,0}, msg_entity); 
    
write_byte(id); 
    
write_string(szBuffer); 
    
write_string(szName); 
    
write_string(szBuffer2); 
    
message_end(); 
    return 
PLUGIN_HANDLED


return 
PLUGIN_CONTINUE



Hunter-Digital 08-14-2010 08:29

Re: Chat Prefixes
 
You're hooking a message and instead of altering it you're sending other ones.

Better way (not tested):

Code:

public plugin_init()
  register_message(get_user_msgid("SayText"), "msg_SayText")

public msg_SayText()
{
  static szFormat[64]

  static sender
  sender = get_msg_arg_int(1)

  get_msg_arg_string(2, szFormat, charsmax(szFormat))

  if(equal(szFormat, "#Cstrike_Chat", 13))
  {
      static szTeam[24]

      switch(szFormat[16])
      {
          case 'C': copy(szTeam, charsmax(szTeam), "(Counter-Terrorist) ")
          case 'T': copy(szTeam, charsmax(szTeam), "(Terrorist) ")
          case 'S': copy(szTeam, charsmax(szTeam), "(Spectator) ")
      }

      formatex(szFormat, charsmax(szFormat),
          "^x01%s%s%s^x03%%s1^x01 :  %%s2",
          "[Prefix] ",
          (szFormat[18] == 'S' ? "*SPEC*" : (szFormat[17] == 'D' || szFormat[18] == 'D' ? "*DEAD*")),
          szTeam
      )

      set_msg_arg_string(2, szFormat)
  }
}


Zpoke 08-14-2010 09:47

Re: Chat Prefixes
 
PHP Code:

print_colorindex, const sFormat[], any:...)
{
new 
players[32], count 1
if ( index players[0] = index; else get_playersplayerscount"ch" )
for ( new 
0counti++ )
{
new 
message[256];
new 
len formatexmessage255"^x04[PREFIX]^x01 " )
vformatmessage[len], 255 lensFormat)
message[192] = '^0'
message_beginindex MSG_ONE MSG_ALLget_user_msgid("SayText"), _index )
write_byteplayers[0] )
write_stringmessage )
message_end()
}
return 
1



Zpoke 08-14-2010 09:49

Re: Chat Prefixes
 
or why don't you just use

PHP Code:

#define PREFIX 


Kreation 08-14-2010 20:10

Re: Chat Prefixes
 
Quote:

Originally Posted by GXLZPGX (Post 1270463)
Thank you for the quick reply but that is too sloppy to organize, I do not need cvars etc, I just want a simple way to change the message.

This is scripting help, not do everything for me. Go to Suggestions / Requests.

ConnorMcLeod 08-14-2010 21:06

Re: Chat Prefixes
 
Simple and efficient : http://forums.alliedmods.net/showthr...99#post1265199

GXLZPGX 08-15-2010 08:58

Re: Chat Prefixes
 
Quote:

Originally Posted by Kreation (Post 1271051)
This is scripting help, not do everything for me. Go to Suggestions / Requests.

Why do you troll so many topics? This is for scripting you moron. Suggestions/Requests is more for requesting whole plugins, I just want the event and how to change it.


All times are GMT -4. The time now is 21:55.

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