SetObjectMaterial Color problem..
#4

I re-read your threads many times but I couldn't understand what exactly you wanted to do.

Let's say a player types 0xFF0000FF like your example which is red, then you get the integer value of that hex (from the string) when you use HexToInt function.

However, if you want to get the A R G B values from the hex (for example: A R G B - 255 255 0 0), I edited the function you used in order to get R G B A values from the hex as a string and stores the values on them by reference. Then you can call ARGB with the values and get the integer value of it.

pawn Код:
public OnFilterScriptInit( )
{
    new
        red,
        green,
        blue,
        alpha,
        color
    ;
    HexStrToRGBA( "0xFF0000FF", red, green, blue, alpha );
    printf( "R: %d, G: %d, B: %d, A: %d", red, green, blue, alpha );
    color = ARGB( alpha, red, green, blue );
    printf( "color: %d", color );
    return 1;
}

stock HexStrToRGBA( string[ ], &red, &green, &blue, &alpha )
{
    if( !strlen( string ) ) return 0;
   
    new
        cur,
        res,
        str[ 4 ][ 3 ]
    ;
   
    strmid( str[ 0 ], string, 2, 5, 3 );
    strmid( str[ 1 ], string, 4, 7, 3 );
    strmid( str[ 2 ], string, 6, 9, 3 );
    strmid( str[ 3 ], string, 8, 11, 3 );
   
    for( new j = 0; j < 4; j++ )
    {
        cur = 1;
        res = 0;
           
        for( new i = 2; i > 0; i-- )
        {
            if( str[ j ][ i - 1 ] < 58 ) res = res + cur * ( str[ j ][ i - 1 ] - 48 );
            else res = res + cur * ( str[ j ][ i - 1 ] - 65 + 10 );
            cur = cur * 16;
        }
       
        switch( j )
        {
            case 0: red = res;
            case 1: green = res;
            case 2: blue = res;
            case 3: alpha = res;
        }
    }
    return 1;
}

stock ARGB( alpha, red, green, blue)
{
    return alpha + ( red * 16777216 ) + ( green * 65536 ) + ( blue * 256 );
}
pawn Код:
// Inserting: 0xFF0000FF

// Output from the above:
R: 255, G: 0, B: 0, A: 255
color: -16776961

// Output from HexToInt:
-16776961
If you do not want to get the values of RGBA, then use HexToInt instead.
Reply


Messages In This Thread
SetObjectMaterial Color problem.. - by Roel - 08.10.2013, 10:32
Re: SetObjectMaterial Color problem.. - by Vince - 08.10.2013, 11:09
Re: SetObjectMaterial Color problem.. - by Roel - 08.10.2013, 12:19
Re: SetObjectMaterial Color problem.. - by Konstantinos - 08.10.2013, 12:39
Re: SetObjectMaterial Color problem.. - by Roel - 08.10.2013, 13:00
Re: SetObjectMaterial Color problem.. - by Konstantinos - 08.10.2013, 13:04

Forum Jump:


Users browsing this thread: 1 Guest(s)