SA-MP Forums Archive
Is there a way to define color with number ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Is there a way to define color with number ? (/showthread.php?tid=462119)



Is there a way to define color with number ? - bustern - 05.09.2013

I am trying to make color saving system, but Y_INI system can save only numbers, and i tryied to #define 3 0xFFFF00AA
But i cant, so is there a way to define color with number or another way to save colors ?


Re: Is there a way to define color with number ? - FiReAlEx - 05.09.2013

You can save it with words.
#define Yellow 0xFFFF00AA


Re: Is there a way to define color with number ? - bustern - 05.09.2013

Nope, i tried and in .INI file it looks like that:Color: -12312


Re: Is there a way to define color with number ? - bustern - 05.09.2013

The problem is:When i try to make color saving system, colors in USER file .INI shows -2321321


Re: Is there a way to define color with number ? - bustern - 05.09.2013

I want that too I am using register system which is using Y_INI...


Re: Is there a way to define color with number ? - Lorenc_ - 05.09.2013

pawn Код:
/** BY DRACOBLUE
 *  Return the value of an hex-string
 *  @param string
 */

stock HexToInt(string[]) {
    if (string[0]==0) return 0;
    new i;
    new cur=1;
    new res=0;
    for (i=strlen(string);i>0;i--) {
        if (string[i-1]<58) res=res+cur*(string[i-1]-48); else res=res+cur*(string[i-1]-65+10);
        cur=cur*16;
    }
    return res;
}
All hex codes output an integer, for example 0xFFFFFFFF outputs -1.

The function I supplied you will convert your hexidecimal into an integer for you. You can always use an integer as a colour on functions, for example:

pawn Код:
// Player's Colour
SetPlayerColor( playerid, -1 ); // Will give white

//Client message
SendClientMessage( playerid, -255, "Hello World!" ); // Might give black (haven't tried)
All you do is save the output from that function to your ini. To load it, just retrieve it as an integer and store it in a variable.

I hope I helped!