• 🏆 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!

[JASS] Convert Player Color to String

Status
Not open for further replies.
Level 27
Joined
May 30, 2007
Messages
2,872
Is it possible to convert a variable of type 'Player Color' to a 'String'?
Is it possible to get the red, green, and blue values (Integer or Real) of a 'Player Color' variable?
And don't tell me to write a function with those values written in it. I can do that.
 
Level 15
Joined
Feb 15, 2006
Messages
851
In order to solve this situation, I did a function which compares the actual team color with the ones assigned by common.j.

Something like that:

JASS:
function GetPlayerColorString takes player p returns string
    local playercolor c = GetPlayerColor(p)
    if c == PLAYER_COLOR_RED then
        return "<Red color code>"
    elseif c == PLAYER_COLOR_BLUE then
        return "<Blue color code>"
    // and so on....
    else
        return "<White color code>"
    endif
endfunction

The advantage of this function is that it takes in account the color even if the player would have changed it before starting the game.
 
In order to solve this situation, I did a function which compares the actual team color with the ones assigned by common.j.

Something like that:

JASS:
function GetPlayerColorString takes player p returns string
    local playercolor c = GetPlayerColor(p)
    if c == PLAYER_COLOR_RED then
        return "<Red color code>"
    elseif c == PLAYER_COLOR_BLUE then
        return "<Blue color code>"
    // and so on....
    else
        return "<White color code>"
    endif
endfunction

The advantage of this function is that it takes in account the color even if the player would have changed it before starting the game.

Adding on to his post, I think this would work:
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

Then you can use it as a local string such as:
JASS:
function example takes nothing returns nothing
    local string p1 = GetPlayerColorString(Player(0))
    local string p2 = GetPlayerColorString(Player(1))
    local string p3 = GetPlayerColorString(Player(2))
    local string p4 = GetPlayerColorString(Player(3))
    local string p5 = GetPlayerColorString(Player(4))
    local string p6 = GetPlayerColorString(Player(5))
    local string p7 = GetPlayerColorString(Player(6))
    local string p8 = GetPlayerColorString(Player(7))
    local string p9 = GetPlayerColorString(Player(8))
    local string p10 = GetPlayerColorString(Player(9))
    local string p11 = GetPlayerColorString(Player(10))
    local string p12 = GetPlayerColorString(Player(11))
endfunction

I hope this helps! [Don't forget if you are using this in text; you should add an "|r" after the string variable or function that you concatenate with the text!]
 
Level 15
Joined
Feb 15, 2006
Messages
851
Let's make it better
JASS:
function GetPlayerColorString takes player p, string text returns string
//Credits to Andrewgosu from TH for the color codes//
    local playercolor c = GetPlayerColor(p)
    if c == PLAYER_COLOR_RED then
        return "|cffFF0202" + text + "|r"
    elseif c == PLAYER_COLOR_BLUE then
        return "|cff0041FF" + text + "|r"
    elseif c == PLAYER_COLOR_CYAN then
        return "|cff1BE5B8" + text + "|r"
    elseif c == PLAYER_COLOR_PURPLE then
        return "|cff530080" + text + "|r"
    elseif c == PLAYER_COLOR_YELLOW then
        return "|cffFFFC00" + text + "|r"
    elseif c == PLAYER_COLOR_ORANGE then
        return "|cffFE890D" + text + "|r"
    elseif c == PLAYER_COLOR_GREEN then
        return "|cff1FBF00" + text + "|r"
    elseif c == PLAYER_COLOR_PINK then
        return "|cffE45AAF" + text + "|r"
    elseif c == PLAYER_COLOR_LIGHT_GRAY then
        return "|cff949596" + text + "|r"
    elseif c == PLAYER_COLOR_LIGHT_BLUE then
        return "|cff7DBEF1" + text + "|r"
    elseif c == PLAYER_COLOR_AQUA then
        return "|cff0F6145" + text + "|r"
    elseif c == PLAYER_COLOR_BROWN then
        return "|cff4D2903" + text + "|r" 
    else
        return "|cffFFFFFF" + text + "|r"
    endif
endfunction
 
Image:
JASS:
native MultiboardSetItemIcon            takes multiboarditem mbi, string iconFileName returns nothing

[Note: To get the multiboard item, use:
JASS:
native MultiboardGetItem                takes multiboard lb, integer row, integer column returns multiboarditem
]

Text:
JASS:
native MultiboardSetItemValue           takes multiboarditem mbi, string val returns nothing

Example:
JASS:
//Put this in your map's header//
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

//====================================

//Add this to your trigger:

function test takes nothing returns nothing
    local string array p
    local integer i = 0

    loop
        exitwhen i == 12
        set p[i] = GetPlayerColorString(Player(i)) 
        set i = i + 1
    endloop
endfunction

Use that for the locals, Get each multiboard item, then just add them to your multiboard using the SetItemValue and just do something like [I2S(p[<Player #>]) + "Text" + "|r"]

I hope this helps!
 
Status
Not open for further replies.
Top