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", 4, 8, 16); // Show RGB decimal-triplet in hex, would be 4810
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", 4, 8, 16); // 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) << 8 ); // Green --C8--
my_color |= ( (255 & 0xFF) << 0 ); // Blue ----FF
PrintToChatAll("%06X", my_color); // Output will be 05C8FF
Explain to me
Prefix 0x will be a hexadecimal value. So 0xFF is equal in decimal to 255
0xF = 15
0x13 = 19
Simple
Bitwise AND operator (&) will compares each bit of its first operand to the corresponding bit of the second operand.
Like this:
11111111 // 255
100001110 // 270
----------
00001110 // 14, begin to calculate the start when value get over 255
Bitwise left shift operators (<<) will "shift" our one byte hexadecimal (8 bits) to left.
Like this:
Code:
before 00000101 // 5
(5 & 255) << 16 // Red channel
after 000001010000000000000000 // 327680
before 11001000 // 200
(200 & 255) << 8 // Green channel
after 1100100000000000 // 51200
before 11111111 // 255
(255 & 255) << 0 // Blue channel
after 11111111 // 255
Bitwise OR assignment (=|)Obtain the bitwise inclusive OR of the first and second operands; store the result in the object specified by the first operand. Bitwise inclusive OR operator (|) compares the values (in binary format) of each operand and yields a value whose bit pattern shows which bits in either of the operands has the value 1.
If both of the bits are 0, the result of that bit is 0; otherwise, the result is 1.
Like this:
Code:
00000000 00000000 00000000 // my_color // empty variable 0
00000101 00000000 00000000 // my_color |= ( (5 & 255) << 16 ); // Red
------------------------
00000101 00000000 00000000 // my_color // Have Red, Dec 327680
00000101 00000000 00000000 // my_color // Have Red, Dec 327680
00000000 11001000 00000000 // my_color |= ( (200 & 255) << 8 ); // Green
------------------------
00000101 11001000 00000000 // my_color // Have Red and Green, Dec 378880
00000101 11001000 00000000 // my_color // Have Red and Green, Dec 378880
00000000 00000000 11111111 // my_color |= ( (255 & 255) << 0 ); // Blue
------------------------
00000101 11001000 11111111 // my_color = 379135 // Red Geen Blue channels
Hex-triplet need to be 6 digit in hexadecimal, remember those leading zeros.
Code:
PrintToChatAll("%06X", my_color); //We get hex-triplet 05C8FF
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)
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.
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.
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.