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

RGB, RGBA, Hex


Post New Thread Reply   
 
Thread Tools Display Modes
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-26-2012 , 14:43   Re: RGB, RGBA, Hex
Reply With Quote #11

If you're writing a plugin that may be used on other versions of the game engine (such as L4D or L4D2), you can check the SDK Version.

PHP Code:
if (SOURCE_SDK_EPISODE2VALVE <= GuessSDKVersion() < SOURCE_SDK_LEFT4DEAD)
{
    
// Supports \x07 and \x08 codes

It'd be nice if we had an actual capability for this registered with SourceMod so we could rely on a less hacky method, though.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-26-2012 at 14:48.
Powerlord is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-26-2012 , 15:37   Re: RGB, RGBA, Hex
Reply With Quote #12

Quote:
Originally Posted by Powerlord View Post
If you're writing a plugin that may be used on other versions of the game engine (such as L4D or L4D2), you can check the SDK Version.

PHP Code:
if (SOURCE_SDK_EPISODE2VALVE <= GuessSDKVersion() < SOURCE_SDK_LEFT4DEAD)
{
    
// Supports \x07 and \x08 codes

It'd be nice if we had an actual capability for this registered with SourceMod so we could rely on a less hacky method, though.
It would be exactly the same check... just in SourceMod, it doesn't magically know the client supports handling the extra codes.
__________________
asherkin is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-26-2012 , 15:46   Re: RGB, RGBA, Hex
Reply With Quote #13

Quote:
Originally Posted by asherkin View Post
It would be exactly the same check... just in SourceMod, it doesn't magically know the client supports handling the extra codes.
The problem with the check as I wrote it is that is depends on a contiguous set of versions supporting it.

However, CS:GO will likely support this. SOURCE_SDK_CSGO is higher than SOURCE_SDK_ALIENSWARM, meaning we now have two range checks:

PHP Code:
if (SOURCE_SDK_EPISODE2VALVE <= GuessSDKVersion() < SOURCE_SDK_LEFT4DEAD || GuessSDKVersion() >= SOURCE_SDK_CSGO)
{

and then if the game after CS:GO doesn't support color codes, then this code has to be adjusted again to add an upper bounds check to the second range.

Whereas SourceMod could just add a capabilities string to it that we could check and all this nasty code would be abstracted away into the core.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-26-2012 at 15:46.
Powerlord is offline
StrikerMan780
AlliedModders Donor
Join Date: Jul 2009
Location: Canada
Old 07-03-2013 , 21:07   Re: RGB, RGBA, Hex
Reply With Quote #14

Could one explain how to do this if the Hex color is a string?

I want to convert... say... String:Color[7]="FF0000";

to

r = 255;
g = 0;
b = 0;
StrikerMan780 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 07-03-2013 , 21:41   Re: RGB, RGBA, Hex
Reply With Quote #15

Quote:
Originally Posted by Powerlord View Post
The problem with the check as I wrote it is that is depends on a contiguous set of versions supporting it.

However, CS:GO will likely support this. SOURCE_SDK_CSGO is higher than SOURCE_SDK_ALIENSWARM, meaning we now have two range checks:

PHP Code:
if (SOURCE_SDK_EPISODE2VALVE <= GuessSDKVersion() < SOURCE_SDK_LEFT4DEAD || GuessSDKVersion() >= SOURCE_SDK_CSGO)
{

and then if the game after CS:GO doesn't support color codes, then this code has to be adjusted again to add an upper bounds check to the second range.

Whereas SourceMod could just add a capabilities string to it that we could check and all this nasty code would be abstracted away into the core.
GuessSDKVersion will eventually™ be deprecated and replaced with a similar function that doesn't guarantee chronological order. Ranges don't make much sense when updates can cause some games/engines/whatever to suddenly be on a newer version than others (TF2, CS:S, HL2DM, DOD:S, SDK Base 2013, I'm looking at you).
psychonic is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 07-07-2013 , 05:43   Re: RGB, RGBA, Hex
Reply With Quote #16

Quote:
Originally Posted by StrikerMan780 View Post
Could one explain how to do this if the Hex color is a string?

I want to convert... say... String:Color[7]="FF0000";

to

r = 255;
g = 0;
b = 0;

StringToIntEx

This work with hex-triplet (FF0000) , but give wrong results with hex-quadruple (FF000000)...
PHP Code:
    new String:ColorString[]="FF0000";
    new 
ColorHexrgb;

    
StringToIntEx(ColorStringColorHex16); // <- Numerical base "16", hexadecimal

    
= ((ColorHex >> 16) & 255);
    
= ((ColorHex >> 8) & 255);
    
= ((ColorHex >> 0) & 255);
    
PrintToServer("%s\n%02X\nr = %i, g = %i, b = %i"ColorStringColorHexrgb); 
And remember, lower case letters give different results than upper case letters, ff != FF *false info

some crappy thing
__________________
Do not Private Message @me

Last edited by Bacardi; 07-07-2013 at 08:45.
Bacardi is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-07-2013 , 08:26   Re: RGB, RGBA, Hex
Reply With Quote #17

Quote:
Originally Posted by Bacardi View Post
And remember, lower case letters give different results than upper case letters, ff != FF
What?
__________________
asherkin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 07-07-2013 , 08:47   Re: RGB, RGBA, Hex
Reply With Quote #18

Quote:
Originally Posted by asherkin View Post
What?
Sry, false info. Works fine with upper/lower cases
__________________
Do not Private Message @me
Bacardi is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 07-15-2013 , 10:42   Re: RGB, RGBA, Hex
Reply With Quote #19

May be useful for some people to know that some color values are stored as bgr integers, rather than the traditional rgb.. Like fog controllers.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 08-06-2013 , 22:58   Re: RGB, RGBA, Hex
Reply With Quote #20

Wow heh, the function I made to convert RGB to Hex was large and I knew there was some easier way I didn't know about to convert properly. Also this was made when I was pretty new to programming so it has pretty bad etiquette.

PHP Code:
RGBToHex(redIntgreenIntblueIntclient)
{
    new 
Float:redFloat float(redInt), Float:greenFloat float(greenInt), Float:blueFloat float(blueInt);
    
redFloat redFloat/16greenFloat greenFloat/16blueFloat blueFloat/16;
    new 
Float:DecRed FloatFraction(redFloat), Float:DecGreen FloatFraction(greenFloat), Float:DecBlue FloatFraction(blueFloat);
    
redFloat-=DecRedgreenFloat -= DecGreenblueFloat-=DecBlue;
    
DecRed *= 16DecGreen *=16DecBlue *=16;
    
redInt RoundToZero(redFloat), greenInt RoundToZero(greenFloat), blueInt RoundToZero(blueFloat);
    new 
IntDecRed RoundToZero(DecRed), IntDecGreen RoundToZero(DecGreen), IntDecBlue RoundToZero(DecBlue);
    
decl String:Red1[4], String:Red2[4], String:Green1[4], String:Green2[4], String:Blue1[4], String:Blue2[4];
    
IntToString(redIntRed1sizeof(Red1)); IntToString(IntDecRedRed2sizeof(Red2));
    
IntToString(greenIntGreen1sizeof(Green1)); IntToString(IntDecGreenGreen2sizeof(Green2));
    
IntToString(blueIntBlue1sizeof(Blue1)); IntToString(IntDecBlueBlue2sizeof(Blue2));
    if (
StrEqual(Red1"10"false)) Red1="A"; if (StrEqual(Red2"10"false)) Red2="A";
    if (
StrEqual(Green1"10"false)) Green1="A"; if (StrEqual(Green2"10"false)) Green2="A";
    if (
StrEqual(Blue1"10"false)) Blue1="A"; if (StrEqual(Blue2"10"false)) Blue2="A";
    if (
StrEqual(Red1"11"false)) Red1="B"; if (StrEqual(Red2"11"false)) Red2="B";
    if (
StrEqual(Green1"11"false)) Green1="B"; if (StrEqual(Green2"11"false)) Green2="B";
    if (
StrEqual(Blue1"11"false)) Blue1="B"; if (StrEqual(Blue2"11"false)) Blue2="B";
    if (
StrEqual(Red1"12"false)) Red1="C"; if (StrEqual(Red2"12"false)) Red2="C";
    if (
StrEqual(Green1"12"false)) Green1="C"; if (StrEqual(Green2"12"false)) Green2="C";
    if (
StrEqual(Blue1"12"false)) Blue1="C"; if (StrEqual(Blue2"12"false)) Blue2="C";
    if (
StrEqual(Red1"13"false)) Red1="D"; if (StrEqual(Red2"13"false)) Red2="D";
    if (
StrEqual(Green1"13"false)) Green1="D"; if (StrEqual(Green2"13"false)) Green2="D";
    if (
StrEqual(Blue1"13"false)) Blue1="D"; if (StrEqual(Blue2"13"false)) Blue2="D";
    if (
StrEqual(Red1"14"false)) Red1="E"; if (StrEqual(Red2"14"false)) Red2="E";
    if (
StrEqual(Green1"14"false)) Green1="E"; if (StrEqual(Green2"14"false)) Green2="E";
    if (
StrEqual(Blue1"14"false)) Blue1="E"; if (StrEqual(Blue2"14"false)) Blue2="E";
    if (
StrEqual(Red1"15"false)) Red1="F"; if (StrEqual(Red2"15"false)) Red2="F";
    if (
StrEqual(Green1"15"false)) Green1="F"; if (StrEqual(Green2"15"false)) Green2="F";
    if (
StrEqual(Blue1"15"false)) Blue1="F"; if (StrEqual(Blue2"15"false)) Blue2="F";
    
decl String:buffer[100];
    
Format(buffersizeof(buffer), "%s%s%s%s%s%s"Red1Red2Green1Green2Blue1Blue2);
    
CPrintToChat(client"[SM] \x07%sThis text is the color of your model."buffer);

blaacky 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 04:30.


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