Well I saw a real lack of basic useful JASS functions so heres three nice easy ones that involve player colour codes. (the bottom one is by me)
function GetPlayerColorString
takes player p,
string s
returns string local playercolor c = GetPlayerColor
(p
) if c == PLAYER_COLOR_RED
then set s =
"|cffFF0202" + s +
"|r" elseif c == PLAYER_COLOR_BLUE
then set s =
"|cff0041FF" + s +
"|r" elseif c == PLAYER_COLOR_CYAN
then set s =
"|cff1BE5B8" + s +
"|r" elseif c == PLAYER_COLOR_PURPLE
then set s =
"|cff530080" + s +
"|r" elseif c == PLAYER_COLOR_YELLOW
then set s =
"|cffFFFC00" + s +
"|r" elseif c == PLAYER_COLOR_ORANGE
then set s =
"|cffFE890D" + s +
"|r" elseif c == PLAYER_COLOR_GREEN
then set s =
"|cff1FBF00" + s +
"|r" elseif c == PLAYER_COLOR_PINK
then set s =
"|cffE45AAF" + s +
"|r" elseif c == PLAYER_COLOR_LIGHT_GRAY
then set s =
"|cff949596" + s +
"|r" elseif c == PLAYER_COLOR_LIGHT_BLUE
then set s =
"|cff7DBEF1" + s +
"|r" elseif c == PLAYER_COLOR_AQUA
then set s =
"|cff0F6145" + s +
"|r" elseif c == PLAYER_COLOR_BROWN
then set s =
"|cff4D2903" + s +
"|r" else set s =
"|cffFFFFFF" + s +
"|r" endif set c =
null return s
endfunction
Like other Player Color String functions, but takes the string to colorize to be slightly more efficient
function GetPlayerColorString
takes player p
returns string//Credits to Andrewgosu from TH for the color codes// local playercolor c = GetPlayerColor
(p
) local string s
if c == PLAYER_COLOR_RED
then set s =
"|cffFF0202" elseif c == PLAYER_COLOR_BLUE
then set s =
"|cff0041FF" elseif c == PLAYER_COLOR_CYAN
then set s =
"|cff1BE5B8" elseif c == PLAYER_COLOR_PURPLE
then set s =
"|cff530080" elseif c == PLAYER_COLOR_YELLOW
then set s =
"|cffFFFC00" elseif c == PLAYER_COLOR_ORANGE
then set s =
"|cffFE890D" elseif c == PLAYER_COLOR_GREEN
then set s =
"|cff1FBF00" elseif c == PLAYER_COLOR_PINK
then set s =
"|cffE45AAF" elseif c == PLAYER_COLOR_LIGHT_GRAY
then set s =
"|cff949596" elseif c == PLAYER_COLOR_LIGHT_BLUE
then set s =
"|cff7DBEF1" elseif c == PLAYER_COLOR_AQUA
then set s =
"|cff0F6145" elseif c == PLAYER_COLOR_BROWN
then set s =
"|cff4D2903" else set s =
"|cffFFFFFF" endif set c =
null return s
endfunction
This function returns the player colour code in case you want to use it for another function. e.g :
Quote:
Originally Posted by PurgeandFire111
call BJDebugMsg(GetPlayerColorString(p)+" This is orange text|r")
It'll display this:
Player 5 (Orange) This is orange text|r
If you want, I guess you could remove the GetPlayerName+|r and instead have this function.
function PlayerColorText takes player whichPlayer, string text returns string return GetPlayerColorString (whichPlayer )+text+ "|r"endfunction
|
GetPlayerNameColoured
I did not create the first of this type, but I did this one from scratch:
function GetPlayerNameColoured
takes player p
returns string local playercolor pc = GetPlayerColor
(p
) local string s
if pc == PLAYER_COLOR_RED
then set s =
"|cffFF0202"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_BLUE
then set s =
"|cff0041FF"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_CYAN
then set s =
"|Cff1BE5B8"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_PURPLE
then set s =
"|CFF530080"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_YELLOW
then set s =
"|CFFFFFC00"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_ORANGE
then set s =
"|CFFFE890D"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_GREEN
then set s =
"|CFF1FBF00"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_PINK
then set s =
"|CFFE45AAF"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_LIGHT_GRAY
then set s =
"|CFF949596"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_LIGHT_BLUE
then set s =
"|CFF7DBEF1"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_AQUA
then set s =
"|CFF0F6145"+GetPlayerName
(p
)+
"|r" elseif pc == PLAYER_COLOR_BROWN
then set s =
"|CFF4D2903"+GetPlayerName
(p
)+
"|r" else // A safty function set s =
"|CFFFFFFFF"+GetPlayerName
(p
)+
"|r" endif set pc =
null return s
endfunction Credit to PurgeAndFire for the colour scripts.
The function returns the players name coloured, according to what colour he/she is. It does not return the color based on what playerslot the player is in, and is compatible with changing player colors.
- Kixer
Updated:
Fixed the colours using a program called Chaos Spectrum by Fougie47, hopefully they are correct now.
The playercolor pc is nulled because it is a handle.
Updated:
Now uses the colour codes that have been suggested as they seem to be correct.
*Updated*