AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Rage SubModule: ColorChat (https://forums.alliedmods.net/showthread.php?t=183388)

ConnorMcLeod 04-21-2012 09:35

Rage SubModule: ColorChat
 
4 Attachment(s)
ColorChat



.: Description :.


Finally a real native for colorchat.



.: Natives :.

  • client_print_color(id, color=DontChange, const fmt[], any:...)
  • client_print_color2(id, sender, const fmt[], any:...)
    Same as client_print_color excepted you set team color according to sender index


.: Stock :.

  • register_dictionary_colored(const filename[])
    Same as register_dictionary, but transform !g, !t and !n into colors code
    so you can use same ML Keys in normal chat or hudmessage or whereever you want
    It's not required at all to use this, you can directly put in a UTF-8 WITHOUT BOM file, 1 3 and 4,
    for this, use npp and hit Alt + corresponding key (1 2 or 4), you should respectively see (SOH) (ETX) and (EOT).
    if you still want to use !n !g and !t, use this stock and enjoy the compiled plugin increased size :)


.: Notes :.


You can find usage example on ColorChat fake native thread



.: Requirements :.


You need the Rage Module to be loaded in order the submodule work.




kiki33hun 04-21-2012 10:55

Re: Rage SubModule: ColorChat
 
Nice job!

iBrazilian 04-21-2012 12:28

Re: Rage SubModule: ColorChat
 
Great job with this Connor!

Xalus 04-21-2012 20:09

Re: Rage SubModule: ColorChat
 
Question,

becuase with the other version without Rage, it had problems with ^n.
Is it fixed with this?

ConnorMcLeod 04-21-2012 20:34

Re: Rage SubModule: ColorChat
 
What you mean ^n ???
In .sma you have to pass ^1 ^3 and ^4, and in ML file, either you directly use 1 3 4 (see first post), either you use !n !g and !t and then you need to use register_dictionary_colored.

K.K.Lv 04-22-2012 01:53

Re: Rage SubModule: ColorChat
 
nice connor,
but i write it into the amxmodx_mm, I think that will be more efficient than your(at least for me):mrgreen:

PHP Code:

static cell AMX_NATIVE_CALL client_print_color(AMX *amxcell *params)
{
    if (
params[2] < || params[2] > 3)
    {
        
LogError(amxAMX_ERR_NATIVE"Invalid color index %d"params[2]);
        return 
0;
    }
    
int len;
    
char *msg;
    if (
params[1] ==0)
    {
        for (
int i 1<= gpGlobals->maxClients; ++i)
        {
            
CPlayer *pPlayer GET_PLAYER_POINTER_I(i);
            if (
pPlayer->ingame)
            {
                
g_langMngr.SetDefLang(i);
                
msg format_amxstring(amxparams3len);
                
msg[len++] = '\n';
                
msg[len] = 0;
                if (
params[2])
                {
                    const 
char szTeamName[4][16] = 
                    {
                         
"",
                         
"TERRORIST",
                         
"CT",
                         
"SPECTATOR"
                    
};
                    
MESSAGE_BEGIN(MSG_ONE_UNRELIABLEgmsgTeamInfoNULLpPlayer->pEdict);
                        
WRITE_BYTE(i);
                        
WRITE_STRING(szTeamName[params[2]]);
                    
MESSAGE_END();
                }
                
MESSAGE_BEGIN(MSG_ONE_UNRELIABLEgmsgSayTextNULLpPlayer->pEdict);
                    
WRITE_BYTE(i);
                    
WRITE_STRING(msg);
                
MESSAGE_END();
            }
        }
    }else
    {
        
int index params[1];
 
        if (
index || index gpGlobals->maxClients)
        {
            
LogError(amxAMX_ERR_NATIVE"Invalid player id %d"index);
            return 
0;
        }
        
CPlayer *pPlayer GET_PLAYER_POINTER_I(index);
        if (
pPlayer->ingame)
        {
            
g_langMngr.SetDefLang(index);
            
msg format_amxstring(amxparams3len);
            
msg[len++] = '\n';
            
msg[len] = 0;
            if (
params[2])
            {
                const 
char szTeamName[4][16] = 
                {
                    
"",
                    
"TERRORIST",
                    
"CT",
                    
"SPECTATOR"
                
};
                
MESSAGE_BEGIN(MSG_ONE_UNRELIABLEgmsgTeamInfoNULLpPlayer->pEdict);
                    
WRITE_BYTE(index);
                    
WRITE_STRING(szTeamName[params[2]]);
                
MESSAGE_END();
            }
            
MESSAGE_BEGIN(MSG_ONE_UNRELIABLEgmsgSayTextNULLpPlayer->pEdict);
                
WRITE_BYTE(index);
                
WRITE_STRING(msg);
            
MESSAGE_END();
        }
    }
    return 
len;
}; 


