• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Snippet] GetPlayerColorString

Level 9
Joined
Jul 27, 2006
Messages
652
JASS:
library GetPlayerColorString
//Credits to Andrewgosu, Silvenon, PurgeAndFire111 for the script

globals
    private string array str
endglobals

function GetPlayerColorString takes player p returns string
    return str[GetHandleId(GetPlayerColor(p))]
endfunction

function GetPlayerColorText takes player p, string s returns string
    return GetPlayerColorString(p) + s + "|r"
endfunction

function GetPlayerNameColored takes player p returns string
    return GetPlayerColorText(p, GetPlayerName(p))
endfunction

private module M
    static method onInit takes nothing returns nothing
        set str[0] = "|cffFF0202"
        set str[1] = "|cff0041FF"
        set str[2] = "|cff1BE5B8"
        set str[3] = "|cff530080"
        set str[4] = "|cffFFFC00"
        set str[5] = "|cffFE890D"
        set str[6] = "|cff1FBF00"
        set str[7] = "|cffE45AAF"
        set str[8] = "|cff949596"
        set str[9] = "|cff7DBEF1"
        set str[10] = "|cff0F6145"
        set str[11] = "|cff4D2903"
    endmethod
endmodule
private struct S
    implement M
endstruct

endlibrary

JASS:
call BJDebugMsg(GetPlayerColorText(p, GetPlayerName(p) + " this is orange text!"))

It'll display this:
Player 5 (Orange) this is orange text!

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*

Updated once and for all by Bribe for much better performance.
 
Last edited by a moderator:
Damn you... Damn you!! Damn you so much... :p

The thing is, I made this one a while back. Technically, Diablo-dk did part of it and I finished it then he made more crazy stuff and stuff. The color codes seem kind of incorrect, maybe you should use Andrewgosu's; or just use my code:
JASS:
function GetPlayerColorString takes player p returns string
//Credits to Andrewgosu from TH for the color codes//
    local playercolor c = GetPlayerColor(p)
    if c == PLAYER_COLOR_RED then
        return "|cffFF0202"
    elseif c == PLAYER_COLOR_BLUE then
        return "|cff0041FF"
    elseif c == PLAYER_COLOR_CYAN then
        return "|cff1BE5B8"
    elseif c == PLAYER_COLOR_PURPLE then
        return "|cff530080"
    elseif c == PLAYER_COLOR_YELLOW then
        return "|cffFFFC00"
    elseif c == PLAYER_COLOR_ORANGE then
        return "|cffFE890D"
    elseif c == PLAYER_COLOR_GREEN then
        return "|cff1FBF00"
    elseif c == PLAYER_COLOR_PINK then
        return "|cffE45AAF"
    elseif c == PLAYER_COLOR_LIGHT_GRAY then
        return "|cff949596"
    elseif c == PLAYER_COLOR_LIGHT_BLUE then
        return "|cff7DBEF1"
    elseif c == PLAYER_COLOR_AQUA then
        return "|cff0F6145"
    elseif c == PLAYER_COLOR_BROWN then
        return "|cff4D2903" 
    else
        return "|cffFFFFFF"
    endif
endfunction
I don't think playercolor's would need to be nulled... Though I'm not sure. I just know it isn't a very big leak. :D

But your's is good. +rep
 
Level 9
Joined
Jul 27, 2006
Messages
652
Ok I'll update the colours asap, probably later today or at least by tomorrow...
 
Level 9
Joined
Jul 27, 2006
Messages
652
*Script Updated*
Now the colours are correct ( or to close to be noticably wrong ).
Also fixed a major stupid mistake with the use of light blue twice.
 
Level 9
Joined
Jul 27, 2006
Messages
652
*Updated*
Updated again to now use the suggested and seemingly preferred colour codes.
Thanks to all that made suggestions and pointed out mistakes.
 
I think you should remove the "GetPlayerName(p)" for the "set s = " part.

The thing is, some people might just want the color. So if they did this:
JASS:
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.

JASS:
function PlayerColorText takes player whichPlayer, string text returns string
    return GetPlayerColorString(whichPlayer)+text+"|r"    
endfunction

:thumbs_up:
 
