Raised This Month: $7 Target: $400
 1% 

RGB, RGBA, Hex


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 06-17-2012 , 10:47   RGB, RGBA, Hex
Reply With Quote #1

Some shitty tutorial. (Copy most text from wiki)

There have been this new chat color feature in few source games for a while,
let's look how we could "make" these color values.

Custom chat color use a hex triplet (three-byte hexadecimal number), where bytes represent the red, green and blue components of the color (RGB).
In hexadecimal FFFFFF.
Where one color channel range is in hex 00 - FF, in decimal 0 - 255

"Note that if any one of the three color values is less than 16 (decimal) or 10 (hex), it must be represented with a leading zero so that the triplet always has exactly six digits."
For example, wrong way (%X)
PHP Code:
PrintToChatAll("%X%X%X"4816); // Show RGB decimal-triplet in hex, would be 4810 
Same example but with advanced formatting (%02X)
  • %: always required
  • flag 0: Pads with 0s instead of spaces when needed
  • width 2: Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
  • precision : skipped
  • specifier X: Hexadecimal representation of the binary value
PHP Code:
PrintToChatAll("%02X%02X%02X"4816); // Show RGB decimal-triplet in hex, would be 040810 
Ok, we have get hex-triplet output with three separate decimal places.
But this can be more easier. (Found from google, but seems bl4nk have also posted before)
This how combine all three color channels to one. (RGB to Hex)
PHP Code:
    new my_color;
    
my_color |=    ( (5   0xFF) << 16);        // Red    05----
    
my_color |=    ( (200 0xFF) << );        // Green  --C8--
    
my_color |=    ( (255 0xFF) << );        // Blue   ----FF

    
PrintToChatAll("%06X"my_color); // Output will be 05C8FF 
Explain to me


These above (RGB) now works with chat color character "\x07"
PHP Code:
PrintToChatAll("\x07%06XMy color"my_color); 
-------------


Another chat color character "\x08", require four color channel (RGBA) where last channel is Alpha, modify text opacity/transparency.
Almost same way as above but we add one more hex byte = two hex digits.
And now remember also that formating, 8 hex digit (%08X)
PHP Code:
    new my_color;
    
my_color |=    ( (5   255) << 24);        // Red    05------
    
my_color |=    ( (200 255) << 16);        // Green  --C8----
    
my_color |=    ( (255 255) << );        // Blue   ----FF--
    
my_color |=    ( (50  255) << );        // Alpha  ------32

    
PrintToChatAll("%08X"my_color);    // 05C8FF32 
Example with RGBA
PHP Code:
PrintToChatAll("\x08%08XMy color"my_color); 
------


Yes, can do even more simple than those before. Just add straight Hex color value in output text, or use text.

PHP Code:
PrintToChatAll("\07%sRed \x0800FF00A0Green \x07%06XBlue",        "FF0000"0x0000FF); 
---

We can do also this in translation files, not need edit plugin
I attached test translation phrase, hope those characters not get erased after uploading here.


More here #22


Sry for bad english and lot of text with misspellings, typos, wrong info.
*edit
Use NotePad++
Attached Thumbnails
Click image for larger version

Name:	testphrase.png
Views:	921
Size:	26.4 KB
ID:	173137  
Attached Files
File Type: txt test.phrases.txt (648 Bytes, 305 views)

Last edited by Bacardi; 01-05-2019 at 18:17. Reason: clarify =|
Bacardi is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 06-17-2012 , 11:19   Re: RGB, RGBA, Hex
Reply With Quote #2

Ok, sry. I take this second post

hex-triple to back decimal-triple (explain later)
PHP Code:
    new my_color 0x05C8FF;
    new 
r,g,b;
    
= ((my_color >> 16) & 0xFF);
    
= ((my_color >> 8) & 0xFF);
    
= ((my_color >> 0) & 0xFF);

    
PrintToChatAll("Hex %06X = R %i, G %i, B %i"my_colorrgb); 

