Here is the version I currently use:
Code: Select all
enum COLOR_PRINT
{
COLOR_RANDOM = -4,
COLOR_GREY,
COLOR_BLUE,
COLOR_RED,
}
stock client_print_color(id, {COLOR_PRINT,_}:color_id, message[], any:...)
{
static SayText, TeamInfo;
if( !SayText )
SayText = get_user_msgid("SayText");
if( !TeamInfo )
TeamInfo = get_user_msgid("TeamInfo");
new const TeamName[][] =
{
"",
"TERRORIST",
"CT",
"SPECTATOR"
};
new ColorChange;
if( _:color_id < 0 )
{
ColorChange = _:color_id;
for( new i=1; i<=32; i++ )
{
if(is_user_connected(i))
{
color_id = COLOR_PRINT:i;
break;
}
}
if( _:color_id <= 0 )
return;
if( message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, TeamInfo, _, id) )
{
write_byte(_:color_id);
switch( COLOR_PRINT:ColorChange )
{
case COLOR_RED: write_string(TeamName[1]);
case COLOR_BLUE: write_string(TeamName[2]);
case COLOR_GREY: write_string(TeamName[3]);
default: write_string(TeamName[random_num(1,3)]);
}
message_end();
ColorChange = get_user_team(_:color_id);
}
}
new message2[128];
message2[0] = '^1'; //The message must start with a color, this is for normal colors
vformat(message2[1], 127, message, 4);
if( message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, SayText, _, id) )
{
write_byte(_:color_id);
write_string(message2);
message_end();
}
if( ColorChange && message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, TeamInfo, _, id) )
{
write_byte(_:color_id);
write_string(TeamName[ColorChange]);
message_end();
}
}
And without the enum (just makes it a single function for easy adding to other plugins):
Code: Select all
stock client_print_color(id, color_id, message[], any:...)
{
static SayText, TeamInfo;
if( !SayText )
SayText = get_user_msgid("SayText");
if( !TeamInfo )
TeamInfo = get_user_msgid("TeamInfo");
new const TeamName[][] =
{
"",
"TERRORIST",
"CT",
"SPECTATOR"
};
new ColorChange;
if( color_id < 0 )
{
ColorChange = color_id;
for( new i=1; i<=32; i++ )
{
if(is_user_connected(i))
{
color_id = i;
break;
}
}
if( color_id <= 0 )
return;
if( message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, TeamInfo, _, id) )
{
write_byte(color_id);
switch( ColorChange )
{
case -1: write_string(TeamName[1]);
case -2: write_string(TeamName[2]);
case -3: write_string(TeamName[3]);
default: write_string(TeamName[random_num(1,3)]);
}
message_end();
ColorChange = get_user_team(color_id);
}
}
new message2[128];
message2[0] = '^1'; //The message must start with a color, this is for normal colors
vformat(message2[1], 127, message, 4);
if( message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, SayText, _, id) )
{
write_byte(color_id);
write_string(message2);
message_end();
}
if( ColorChange && message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, TeamInfo, _, id) )
{
write_byte(color_id);
write_string(TeamName[ColorChange]);
message_end();
}
}
All you have to do is not put any color codes in the message.
In other words:
Code: Select all
client_print_color(id, COLOR_RED, "This is normal colored text.")
client_print_color(id, COLOR_RED, "^3This is red colored text.")
client_print_color(id, COLOR_RED, "^4This is green colored text.")
client_print_color(id, COLOR_BLUE, "This is normal colored text.")
client_print_color(id, COLOR_BLUE, "^3This is blue colored text.")
client_print_color(id, COLOR_BLUE, "^4This is green colored text.")
client_print_color(id, COLOR_GREY, "This is normal colored text.")
client_print_color(id, COLOR_GREY, "^3This is grey colored text.")
client_print_color(id, COLOR_GREY, "^4This is green colored text.")
client_print_color(id, COLOR_RANDOM, "This is normal colored text.")
client_print_color(id, COLOR_RANDOM, "^3This is random colored text.")
client_print_color(id, COLOR_RANDOM, "^4This is green colored text.")