AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   RGB, RGBA, Hex (https://forums.alliedmods.net/showthread.php?t=187746)

Bacardi 06-17-2012 10:47

RGB, RGBA, Hex
 
2 Attachment(s)
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" https://dl.dropbox.com/u/38118182/pi...color_text.png
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 https://dl.dropbox.com/u/38118182/pi...text_alpha.png
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.
https://dl.dropbox.com/u/38118182/pi...olor_text2.png
PHP Code:

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

---

We can do also this in translation files, not need edit plugin :3
I attached test translation phrase, hope those characters not get erased after uploading here.
https://forums.alliedmods.net/attach...7&d=1546730165

More here #22


Sry for bad english and lot of text with misspellings, typos, wrong info.
*edit
Use NotePad++

Bacardi 06-17-2012 11:19

Re: RGB, RGBA, Hex
 
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); 


RedSword 06-24-2012 13:36

Re: RGB, RGBA, Hex
 
Quote:

Originally Posted by Bacardi (Post 1730490)
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.

asherkin 06-24-2012 13:39

Re: RGB, RGBA, Hex
 
Quote:

Originally Posted by RedSword (Post 1735255)
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.

RedSword 06-24-2012 14:35

Re: RGB, RGBA, Hex
 
Quote:

Originally Posted by asherkin (Post 1735256)
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 :3).

Thanks Asherkin, and thanks for the tutorial Bacardi.

kileedyg 06-24-2012 15:12

Re: RGB, RGBA, Hex
 
is dis possible to make in gldsrc?

Bacardi 06-24-2012 16:16

Re: RGB, RGBA, Hex
 
Quote:

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

funny, what a coincidence :3
[SOLVED][CSS] How to use multiple team colors in one message

Mitchell 06-24-2012 17:21

Re: RGB, RGBA, Hex
 
Quote:

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

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

RedSword 06-24-2012 19:47

Re: RGB, RGBA, Hex
 
Quote:

Originally Posted by Mitchell (Post 1735355)
Few plugins that use this already for CSS... YOu must have not looked hard enough[...]

Quote from yourself :
Quote:

Originally Posted by Mitchell (Post 1729492)
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.

Mitchell 06-26-2012 13:30

Re: RGB, RGBA, Hex
 
Quote:

Originally Posted by RedSword (Post 1735456)
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.


All times are GMT -4. The time now is 03:42.

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