08.10.2013, 10:32
Hello,
I just cannot get it working, I tried many different converts but everything fails.
Right now I have the following;
I wan't players to enter a Hex color, and my script should convert it to a ARGB format for SetObjectMaterial.
So this is what I do,
I have this functions:
Then i use the following line to convert the color to this ARGB format:
I will show you some print lines;
The users input is: 0xFF0000FF (which is red)
The following code give me this result: FFFF0000
Now the ARGB converter gives me the following result: -16776961
And the material becomes blue instead of red.
So it seems i have to switch blue as red.
I tried that on different ways but it always becomes blue for some reason.
Someone know how to deal with this?
I just cannot get it working, I tried many different converts but everything fails.
Right now I have the following;
I wan't players to enter a Hex color, and my script should convert it to a ARGB format for SetObjectMaterial.
So this is what I do,
I have this functions:
Код:
stock ARGB( alpha, red, green, blue) { return alpha + (red * 16777216) + (green * 65536) + (blue * 256); } 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; }
Код:
ARGB(HexToInt(alpha), HexToInt(red), HexToInt(green), HexToInt(blue))
The users input is: 0xFF0000FF (which is red)
The following code give me this result: FFFF0000
Код:
printf("%s%s%s%s",alpha,red,green,blue);
And the material becomes blue instead of red.
So it seems i have to switch blue as red.
I tried that on different ways but it always becomes blue for some reason.
Someone know how to deal with this?