Rules FAQ Members List Search Register Login

 Raised This Month: \$62 Target: \$400 15%

Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
06-17-2012 , 10:47   RGB, RGBA, Hex
#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).
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  ```
Same example but with advanced formatting (%02X)
• %: always required
• 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

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) << 8 );        // Blue   ----FF--     my_color |=    ( (50  & 255) << 0 );        // 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
Attached Thumbnails

Attached Files
 test.phrases.txt (648 Bytes, 40 views)

Last edited by Bacardi; 01-05-2019 at 18:17. Reason: clarify =|
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
 06-17-2012 , 11:19   Re: RGB, RGBA, Hex #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;    r = ((my_color >> 16) & 0xFF);    g = ((my_color >> 8) & 0xFF);    b = ((my_color >> 0) & 0xFF);    PrintToChatAll("Hex %06X = R %i, G %i, B %i", my_color, r, g, b);  ``` Last edited by Bacardi; 06-17-2012 at 11:22.
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
06-24-2012 , 13:36   Re: RGB, RGBA, Hex
#3

Quote:
 Originally Posted by Bacardi 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
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
06-24-2012 , 13:39   Re: RGB, RGBA, Hex
#4

Quote:
 Originally Posted by RedSword 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.
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
06-24-2012 , 14:35   Re: RGB, RGBA, Hex
#5

Quote:
 Originally Posted by asherkin 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.
kileedyg
BANNED
Join Date: Dec 2008
Location: Lithuania
 06-24-2012 , 15:12   Re: RGB, RGBA, Hex #6 is dis possible to make in gldsrc?
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
06-24-2012 , 16:16   Re: RGB, RGBA, Hex
#7

Quote:
 Originally Posted by RedSword 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
Mitchell
~lick~
Join Date: Mar 2010
06-24-2012 , 17:21   Re: RGB, RGBA, Hex
#8

Quote:
 Originally Posted by RedSword 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.
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
SourceMod Plugin Approver
Join Date: Mar 2006
06-24-2012 , 19:47   Re: RGB, RGBA, Hex
#9

Quote:
 Originally Posted by Mitchell Few plugins that use this already for CSS... YOu must have not looked hard enough[...]
Quote from yourself :
Quote:
 Originally Posted by Mitchell 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
Mitchell
~lick~
Join Date: Mar 2010
06-26-2012 , 13:30   Re: RGB, RGBA, Hex
#10

Quote:
 Originally Posted by RedSword 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.
__________________

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Server Discussion     Source Servers (SRCDS)     HL1 Servers (HLDS) AMX Mod X     News     Bug Reports     General     Off-Topic     Plugins         Suggestions / Requests         Approved Plugins         New Plugin Submissions         Unapproved/Old Plugins         Translation Request         High-Traffic Plugins             GunGame             UAIO (Ultimate All-In-One Plugin)             xREDIRECT             CSDM             AMX Super             RuneMod             Zombie Plague Mod             SuperHero Mod                 News                 Tech Support                 Scripting Help                 Off-Topic / General Chat                 Heroes                     Suggestions / Requests                     Approved Heroes                     New Submissions                     Unapproved/Old Heroes                         Module Heroes                     SuperHero Mod Stats - By 123                 (OLD) Bug Reports     Scripting         Scripting Help         Code Snippets/Tutorials         Module Coding     Donor Access SourceMod     News     General     Plugins         Plugins         Unapproved Plugins         Plugin/Gameplay Ideas and Requests         High-Traffic Plugins             SourceMod Anti-Cheat             Zombie:Reloaded             SourceBans             VSH / Freak Fortress             Store             SM_Hosties             HLstatsX:CE     Scripting     Extensions     Snippets and Tutorials     Donor Access     Metamod: Source         Metamod:Source Plugins         Metamod:Source Questions         Coding MM:S Plugins & SM Extensions Hosted Stuff     Asherkin's Plugins         TF2Items         TFDodgeball         SteamTools     Bail's Plugins         CSDM         CS:S DM Off-Topic & Trash     Off-Topic     Trash

All times are GMT -4. The time now is 08:58.

 DMCA - Archive - Top