Level 9
Joined
Jul 27, 2006
Messages
652
Thank you Purple,
Im going to update this and change it into player colour string functions if no one minds.
I'll add Purge's GetPlayerColourString and maybe a few examples of use later today...
 
Ow man you really had to use so many "elseif"-s...

JASS:
globals
string array GPC_PCString
endglobals

library GPC
function GetPlayerColour takes player p returns string
return GPC_PCString[GetPlayerId(p)]
endfunction

function GetPlayerNameColoured takes player p returns string
return GPC_PCString[GetPlayerId(p)]+GetPlayerName(p)+"|r"
endfunction

function GetPlayerIdColour takes integer i returns string
return GPC_PCString[i]
endfunction

function GetPlayerIdNameColoured takes integer i returns string
return GPC_PCString[i]+GetPlayerName(Player(i))+"|r"
endfunction

function InitTrig_GetPlayerColour takes nothing returns nothing
set GPC_PCString[0] = "|c00ff0000"
set GPC_PCString[1] = "|c000000ff"
set GPC_PCString[2] = "|c0018e7bd"
set GPC_PCString[3] = "|c00520084"
set GPC_PCString[4] = "|c00ffff00"
set GPC_PCString[5] = "|c00ff8a08"
set GPC_PCString[6] = "|c0018be00"
set GPC_PCString[7] = "|c00e759ad"
set GPC_PCString[8] = "|c00949694"
set GPC_PCString[9] = "|c007bbef7"
set GPC_PCString[10] = "|c00086142"
set GPC_PCString[11] = "|c004a2800"
endfunction
endlibrary

You could do it all this way, it is simplier, and waaay faster. These are 100% right colours, for nitpicking people like Thunder_eye :)
 

Attachments

  • Player Color Tag System.w3x
    11.8 KB · Views: 369
Level 9
Joined
Jul 27, 2006
Messages
652
There really is no need to use vJASS,
This is a simple new JASSer orientated script....
 
Level 9
Joined
Jul 27, 2006
Messages
652
Yes I know,
but none the less, this is a simple function and there is no need to use vJASS...
*Thread updates*
Could a mod rename this thread "Player Colour Code Funtions" or something of the like...
 
Level 6
Joined
Apr 16, 2007
Messages
177
Hum... Playercolors don't need to be nulled - they are permanent, just like players.
Using variables doesn't require vJASS, you can always just use the normal trigger initialisation. It won't be as easy to import into a map then, but heck - just who cares^^ Also you could do a 'declare on demand' approach, just declaring color codes when they are used for the first time. Is slower than the other approach, but does not require an init function.

Also, happytauren, your system (just like previously mine) will return the wrong color codes in a map where you can choose your player color in the lobby (some maps allow that). Look into my utilities library to see how you can fix that, if you want. Or just use my utilities library - you don't need the function calls there.
Just use PlayerName[ i ] and PlayerColor[ i ] for colored strings.
I don't know wether I'm using the absolutely correct color strings, though. I think I use the ones from JassShopPro, too.
And yes, I know JassHelper inlines the function calls. But I don't like function calls, anyway. I think a good array is much more beautiful.

Best regards, Davey
 
Level 9
Joined
Nov 28, 2008
Messages
704
JASS:
library Colors initializer Init_Colors
                    //Color codes for players. Has three functions: GPCC, GPCN, and GPCNU. It also includes the equivilent numbers for pings.
globals
    string array ColorCodes     //Variables are faster, and require much less if/then/elses.
    integer array ColorCodesRed
    integer array ColorCodesGreen
    integer array ColorCodesBlue
    real array ColorCodesRed1
    real array ColorCodesGreen1
    real array ColorCodesBlue1
endglobals

function GPCC takes integer i returns string //Short for Get Player Color Code
    if i > -1 and i < 12 then
        return ColorCodes[i]
    endif                                               //This should be used if you want to use custom names in a custom chat system using a different variable, or just coloring something randomly when you have no player, or coloring different parts off things different colors when people talk.. etc.
    return "|CFF000000"
endfunction

function GPCN takes player p returns string   //Short for Get Player Colored Name
    return ColorCodes[GetPlayerId(p)] + GetPlayerName(p) + "|r"         //Should be used when you want a colored player name.