yokomo 04-22-2012 02:01

Re: Rage SubModule: ColorChat
 
Quote:

Originally Posted by K.K.Lv (Post 1694204)
nice connor,
but i write it into the amxmodx_mm, I think that will be more efficient than your(at least for me):mrgreen:

Sorry offtopic.
Private or public? if public can you share to us? wanna try too.

K.K.Lv 04-22-2012 02:32

Re: Rage SubModule: ColorChat
 
Quote:

Originally Posted by yokomo (Post 1694206)
Sorry offtopic.
Private or public? if public can you share to us? wanna try too.

I have edit my post, please see the code

Xalus 04-22-2012 03:23

Re: Rage SubModule: ColorChat
 
Quote:

Originally Posted by ConnorMcLeod (Post 1694069)
What you mean ^n ???
In .sma you have to pass ^1 ^3 and ^4, and in ML file, either you directly use 1 3 4 (see first post), either you use !n !g and !t and then you need to use register_dictionary_colored.

^n -> Space in hudmessages,
If U added that in ML file, with ur register_dictionary_colored, it didn't show,
So there wasn't a space.

ConnorMcLeod 04-22-2012 05:03

Re: Rage SubModule: ColorChat
 
Quote:

Originally Posted by Xalus (Post 1694223)
^n -> Space in hudmessages,
If U added that in ML file, with ur register_dictionary_colored, it didn't show,
So there wasn't a space.


Didn't know, should be the same with that version.
So you mean hudmessages are broken after you use register_dictionary_colored on a ml file ?

Edit : Just had an idea, i you know that a file will be proceeded with register_dictionary_colored, try to change all ^n with ^^n, i think the problem may be that strings are formated 2 times.



Quote:

Originally Posted by K.K.Lv (Post 1694204)
nice connor,
but i write it into the amxmodx_mm, I think that will be more efficient than your(at least for me):mrgreen:

PHP Code:

static cell AMX_NATIVE_CALL client_print_color(AMX *amxcell *params)
{
    if (
params[2] < || params[2] > 3)
    {
        
LogError(amxAMX_ERR_NATIVE"Invalid color index %d"params[2]);
        return 
0;
    }
    
int len;
    
char *msg;
    if (
params[1] ==0)
    {
        for (
int i 1<= gpGlobals->maxClients; ++i)
        {
            
CPlayer *pPlayer GET_PLAYER_POINTER_I(i);
            if (
pPlayer->ingame)
            {
                
g_langMngr.SetDefLang(i);
                
msg format_amxstring(amxparams3len);
                
msg[len++] = '\n';
                
msg[len] = 0;
                if (
params[2])
                {
                    const 
char szTeamName[4][16] = 
                    {
                         
"",
                         
"TERRORIST",
                         
"CT",
                         
"SPECTATOR"
                    
};
                    
MESSAGE_BEGIN(MSG_ONE_UNRELIABLEgmsgTeamInfoNULLpPlayer->pEdict);
                        
WRITE_BYTE(i);
                        
WRITE_STRING(szTeamName[params[2]]);
                    
MESSAGE_END();
                }
                
MESSAGE_BEGIN(MSG_ONE_UNRELIABLEgmsgSayTextNULLpPlayer->pEdict);
                    
WRITE_BYTE(i);
                    
WRITE_STRING(msg);
                
MESSAGE_END();
            }
        }
    }else
    {
        
int index params[1];
 
        if (
index || index gpGlobals->maxClients)
        {
            
LogError(amxAMX_ERR_NATIVE"Invalid player id %d"index);
            return 
0;
        }
        
CPlayer *pPlayer GET_PLAYER_POINTER_I(index);
        if (
pPlayer->ingame)
        {
            
g_langMngr.SetDefLang(index);
            
msg format_amxstring(amxparams3len);
            
msg[len++] = '\n';
            
msg[len] = 0;
            if (
params[2])
            {
                const 
char szTeamName[4][16] = 
                {
                    
"",
                    
"TERRORIST",
                    
"CT",
                    
"SPECTATOR"
                
};
                
MESSAGE_BEGIN(MSG_ONE_UNRELIABLEgmsgTeamInfoNULLpPlayer->pEdict);
                    
WRITE_BYTE(index);
                    
WRITE_STRING(szTeamName[params[2]]);
                
MESSAGE_END();
            }
            
MESSAGE_BEGIN(MSG_ONE_UNRELIABLEgmsgSayTextNULLpPlayer->pEdict);
                
WRITE_BYTE(index);
                
WRITE_STRING(msg);
            
MESSAGE_END();
        }
    }
    return 
len;
}; 


Why would it be more efficient ?
Your way gonna change players place in scoreboard (only for themselves but still), also you should make sure the message length is 191 max.
Anyway you would have to recompile any new amxx update.


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

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