Last edited by Bacardi; 06-17-2012 at 11:22.
Bacardi is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-24-2012 , 13:36   Re: RGB, RGBA, Hex
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
There have been this new chat color feature in few source games for a while,.
I knew about TF2, but which other mods use it ? I'm rather certain CS:S doesn't.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-24-2012 , 13:39   Re: RGB, RGBA, Hex
Reply With Quote #4

Quote:
Originally Posted by RedSword View Post
I knew about TF2, but which other mods use it ? I'm rather certain CS:S doesn't.
Everything on the 2009 engine.
TF2, CS:S, HL2DM, DOD:S, Garry's Mod, etc.
__________________

Last edited by asherkin; 06-24-2012 at 13:39.
asherkin is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-24-2012 , 14:35   Re: RGB, RGBA, Hex
Reply With Quote #5

Quote:
Originally Posted by asherkin View Post
Everything on the 2009 engine.
TF2, CS:S, HL2DM, DOD:S, Garry's Mod, etc.
Oh shit. Tested and you're right. Why no one did talk about CS:S -_-' (only heard about TF2 before ).

Thanks Asherkin, and thanks for the tutorial Bacardi.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work

Last edited by RedSword; 06-24-2012 at 14:37.
RedSword is offline
kileedyg
BANNED
Join Date: Dec 2008
Location: Lithuania
Old 06-24-2012 , 15:12   Re: RGB, RGBA, Hex
Reply With Quote #6

is dis possible to make in gldsrc?
kileedyg is offline
Send a message via Skype™ to kileedyg
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 06-24-2012 , 16:16   Re: RGB, RGBA, Hex
Reply With Quote #7

Quote:
Originally Posted by RedSword View Post
Oh shit. Tested and you're right. Why no one did talk about CS:S -_-' (only heard about TF2 before ).
funny, what a coincidence
[SOLVED][CSS] How to use multiple team colors in one message
Bacardi is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 06-24-2012 , 17:21   Re: RGB, RGBA, Hex
Reply With Quote #8

Quote:
Originally Posted by RedSword View Post
Oh shit. Tested and you're right. Why no one did talk about CS:S -_-' (only heard about TF2 before ).

Thanks Asherkin, and thanks for the tutorial Bacardi.
Few plugins that use this already for CSS... YOu must have not looked hard enough.
https://forums.alliedmods.net/showthread.php?t=186784
https://forums.alliedmods.net/showthread.php?t=187570
https://forums.alliedmods.net/showthread.php?t=186340
https://forums.alliedmods.net/showthread.php?t=186695
cople of posts that have in-game picutes:
https://forums.alliedmods.net/showpo...7&postcount=14
https://forums.alliedmods.net/showpo...0&postcount=36
Mitchell is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-24-2012 , 19:47   Re: RGB, RGBA, Hex
Reply With Quote #9

Quote:
Originally Posted by Mitchell View Post
Few plugins that use this already for CSS... YOu must have not looked hard enough[...]
Quote from yourself :
Quote:
Originally Posted by Mitchell View Post
It came out 10 days after tf2 was updated.
http://store.steampowered.com/news/8037/
And I'm terribly sorry that I've not been aware of the Steam update that made a TF2-only features at first check be available in other games. I'll go ***p myself a couple of time for your **n *******e.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 06-26-2012 , 13:30   Re: RGB, RGBA, Hex
Reply With Quote #10

Quote:
Originally Posted by RedSword View Post
Quote from yourself :

And I'm terribly sorry that I've not been aware of the Steam update that made a TF2-only features at first check be available in other games. I'll go slap myself a couple of time for your **n *******e.
The chat handler is on all orangebox game, each game has the specific original colors, like how tf2 had the white color as the default, and css had the yellow color as default. Sorry being rude about it i was just posting some topics corresponding with Bascadi's Post.
Mitchell is offline
Reply


Thread Tools
Display Modes

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:17.


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