endfunction

function GPCNU takes player p returns string //Short for Get Player Colored Name Unfinished (refering to the missing "|r".. could be used for rnadom things, I suppose. Like Mooglefrooglian the Nurb has fallen. "the Nurb" could be colored as well as the name.
    return ColorCodes[GetPlayerId(p)] + GetPlayerName(p)                    //Should be used when you want to add something else also colored the same as the name. I dont see much use, but hey, why not?
endfunction

function Init_Colors takes nothing returns nothing
    local integer i = 0
    set ColorCodes[0] = "|cFFff0303"
    set ColorCodes[1] = "|cFF0042ff"
    set ColorCodes[2] = "|cFF1ce6b9"
    set ColorCodes[3] = "|cFF540081"
    set ColorCodes[4] = "|cFFfffc01"
    set ColorCodes[5] = "|cfffe8a0e"   //Using data from [url]http://www.wc3campaigns.net/showpost.php?p=596801&postcount=5[/url]
    set ColorCodes[6] = "|cFF20c000"  //Its apparently copied directly from the war3.mpq itself, who am I to argue?
    set ColorCodes[7] = "|cFFe55bb0"
    set ColorCodes[8] = "|cFF959697"
    set ColorCodes[9] = "|cFF7ebff1"
    set ColorCodes[10] = "|cFF106246"
    set ColorCodes[11] = "|cFF4e2a04"
    
    // End of Player Colors.
    //Start of Integers.
    
    set ColorCodesRed[0] = 255
    set ColorCodesGreen[0] = 2
    set ColorCodesBlue[0] = 2
    set ColorCodesRed[1] = 0
    set ColorCodesGreen[1] = 65
    set ColorCodesBlue[1] = 255
    set ColorCodesRed[2] = 27
    set ColorCodesGreen[2] = 230
    set ColorCodesBlue[2] =  184
    set ColorCodesRed[3] = 83
    set ColorCodesGreen[3] = 0
    set ColorCodesBlue[3] = 128
    set ColorCodesRed[4] = 255
    set ColorCodesGreen[4] = 252
    set ColorCodesBlue[4] = 0
    set ColorCodesRed[5] = 254
    set ColorCodesGreen[5] = 137
    set ColorCodesBlue[5] =13
    set ColorCodesRed[6] = 31
    set ColorCodesGreen[6] = 191
    set ColorCodesBlue[6] =  0
    set ColorCodesRed[7] = 229
    set ColorCodesGreen[7] = 90
    set ColorCodesBlue[7] = 175
    set ColorCodesRed[8] = 148
    set ColorCodesGreen[8] = 149
    set ColorCodesBlue[8] = 150
    set ColorCodesRed[9] = 125
    set ColorCodesGreen[9] = 190
    set ColorCodesBlue[9] = 241
    set ColorCodesRed[10] = 15
    set ColorCodesGreen[10] = 97
    set ColorCodesBlue[10] = 69
    set ColorCodesRed[11] = 77
    set ColorCodesGreen[11] = 41
    set ColorCodesBlue[11] = 3
    
    //End of Integers
    //Start of 0.0-1.0 codes.
    
    loop
        exitwhen i > 11
        set ColorCodesRed1[i] = ColorCodesRed[i] / 255.0
        set ColorCodesGreen1[i] = ColorCodesGreen[i] / 255.0
        set ColorCodesBlue1[i] = ColorCodesBlue[i] / 255.0
        set i = i + 1
    endloop
    
endfunction

endlibrary
 
A better version of Mooglefrooglian's that takes into account the fact that player colours may be changed at map init.

JASS:
/*
Color codes for players. Has three functions: GPCC, GPCN, and GPCNU. It also includes the equivilent 
numbers for pings.
*/

library Colors initializer Init_Colors
                
globals
    string array ColorCodes //Variables are faster, and require much less if/then/elses.
    integer array ColorCodesRed
    integer array ColorCodesGreen
    integer array ColorCodesBlue
    real array ColorCodesRed1
    real array ColorCodesGreen1
    real array ColorCodesBlue1
endglobals

/*
Get Player Color Code

This should be used if you want to use custom names in a custom chat system using a different variable, 
or just coloring something randomly when you have no player, or coloring different parts off things 
different colors when people talk.
*/

