Change transparency of a players color.
#1

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
Reply
#2

You can get the player's color by using GetPlayerColor. Add this under your includes/defines:

pawn Код:
new playercolor;


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.
Reply
#3

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
Reply
#4

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
Reply
#5

Brilliant!!! Thats exactly what I wanted, thanks so much!



David
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)