HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GetPlayerColored

07-27-2008, 10:13 AM#1
Ammorth
Collapse JASS:
library GetPlayerColored initializer init
    // GetPlayerColored by Ammorth
    // v1.2
    // functions should be self-explanatory
    // Credits to DioD for multiple fixes

    globals
        private string array PlayerColor
        private integer array redhex
        private integer array greenhex
        private integer array bluehex
    endglobals

    function GetPlayerNameColored takes player p returns string // colored player name
        return PlayerColor[GetHandleId(GetPlayerColor(p))]+GetPlayerName(p)+"|r"
    endfunction

    function GetPlayerTextColor takes player p returns string // only textcode
        return PlayerColor[GetHandleId(GetPlayerColor(p))]
    endfunction

    function GetPlayerRedHex takes player p returns integer // integer value for red
        return redhex[GetHandleId(GetPlayerColor(p))]
    endfunction

    function GetPlayerGreenHex takes player p returns integer // integer value for green
        return greenhex[GetHandleId(GetPlayerColor(p))]
    endfunction

    function GetPlayerBlueHex takes player p returns integer // integer value for blue
        return bluehex[GetHandleId(GetPlayerColor(p))]
    endfunction

    private function init takes nothing returns nothing
        set PlayerColor[0] = "|CFFFF0303" // red
        set PlayerColor[1] = "|CFF0042FF" // blue
        set PlayerColor[2] = "|CFF1CE6B9" // teal
        set PlayerColor[3] = "|CFF540081" // purple
        set PlayerColor[4] = "|CFFFFFF01" // yellow
        set PlayerColor[5] = "|CFFFE8A0E" // orange
        set PlayerColor[6] = "|CFF20C000" // green
        set PlayerColor[7] = "|CFFE55BB0" // pink
        set PlayerColor[8] = "|CFF959697" // grey
        set PlayerColor[9] = "|CFF7EBFF1" // light blue
        set PlayerColor[10] = "|CFF106246" // dark green
        set PlayerColor[11] = "|CFF4E2A04" // brown
        set redhex[0] = 255
        set redhex[1] = 0
        set redhex[2] = 28
        set redhex[3] = 84
        set redhex[4] = 255
        set redhex[5] = 254
        set redhex[6] = 32
        set redhex[7] = 229
        set redhex[8] = 149
        set redhex[9] = 126
        set redhex[10] = 16
        set redhex[11] = 78
        set greenhex[0] = 3
        set greenhex[1] = 66
        set greenhex[2] = 230
        set greenhex[3] = 0
        set greenhex[4] = 255
        set greenhex[5] = 138
        set greenhex[6] = 192
        set greenhex[7] = 91
        set greenhex[8] = 150
        set greenhex[9] = 191
        set greenhex[10] = 98
        set greenhex[11] = 42
        set bluehex[0] = 3
        set bluehex[1] = 255
        set bluehex[2] = 185
        set bluehex[3] = 129
        set bluehex[4] = 1
        set bluehex[5] = 14
        set bluehex[6] = 0
        set bluehex[7] = 176
        set bluehex[8] = 151
        set bluehex[9] = 241
        set bluehex[10] = 70
        set bluehex[11] = 4
    endfunction

endlibrary

Quick and easy script for coloured names. Has functions to get colors for multiboards (hex values). Will display correct colors even after player color changes (thanks DioD).

Fixed for 1.24 (thanks again DioD)

Release Notes

v1.0
- First Public Release

v1.1
- Added proper color ID check
- Fix a couple color codes and hex values

v1.2
- Updated for 1.24
- In-lined the functions as 1.24 removed need for the return bug

07-27-2008, 12:51 PM#2
DioD
There is RB function for color detection missing
Code:
function GetPlayerColorId takes player Who returns integer
    return GetPlayerColor(Who)
    return 0
endfunction

GetPlayerId >> GetPlayerColorId
07-28-2008, 05:05 AM#3
Ammorth
Thanks for the info! Never knew you could do that. I was going to add some comparison to check for player colors, but the return bug is really nifty.
07-28-2008, 06:53 AM#4
Jazradel
Collapse JASS:
function GetPlayerColorId takes player Who returns integer
    return GetPlayerColor(Who)
    return 0
endfunction
What does that do? Takes a player and returns an integer, but what for? Is it the code for the the color of that player?
07-28-2008, 07:22 AM#5
Ammorth
It returns an integer which ranges from 0 to 11 based on the current color of the player.
07-28-2008, 08:03 AM#6
Captain Griffen
Collapse JASS:
function GetPlayerColorId takes player Who returns integer
    return GetPlayerId(GetPlayerColor(Who))
endfunction

Clearer and probably faster, since the return bug is quite slow.
07-28-2008, 09:53 AM#7
Ammorth
That won't compile as GetPlayerColor returns a playercolor and not a player.

The return bug has only 1 function call within it, so it shouldn't be too slow. In fact, all the function (minus the player name) take 3 functions and 1 array read.
07-28-2008, 10:06 AM#8
Captain Griffen
Quote:
Originally Posted by Ammorth
That won't compile as GetPlayerColor returns a playercolor and not a player.

The return bug has only 1 function call within it, so it shouldn't be too slow. In fact, all the function (minus the player name) take 3 functions and 1 array read.

Hmm...good point. I thought players were 0-11 on the handle indexes, but no, it's playercolor. Ignore me.
07-28-2008, 12:12 PM#9
moyack
Approvedzord'd
06-10-2009, 07:13 PM#10
Here-b-Trollz
Collapse This must be updated for v1.23b:
function GetPlayerColorID takes player p returns integer
    local integer i=0
    local playercolor get=GetPlayerColor(p)
    loop
        exitwhen i==bj_MAX_PLAYERS
        if(ConvertPlayerColor(i)==get)then
            return i
        endif
        set i=i+1
    endloop
    return -1
endfunction
06-13-2009, 11:12 AM#11
Themerion
Collapse JASS:
function GetPlayerRedHex takes player p returns integer // integer value for red
    return redhex[GetPlayerColorID(p)]
endfunction

function GetPlayerGreenHex takes player p returns integer // integer value for green
    return greenhex[GetPlayerColorID(p)]
endfunction

function GetPlayerBlueHex takes player p returns integer // integer value for blue
    return bluehex[GetPlayerColorID(p)]
endfunction

Um... Hex?

To mee it seems these functions return 256-RGB, not hex.
06-13-2009, 12:28 PM#12
Mr.Malte
These ColorCodes are simply wrong!
06-25-2009, 06:32 AM#13
Blubb-Tec
this would need a fix for 1.23b/1.24+, but I think Vexorian's ARGB already includes all of this, plus some more, and should be made standard.
Since I still see people using this in actual maps, I vote for this to be GYed, because its more harmful than helpful for users.
06-25-2009, 06:36 AM#14
Tyrande_ma3x
Why should this be graveyarded? A fix for this was already suggested, OP just needs to add it and it's going to work for 1.23b. I find this really useful and simple, easier to use than ARGB...
06-25-2009, 07:20 AM#15
Bobo_The_Kodo
Syntax is more cool imo

anyway, it can just be changed to GetHandleId(GetPlayerColor(i))

it works same for pseudohandles you know ..