function GPCC takes player p returns string
    if i > -1 and i < 12 then
        return ColorCodes[GetHandleId(GetPlayerColor(p))]
    endif
    return "|CFF000000"
endfunction

/*
Get Player Colored Name

Should be used when you want a colored player name.
*/

function GPCN takes player p returns string
    return ColorCodes[GetHandleId(GetPlayerColor(p))] + GetPlayerName(p) + "|r"
endfunction

/*
Get Player Colored Name Unfinished

This doesn't add the "|r" to the end of the string so you can have things after the name colored too.

Should be used when you want to add something else also colored the same as the name. I dont see much use, 
but hey, why not?
*/

function GPCNU takes player p returns string
    return ColorCodes[GetHandleId(GetPlayerColor(p))] + GetPlayerName(p)
endfunction

/*
Using data from [url]http://www.wc3campaigns.net/showpost.php?p=596801&postcount=5[/url]
Its apparently copied directly from the war3.mpq itself, who am I to argue?
*/

function Init_Colors takes nothing returns nothing
    local integer i = 0
    set ColorCodes[0] = "|cFFff0303"
    set ColorCodes[1] = "|cFF0042ff"
    set ColorCodes[2] = "|cFF1ce6b9"
    set ColorCodes[3] = "|cFF540081"
    set ColorCodes[4] = "|cFFfffc01"
    set ColorCodes[5] = "|cfffe8a0e" 
    set ColorCodes[6] = "|cFF20c000"
    set ColorCodes[7] = "|cFFe55bb0"
    set ColorCodes[8] = "|cFF959697"
    set ColorCodes[9] = "|cFF7ebff1"
    set ColorCodes[10] = "|cFF106246"
    set ColorCodes[11] = "|cFF4e2a04"
    // End of Player Colors.
    
    //Start of Integers.
    set ColorCodesRed[0] = 255
    set ColorCodesGreen[0] = 2
    set ColorCodesBlue[0] = 2
    set ColorCodesRed[1] = 0
    set ColorCodesGreen[1] = 65
    set ColorCodesBlue[1] = 255
    set ColorCodesRed[2] = 27
    set ColorCodesGreen[2] = 230
    set ColorCodesBlue[2] = 184
    set ColorCodesRed[3] = 83
    set ColorCodesGreen[3] = 0
    set ColorCodesBlue[3] = 128
    set ColorCodesRed[4] = 255
    set ColorCodesGreen[4] = 252
    set ColorCodesBlue[4] = 0
    set ColorCodesRed[5] = 254
    set ColorCodesGreen[5] = 137
    set ColorCodesBlue[5] =13
    set ColorCodesRed[6] = 31
    set ColorCodesGreen[6] = 191
    set ColorCodesBlue[6] = 0
    set ColorCodesRed[7] = 229
    set ColorCodesGreen[7] = 90
    set ColorCodesBlue[7] = 175
    set ColorCodesRed[8] = 148
    set ColorCodesGreen[8] = 149
    set ColorCodesBlue[8] = 150
    set ColorCodesRed[9] = 125
    set ColorCodesGreen[9] = 190
    set ColorCodesBlue[9] = 241
    set ColorCodesRed[10] = 15
    set ColorCodesGreen[10] = 97
    set ColorCodesBlue[10] = 69
    set ColorCodesRed[11] = 77
    set ColorCodesGreen[11] = 41
    set ColorCodesBlue[11] = 3
    //End of Integers
    
    //Start of 0.0-1.0 real codes.
    loop
        exitwhen i > 11
        set ColorCodesRed1[i] = ColorCodesRed[i] / 255.0
        set ColorCodesGreen1[i] = ColorCodesGreen[i] / 255.0
        set ColorCodesBlue1[i] = ColorCodesBlue[i] / 255.0
        set i = i + 1
    endloop
endfunction

endlibrary
 
Level 9
Joined
Nov 28, 2008
Messages
704
An interesting take EoW, but I have made some maps where I set the player colors all to the same thing (for something like a whos the killer map).

I might use it though. Thanks.

Also, cJass isnt allowed to be submitted. This makes me sadface.
 
Top