Change transparency of a players color. - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Change transparency of a players color. (
/showthread.php?tid=88334)
Change transparency of a players color. -
pyrodave - 25.07.2009
I am working on a small project where a player can do something like /invis and the transparency part of thier hex color will be set to 00, however, I don't want the player to loose thier original color, so the players color is retrieved, and then the transparency of thier current colour set to 0, I have no idea how to do this, and some advice would be absolutely brilliant!
Thanks
David
Re: Change transparency of a players color. -
refshal - 25.07.2009
You can get the player's color by using
GetPlayerColor. Add this under your includes/defines:
Then add this on OnPlayerSpawn:
pawn Код:
playercolor = GetPlayerColor(playerid);
Now you've got a backup of the old color. Then you can use something like SetPlayerColor(playerid, playercolor); in some command to get the old color back.
Re: Change transparency of a players color. -
pyrodave - 25.07.2009
Yeah yeah i know that already, but im talking about changing the current players color by converting the decimal value which GetPlayerColor returns to hex and then altering the transparency, not just setting the players colour, the reason being, I dont want the player to appear black when tab is pushed.
Anyway, thanks for at least trying to help
Re: Change transparency of a players color. -
paytas - 26.07.2009
The formula is:
pawn Код:
color = (color & 0xFFFFFF00) | alpha
In example if you have a white color with no transparency and you want it half transparent:
pawn Код:
new color = 0xFFFFFFFF;
color = (color & 0xFFFFFF00) | 127;
//new value of color is 0xFFFFFF7F
In addition, if you want to know, here is how to change each color channels:
pawn Код:
//red:
color = (color & 0x00FFFFFF) | red << 24
//green:
color = (color & 0xFF00FFFF) | green << 16
//blue:
color = (color & 0xFFFF00FF) | blue << 8
And how to get the value of a channel:
pawn Код:
red = color >> 24 & 0xFF
green = color >> 16 & 0xFF
blue = color >> 8 & 0xFF
alpha = color & 0xFF
Re: Change transparency of a players color. -
pyrodave - 26.07.2009
Brilliant!!! Thats exactly what I wanted, thanks so much!
David