Raised This Month: $51 Target: $400
 12% 

Need help with coloring text


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheTealTeal
New Member
Join Date: Dec 2016
Old 12-25-2016 , 15:34   Need help with coloring text
Reply With Quote #1

Hey, so im making a source mod plugin where you put a command in and you says a line of text in chat, but i need help with being able to color the letters in chat.

Thanks in advanced!
TheTealTeal is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 12-25-2016 , 16:38   Re: Need help with coloring text
Reply With Quote #2

Colors can work slightly different based on the game but here are two functions that are useful for printing colored messages

PHP Code:
/**
* Used to print messages to all players and allows special colors without annoying hexadecimal spam in console
*/
stock void PrintColorTextAll(const String:msg[], any:...)
{
    
decl String:buffer[300];
    
VFormat(buffersizeof(buffer), msg2);
    new 
Handle:hMessage StartMessageAll("SayText2"); 
    if (
hMessage != INVALID_HANDLE
    {
        if(
GetFeatureStatus(FeatureType_Native"GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf
        {
            
PbSetInt(hMessage"ent_idx"0);
            
PbSetBool(hMessage"chat"true);
            
PbSetString(hMessage"msg_name"buffer);
            
PbAddString(hMessage"params""");
            
PbAddString(hMessage"params""");
            
PbAddString(hMessage"params""");
            
PbAddString(hMessage"params""");
        }
        else
        {
            
BfWriteByte(hMessage0);
            
BfWriteByte(hMessagetrue);
            
BfWriteString(hMessagebuffer);
        }
        
        
EndMessage();
    }
}

/**
* Used to print messages to a single player and allows special colors without annoying hexadecimal spam in console
*/
stock void PrintColorText(client, const String:msg[], any:...)
{
    if(
IsClientInGame(client))
    {
        new 
String:buffer[300];
        
VFormat(buffersizeof(buffer), msg3);
        
        new 
Handle:hMessage StartMessageOne("SayText2"client); 
        if (
hMessage != INVALID_HANDLE
        { 
            if(
GetFeatureStatus(FeatureType_Native"GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf
            {
                
PbSetInt(hMessage"ent_idx"client);
                
PbSetBool(hMessage"chat"true);
                
PbSetString(hMessage"msg_name"buffer);
                
PbAddString(hMessage"params""");
                
PbAddString(hMessage"params""");
                
PbAddString(hMessage"params""");
                
PbAddString(hMessage"params""");
            }
            else
            {
                
BfWriteByte(hMessageclient);
                
BfWriteByte(hMessagetrue);
                
BfWriteString(hMessagebuffer);
            }
            
            
EndMessage();
        }
    }

Examples

PrintColorText(client, "\x07FF00FFHello world"); // Hex code (doesn't work in all games)
PrintColorTextAll("\x02Hello world"); // Can usually do \x01, \x02, \x03, etc depends on the game to know how many there are
PrintColorTexAll("\x08FFFF0099Hello world!"); // Alpha channel (doesn't work in all games)
blaacky is offline
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 12-26-2016 , 05:34   Re: Need help with coloring text
Reply With Quote #3

If your game is TF2 you can use morecolors.inc
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests

Last edited by BraveFox; 12-26-2016 at 05:34.
BraveFox is offline
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 00:14.


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