[System] Player Color Utils (PCU)

Level 11
Joined
Apr 29, 2007
Messages
826
Save all colors in a parent number, let's say 10. Now, you can order all colorstrings in 10 so you can instantly load the player in one line.

JASS:
    return LoadPlayerHandle(hashtable, 10, colorstring)
Saving would be done like this:
JASS:
    call SavePlayerHandle(hashtable, 10, currentplayercolor, player)
Pretty easy, duh.

edit/ Forgot to mention you have to use StringHash on strings to get an integer out of them.
 
Last edited:
Level 4
Joined
Jan 29, 2007
Messages
98
Is this how you mean ? :S

JASS:
library PlayerColors initializer Init


///////////////////////////////////////////////////////////////////////////////////////////////////////
//***************************************************************************************************//
//@@/////////////////////////////////// *//PlayerColorUtils\\* ////////////////////////////////////@@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 @@//
//@@                 %%                                                         %%                 @@//
//@@                 %%    //\\\\\               /////////  ///          \\\    %%                 @@//
//@@                 %%    //\\   \\\        //////         ///          \\\    %%                 @@//
//@@                 %%    //\\     \\\     /////           ///          \\\    %%                 @@//
//@@                 %%    //\\     ///   ////              ///          \\\    %%                 @@//
//@@                 %%    //\\   ///    ////               ///          \\\    %%                 @@//
//@@                 %%    //\\///      ////                ///          \\\    %%                 @@//
//@@                 %%    //\\         \\\\                ////        \\\\    %%                 @@//
//@@                 %%    //\\          \\\\               ////        \\\\    %%                 @@//
//@@                 %%    //\\           \\\\              ////        \\\\    %%                 @@//
//@@                 %%    //\\             \\\\\            ////      \\\\     %%                 @@//
//@@                 %%    //\\               \\\\\\          ////    \\\\      %%                 @@//
//@@                 %%    //\\                  \\\\\\\\\       ///\\\         %%                 @@//
//@@                 %%                                                         %%                 @@//
//@@                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                   Made by , Komaqtion                                         @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                        Purpose:                                               @@//
//@@                                                                                               @@//
//@@             ¤ This snippet is supposed to help people to, with ease, to use playercolors      @@//
//@@               in all aspects they'd possibly want.                                            @@//
//@@                                                                                               @@//
//@@                                         Usage:                                                @@//
//@@                                                                                               @@//
//@@             ¤ To use this snippet, simply type "call PlayerColoredString(playerid, string)"   @@//
//@@               where "string" is the string you want to colorize, and "playerid"               @@//
//@@               is the player number of the player, whose color you wan to use.                 @@//
//@@               Note: This uses JASS' player number range, meaning that                         @@//
//@@               Player 1(Red)'s number is 0, and Player 2(Blue)'s number is 1,                  @@//
//@@               and so on...                                                                    @@//
//@@               You can also get only the players color-string for own usage...                 @@//
//@@               This is accomplished by using the function "GetPlayerColorString"               @@//
//@@               which takes the player to get the string, or you can also use                   @@//
//@@               the GetPlayerColorStringById function, which takes the player's                 @@//
//@@               Id, or number instead :D                                                        @@//
//@@               You can also change the color of texttags using this snippet...                 @@//
//@@               The function is called "PlayerColoredTextTag" and takes integer alpha           @@//
//@@               which is transparency, player p, the playercolor you which to use, and          @@//
//@@               texttag tag which is the texttag you which to change the color of !             @@//
//@@               You can also use the function "GetPlayerByColor" which takes a string (color)   @@//
//@@               and returns the player which has that specific color. You can even type         @@//
//@@               "ReD" or "REd" or even "..,,  R, e.., d" and it'll return Player(0) or          @@//
//@@               player red in all three cases. And, you can also get the player's color         @@//
//@@               this way.                                                                       @@//
//@@                                                                                               @@//
//@@               WARNING: If you put an invalid player as an argument, in any of the functions,  @@//
//@@               it WILL return Player( 0 ), or Player "Red" !                                   @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                    Requirements:                                              @@//
//@@                                                                                               @@//
//@@             ¤ This snippet's only requirement is vJASS compilement, which is                  @@//
//@@               easiest achieved by downloading JASS Newgen Pack, at                            @@//
//@@               [url]http://www.thehelper.net/forums/showthread.php?t=73936[/url]                          @@//
//@@               You'll also have to update JASS Helper to the latest version...                 @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                        Credits:                                               @@//
//@@                                                                                               @@//
//@@             ¤ Azlier, for helping me out alot with several bugfixes and tweaking !            @@//
//@@               Jesus4Lyf, for also helping me out alot ! :D                                    @@//
//@@               Quraji, for helping me add the "GetPlayerByColor" function ! :D                 @@//
//@@                                                                                               @@//
//@@               And credits, if you use this that is, is not needed to give me                  @@//
//@@               though it's always welcome ;)                                                   @@//
//@@                                                                                               @@//
//@@///////////////////////////////////////////////////////////////////////////////////////////////@@//
//***************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////


    globals
        private integer array Red
        private integer array Green
        private integer array Blue
        private integer array RedString
        private integer array GreenString
        private integer array BlueString
        private string array PlayerColor
        private string array PlayerColorString
        private string array PlayerColorWord
        private string array PlayerColorWordString
        
        private hashtable StoredColors = InitHashtable()
        
        private constant string EndString = "|r"
    endglobals
    
    function PlayerColoredStringById takes integer playerId, string s returns string
        return PlayerColor[playerId] + s + EndString
    endfunction
    
    function PlayerColoredString takes player p, string s returns string
        return PlayerColor[GetPlayerId( p )] + s + EndString
    endfunction
    
    function PlayerColoredTextTag takes texttag tag, player p, integer alpha returns nothing
        local integer id = GetPlayerId( p )
        
        if p != null then
            call SetTextTagColor( tag, Red[id], Green[id], Blue[id], alpha )
        endif

    endfunction
    
    function PlayerColoredTextTagById takes texttag tag, integer playerId, integer alpha returns nothing
        call SetTextTagColor( tag, Red[playerId], Green[playerId], Blue[playerId], alpha )
    endfunction
    
    function GetPlayerColorString takes player p returns string
        return PlayerColor[GetPlayerId( p )]
    endfunction
    
    function GetPlayerColorStringById takes integer playerId returns string
        return PlayerColor[playerId]
    endfunction
    
    /*private function CompressString takes string compstring returns string
        local integer w = StringLength( compstring )
        local integer i = 0
        local string s = ""
        
        loop
        
                if SubString( compstring, i, i + 1 ) != " " or SubString( compstring, i, i + 1 ) != "." or SubString( compstring, i, i + 1 ) != "," then
                    set s = s + SubString( compstring, i, i + 1 )
                endif
                
            set i = i + 1
            
        exitwhen i > w
        endloop
        
        return s
    endfunction*/
    
    function GetPlayerByColor takes string s returns player
        local integer i = 0
        
        set s = StringCase( s, false )
        //set s = CompressString( s )
        
        loop 
        
            if s == PlayerColorWordString[i] then
                return Player( i )
            endif
            
            set i = i + 1
            
        exitwhen ( i >= 13 )
        endloop
        
        if s == PlayerColorWordString[13] then
            return Player( 8 )
        elseif s == PlayerColorWordString[14] or s == PlayerColorWordString[15] then
            return Player( 2 )
        elseif s == PlayerColorWordString[16] or s == PlayerColorWordString[17] then
            return Player(12)
        endif
        
        return null
    endfunction
    
    function GetPlayerColorByColor takes string s returns string
        local integer i = 0
        
        set s = StringCase( s, false )
        //set s = CompressString( s )
        
        loop 
        
            if s == PlayerColorWordString[i] then
                return PlayerColor[i]
            endif
            
            set i = i + 1
            exitwhen ( i >= 13 )
        endloop
        
        if s == PlayerColorWordString[13] then
            return PlayerColor[8]
        elseif s == PlayerColorWordString[14] or s == PlayerColorWordString[15] then
            return PlayerColor[2]
        elseif s == PlayerColorWordString[16] or s == PlayerColorWordString[17] then
            return PlayerColor[12]
        endif
        
        return ""
    endfunction
    
    private function OnColorChange takes player whichPlayer, playercolor color returns nothing
        local integer id = GetPlayerId( whichPlayer )
        local integer pc = GetHandleId( color )

        set PlayerColor[id] = PlayerColorString[pc]
        set Red[id] = RedString[pc]
        set Green[id] = GreenString[pc]
        set Blue[id] = BlueString[pc]
        set PlayerColorWord[id] = PlayerColorWordString[pc]
        
        call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorString[ pc ] ) / 20000000 + 96, whichPlayer )
    endfunction
    
    hook SetPlayerColor OnColorChange
    
    private function Init takes nothing returns nothing
        local integer i = 12
        local integer i2
    
        set PlayerColorString[0] = "|c00ff0202"
        set RedString[0] = 0xff
        set GreenString[0] = 0x02
        set BlueString[0] = 0x02
        set PlayerColorWordString[0] = "red"
        set PlayerColorString[1] = "|c000041ff"
        set RedString[1] = 0x00
        set GreenString[1] = 0x41
        set BlueString[1] = 0xff
        set PlayerColorWordString[1] = "blue"
        set PlayerColorString[2] = "|c001be5b8"
        set RedString[2] = 0x1b
        set GreenString[2] = 0xe5
        set BlueString[2] = 0xb8
        set PlayerColorWordString[2] = "teal"
        set PlayerColorString[3] = "|c00530080"
        set RedString[3] = 0x53
        set GreenString[3] = 0x00
        set BlueString[3] = 0x80
        set PlayerColorWordString[3] = "purple"
        set PlayerColorString[4] = "|c00fffc00"
        set RedString[4] = 0xff
        set GreenString[4] = 0xfc
        set BlueString[4] = 0x00
        set PlayerColorWordString[4] = "yellow"
        set PlayerColorString[5] = "|c00fe890d"
        set RedString[5] = 0xfe
        set GreenString[5] = 0x89
        set BlueString[5] = 0x0d
        set PlayerColorWordString[5] = "orange"
        set PlayerColorString[6] = "|c001fbf00"
        set RedString[6] = 0x1f
        set GreenString[6] = 0xbf
        set BlueString[6] = 0x00
        set PlayerColorWordString[6] = "green"
        set PlayerColorString[7] = "|c00e45aaf"
        set RedString[7] = 0xe4
        set GreenString[7] = 0x5a
        set BlueString[7] = 0xaf
        set PlayerColorWordString[7] = "pink"
        set PlayerColorString[8] = "|c00949596"
        set RedString[8] = 0x94
        set GreenString[8] = 0x95
        set BlueString[8] = 0x96
        set PlayerColorWordString[8] = "grey"
        set PlayerColorString[9] = "|c007dbef1"
        set RedString[9] = 0x7d
        set GreenString[9] = 0xbe
        set BlueString[9] = 0xf1
        set PlayerColorWordString[9] = "lightblue"
        set PlayerColorString[10] = "|c000f6145"
        set RedString[10] = 0x0f
        set GreenString[10] = 0x61
        set BlueString[10] = 0x45
        set PlayerColorWordString[10] = "darkgreen"
        set PlayerColorString[11] = "|c004d2903"
        set RedString[11] = 0x4d
        set GreenString[11] = 0x29
        set BlueString[11] = 0x03
        set PlayerColorWordString[11] = "brown"

        set PlayerColorString[12] = "|c00272727"
        set RedString[12] = 0x27
        set GreenString[12] = 0x27
        set BlueString[12] = 0x27
        set PlayerColorWordString[12] = "darkgrey"
        
        set PlayerColorWordString[13] = "gray"
        set PlayerColorWordString[14] = "aqua"
        set PlayerColorWordString[15] = "cyan"
        set PlayerColorWordString[16] = "darkgray"
        set PlayerColorWordString[17] = "neutral"
    
        loop
            exitwhen i < 0
            
            //call DisplayTimedTextToPlayer( Player( 0 ), 0.0, 0.0, 999999.0, I2S( StringHash( PlayerColorString[ i ] ) / 20000000 + 96 ) )
            call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorString[ GetHandleId( GetPlayerColor( Player( i ) ) ) ] ) / 20000000 + 96, Player( i ) )
            
            set i2 = GetHandleId( GetPlayerColor( Player( i ) ) )
            set PlayerColor[i] = PlayerColorString[i2]
            set Red[i] = RedString[i2]
            set Green[i] = GreenString[i2]
            set Blue[i] = BlueString[i2]
            set PlayerColorWord[i] = PlayerColorWordString[i]
            set i = i - 1
        endloop
        
    endfunction
    
endlibrary
 
Level 4
Joined
Jan 29, 2007
Messages
98
This ? :eek:

JASS:
library PlayerColors initializer Init


///////////////////////////////////////////////////////////////////////////////////////////////////////
//***************************************************************************************************//
//@@/////////////////////////////////// *//PlayerColorUtils\\* ////////////////////////////////////@@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 @@//
//@@                 %%                                                         %%                 @@//
//@@                 %%    //\\\\\               /////////  ///          \\\    %%                 @@//
//@@                 %%    //\\   \\\        //////         ///          \\\    %%                 @@//
//@@                 %%    //\\     \\\     /////           ///          \\\    %%                 @@//
//@@                 %%    //\\     ///   ////              ///          \\\    %%                 @@//
//@@                 %%    //\\   ///    ////               ///          \\\    %%                 @@//
//@@                 %%    //\\///      ////                ///          \\\    %%                 @@//
//@@                 %%    //\\         \\\\                ////        \\\\    %%                 @@//
//@@                 %%    //\\          \\\\               ////        \\\\    %%                 @@//
//@@                 %%    //\\           \\\\              ////        \\\\    %%                 @@//
//@@                 %%    //\\             \\\\\            ////      \\\\     %%                 @@//
//@@                 %%    //\\               \\\\\\          ////    \\\\      %%                 @@//
//@@                 %%    //\\                  \\\\\\\\\       ///\\\         %%                 @@//
//@@                 %%                                                         %%                 @@//
//@@                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                 @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                   Made by , Komaqtion                                         @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                        Purpose:                                               @@//
//@@                                                                                               @@//
//@@             ¤ This snippet is supposed to help people to, with ease, to use playercolors      @@//
//@@               in all aspects they'd possibly want.                                            @@//
//@@                                                                                               @@//
//@@                                         Usage:                                                @@//
//@@                                                                                               @@//
//@@             ¤ To use this snippet, simply type "call PlayerColoredString(playerid, string)"   @@//
//@@               where "string" is the string you want to colorize, and "playerid"               @@//
//@@               is the player number of the player, whose color you wan to use.                 @@//
//@@               Note: This uses JASS' player number range, meaning that                         @@//
//@@               Player 1(Red)'s number is 0, and Player 2(Blue)'s number is 1,                  @@//
//@@               and so on...                                                                    @@//
//@@               You can also get only the players color-string for own usage...                 @@//
//@@               This is accomplished by using the function "GetPlayerColorString"               @@//
//@@               which takes the player to get the string, or you can also use                   @@//
//@@               the GetPlayerColorStringById function, which takes the player's                 @@//
//@@               Id, or number instead :D                                                        @@//
//@@               You can also change the color of texttags using this snippet...                 @@//
//@@               The function is called "PlayerColoredTextTag" and takes integer alpha           @@//
//@@               which is transparency, player p, the playercolor you which to use, and          @@//
//@@               texttag tag which is the texttag you which to change the color of !             @@//
//@@               You can also use the function "GetPlayerByColor" which takes a string (color)   @@//
//@@               and returns the player which has that specific color. You can even type         @@//
//@@               "ReD" or "REd" or even "..,,  R, e.., d" and it'll return Player(0) or          @@//
//@@               player red in all three cases. And, you can also get the player's color         @@//
//@@               this way.                                                                       @@//
//@@                                                                                               @@//
//@@               WARNING: If you put an invalid player as an argument, in any of the functions,  @@//
//@@               it WILL return Player( 0 ), or Player "Red" !                                   @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                    Requirements:                                              @@//
//@@                                                                                               @@//
//@@             ¤ This snippet's only requirement is vJASS compilement, which is                  @@//
//@@               easiest achieved by downloading JASS Newgen Pack, at                            @@//
//@@               [url]http://www.thehelper.net/forums/showthread.php?t=73936[/url]                          @@//
//@@               You'll also have to update JASS Helper to the latest version...                 @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                        Credits:                                               @@//
//@@                                                                                               @@//
//@@             ¤ Azlier, for helping me out alot with several bugfixes and tweaking !            @@//
//@@               Jesus4Lyf, for also helping me out alot ! :D                                    @@//
//@@               Quraji, for helping me add the "GetPlayerByColor" function ! :D                 @@//
//@@                                                                                               @@//
//@@               And credits, if you use this that is, is not needed to give me                  @@//
//@@               though it's always welcome ;)                                                   @@//
//@@                                                                                               @@//
//@@///////////////////////////////////////////////////////////////////////////////////////////////@@//
//***************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////


    globals
        private integer array Red
        private integer array Green
        private integer array Blue
        private integer array RedString
        private integer array GreenString
        private integer array BlueString
        private string array PlayerColor
        private string array PlayerColorString
        private string array PlayerColorWord
        private string array PlayerColorWordString
        
        private hashtable StoredColors = InitHashtable()
        
        private constant string EndString = "|r"
    endglobals
    
    function PlayerColoredStringById takes integer playerId, string s returns string
        return PlayerColor[playerId] + s + EndString
    endfunction
    
    function PlayerColoredString takes player p, string s returns string
        return PlayerColor[GetPlayerId( p )] + s + EndString
    endfunction
    
    function PlayerColoredTextTag takes texttag tag, player p, integer alpha returns nothing
        local integer id = GetPlayerId( p )
        
        if p != null then
            call SetTextTagColor( tag, Red[id], Green[id], Blue[id], alpha )
        endif

    endfunction
    
    function PlayerColoredTextTagById takes texttag tag, integer playerId, integer alpha returns nothing
        call SetTextTagColor( tag, Red[playerId], Green[playerId], Blue[playerId], alpha )
    endfunction
    
    function GetPlayerColorString takes player p returns string
        return PlayerColor[GetPlayerId( p )]
    endfunction
    
    function GetPlayerColorStringById takes integer playerId returns string
        return PlayerColor[playerId]
    endfunction
    
    /*private function CompressString takes string compstring returns string
        local integer w = StringLength( compstring )
        local integer i = 0
        local string s = ""
        
        loop
        
                if SubString( compstring, i, i + 1 ) != " " or SubString( compstring, i, i + 1 ) != "." or SubString( compstring, i, i + 1 ) != "," then
                    set s = s + SubString( compstring, i, i + 1 )
                endif
                
            set i = i + 1
            
        exitwhen i > w
        endloop
        
        return s
    endfunction*/
    
    function GetPlayerByColor takes string s returns player
        return LoadPlayerHandle( StoredColors, 1, StringHash( StringCase( s, false ) ) / 20000000 + 96 )
    endfunction
    
    function GetPlayerColorStringByColor takes string s returns string
        return PlayerColor[ GetPlayerId( LoadPlayerHandle( StoredColors, 1, StringHash( StringCase( s, false ) ) / 20000000 + 96 ) ) ]
    endfunction
    
    private function OnColorChange takes player whichPlayer, playercolor color returns nothing
        local integer id = GetPlayerId( whichPlayer )
        local integer pc = GetHandleId( color )

        set PlayerColor[id] = PlayerColorString[pc]
        set Red[id] = RedString[pc]
        set Green[id] = GreenString[pc]
        set Blue[id] = BlueString[pc]
        set PlayerColorWord[id] = PlayerColorWordString[pc]
        
        call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorString[ pc ] ) / 20000000 + 96, whichPlayer )
    endfunction
    
    hook SetPlayerColor OnColorChange
    
    private function Init takes nothing returns nothing
        local integer i = 12
        local integer i2
    
        set PlayerColorString[0] = "|c00ff0202"
        set RedString[0] = 0xff
        set GreenString[0] = 0x02
        set BlueString[0] = 0x02
        set PlayerColorWordString[0] = "red"
        set PlayerColorString[1] = "|c000041ff"
        set RedString[1] = 0x00
        set GreenString[1] = 0x41
        set BlueString[1] = 0xff
        set PlayerColorWordString[1] = "blue"
        set PlayerColorString[2] = "|c001be5b8"
        set RedString[2] = 0x1b
        set GreenString[2] = 0xe5
        set BlueString[2] = 0xb8
        set PlayerColorWordString[2] = "teal"
        set PlayerColorString[3] = "|c00530080"
        set RedString[3] = 0x53
        set GreenString[3] = 0x00
        set BlueString[3] = 0x80
        set PlayerColorWordString[3] = "purple"
        set PlayerColorString[4] = "|c00fffc00"
        set RedString[4] = 0xff
        set GreenString[4] = 0xfc
        set BlueString[4] = 0x00
        set PlayerColorWordString[4] = "yellow"
        set PlayerColorString[5] = "|c00fe890d"
        set RedString[5] = 0xfe
        set GreenString[5] = 0x89
        set BlueString[5] = 0x0d
        set PlayerColorWordString[5] = "orange"
        set PlayerColorString[6] = "|c001fbf00"
        set RedString[6] = 0x1f
        set GreenString[6] = 0xbf
        set BlueString[6] = 0x00
        set PlayerColorWordString[6] = "green"
        set PlayerColorString[7] = "|c00e45aaf"
        set RedString[7] = 0xe4
        set GreenString[7] = 0x5a
        set BlueString[7] = 0xaf
        set PlayerColorWordString[7] = "pink"
        set PlayerColorString[8] = "|c00949596"
        set RedString[8] = 0x94
        set GreenString[8] = 0x95
        set BlueString[8] = 0x96
        set PlayerColorWordString[8] = "grey"
        set PlayerColorString[9] = "|c007dbef1"
        set RedString[9] = 0x7d
        set GreenString[9] = 0xbe
        set BlueString[9] = 0xf1
        set PlayerColorWordString[9] = "lightblue"
        set PlayerColorString[10] = "|c000f6145"
        set RedString[10] = 0x0f
        set GreenString[10] = 0x61
        set BlueString[10] = 0x45
        set PlayerColorWordString[10] = "darkgreen"
        set PlayerColorString[11] = "|c004d2903"
        set RedString[11] = 0x4d
        set GreenString[11] = 0x29
        set BlueString[11] = 0x03
        set PlayerColorWordString[11] = "brown"

        set PlayerColorString[12] = "|c00272727"
        set RedString[12] = 0x27
        set GreenString[12] = 0x27
        set BlueString[12] = 0x27
        set PlayerColorWordString[12] = "darkgrey"
        
        set PlayerColorWordString[13] = "gray"
        set PlayerColorWordString[14] = "aqua"
        set PlayerColorWordString[15] = "cyan"
        set PlayerColorWordString[16] = "darkgray"
        set PlayerColorWordString[17] = "neutral"
    
        loop
            exitwhen i < 0
            call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorWordString[ i ] ) / 20000000 + 96, Player( i ) )
            
            set i2 = GetHandleId( GetPlayerColor( Player( i ) ) )
            set PlayerColor[i] = PlayerColorString[i2]
            set Red[i] = RedString[i2]
            set Green[i] = GreenString[i2]
            set Blue[i] = BlueString[i2]
            set PlayerColorWord[i] = PlayerColorWordString[i]
            set i = i - 1
        endloop
        
        call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorWordString[ 13 ] ) / 20000000 + 96, Player( 8 ) )
        call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorWordString[ 14 ] ) / 20000000 + 96, Player( 2 ) )
        call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorWordString[ 15 ] ) / 20000000 + 96, Player( 2 ) )
        call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorWordString[ 16 ] ) / 20000000 + 96, Player( 12 ) )
        call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorWordString[ 17 ] ) / 20000000 + 96, Player( 12 ) )
        
    endfunction
    
endlibrary
 
Level 4
Joined
Jan 29, 2007
Messages
98
Hello :D

Sorry for not posting here, but I balieved this had been graveyarded (For unknown reason to me XD) so I've only been updating it on TheHelper.net, but here is a quite major update of it anyways ;)

JASS:
library PlayerColors initializer Init


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*********************************************************************************************************//
//@@/////////////////////////////////// *//PlayerColorUtils\\* //////////////////////////////////////////@@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                      @@//
//@@                  %%                                                         %%                      @@//
//@@                  %%    //\\\\\               /////////  ///          \\\    %%                      @@//
//@@                  %%    //\\   \\\        //////         ///          \\\    %%                      @@//
//@@                  %%    //\\     \\\     /////           ///          \\\    %%                      @@//
//@@                  %%    //\\     ///   ////              ///          \\\    %%                      @@//
//@@                  %%    //\\   ///    ////               ///          \\\    %%                      @@//
//@@                  %%    //\\///      ////                ///          \\\    %%                      @@//
//@@                  %%    //\\         \\\\                ////        \\\\    %%                      @@//
//@@                  %%    //\\          \\\\               ////        \\\\    %%                      @@//
//@@                  %%    //\\           \\\\              ////        \\\\    %%                      @@//
//@@                  %%    //\\             \\\\\            ////      \\\\     %%                      @@//
//@@                  %%    //\\               \\\\\\          ////    \\\\      %%                      @@//
//@@                  %%    //\\                  \\\\\\\\\       ///\\\         %%                      @@//
//@@                  %%                                                         %%                      @@//
//@@                  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                      @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                     Made by , Komaqtion                                             @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                         Purpose:                                                    @@//
//@@                                                                                                     @@//
//@@         # This snippet is supposed to help people to, with ease, to use playercolors                @@//
//@@           in all aspects they'd possibly want.                                                      @@//
//@@                                                                                                     @@//
//@@                                         Usage:                                                      @@//
//@@                                                                                                     @@//
//@@         # The function provided by this small system is:                                            @@//
//@@           *NOTE* If you input an invalid player in any of the functions, it'll                      @@//
//@@           automatically work as if you inputted Player( 0 ), or Player (Red)...                     @@//
//@@                                                                                                     @@//
//@@      function PlayerColoredString takes player p, string s returns string                           @@//
//@@                                                                                                     @@//
//@@               - "player p" -> The player of which you want to use the color for the                 @@//
//@@               inputted string.                                                                      @@//
//@@               - "string coloredString" -> The string which is to be returned                        @@//
//@@               in the wanted playercolor.                                                            @@//
//@@               - "returns string" -> This function will return the inputted string,                  @@//
//@@               but in the playercolor of the player with the inputted playerid.                      @@//
//@@                                                                                                     @@//
//@@      function PlayerColoredStringById takes integer playerId, string s returns string               @@//
//@@                                                                                                     @@//
//@@               - "integer playerId" -> The player-number of the player's color                       @@//
//@@               you wish to use.                                                                      @@//
//@@               - "string coloredString" -> The string which is to be returned                        @@//
//@@               in the wanted playercolor.                                                            @@//
//@@               - "returns string" -> This function will return the inputted string,                  @@//
//@@               but in the playercolor of the player with the inputted playerid.                      @@//
//@@                                                                                                     @@//
//@@      function GetPlayerNameColored takes player p returns string                                    @@//
//@@                                                                                                     @@//
//@@               - "player p" -> The player of which you want to use the color for the                 @@//
//@@               inputted string. (And also the name ;))                                               @@//
//@@               - "returns string" -> This function will return the player's name you                 @@//
//@@               inputted, but in the playercolor of that player.                                      @@//
//@@                                                                                                     @@//
//@@      function PlayerColoredTextTag takes texttag coloredTag,                                        @@//
//@@               player p, integer alpha returns nothing                                               @@//
//@@                                                                                                     @@//
//@@               - "texttag coloredTag" -> The texttag of which the color is to be changed.            @@//
//@@               - "player p" -> The player of which color the texttag is to be changed to.            @@//
//@@               - "integer alpha" -> The amount of transparency the text (texttag) should have.       @@//
//@@               /\ THIS RANGES FROM 0 TO 255, WITH 255 BEING 100% SEETHROUGH ! /\                     @@//
//@@               - "returns nothing" -> This function will not return anything, as it just             @@//
//@@               modifies the existing texttag, and can't be used in any variable or so.               @@//
//@@                                                                                                     @@//
//@@      function PlayerColoredTextTagById takes texttag coloredTag,                                    @@//
//@@               integer playerId, integer alpha returns nothing                                       @@//
//@@                                                                                                     @@//
//@@               - "texttag coloredTag" -> The texttag of which the color is to be changed.            @@//
//@@               - "integer playerId" -> The playerid of the player of which color the texttag         @@//
//@@               is to be changed to.                                                                  @@//
//@@               - "integer alpha" -> The amount of transparency the text (texttag) should have.       @@//
//@@               /\ THIS RANGES FROM 0 TO 255, WITH 255 BEING 100% SEETHROUGH ! /\                     @@//
//@@               - "returns nothing" -> This function will not return anything, as it just             @@//
//@@               modifies the existing texttag, and can't be used in any variable or so.               @@//
//@@                                                                                                     @@//
//@@      function GetPlayerColorString takes player p returns string                                    @@//
//@@                                                                                                     @@//
//@@               - "player p" -> The player we will be getting the "color-code" of.                    @@//
//@@               - "returns string" -> This function will return the actual ARGB code                  @@//
//@@               (Not the system, but the hex-code).                                                   @@//
//@@                                                                                                     @@//
//@@      function GetPlayerColorStringById takes integer playerId returns string                        @@//
//@@                                                                                                     @@//
//@@               - "integer playerId" -> The id of the player we will be getting                       @@//
//@@               the "color-code" of.                                                                  @@//
//@@               - "returns string" -> This function will return the actual ARGB code                  @@//
//@@               (Not the system, but the hex-code).                                                   @@//
//@@                                                                                                     @@//
//@@      function GetPlayerByColor takes string color returns player                                    @@//
//@@                                                                                                     @@//
//@@               - "string color" -> This is where you put the color of the player                     @@//
//@@                you want to get (E.g "blue")                                                         @@//
//@@               - "returns player" -> As said, this is the player who has                             @@//
//@@               the color you inputted.                                                               @@//
//@@                                                                                                     @@//
//@@      function GetPlayerColorStringByColor takes string color returns string                         @@//
//@@                                                                                                     @@//
//@@               - "string color" -> This is the player's color of which you                           @@//
//@@               want to get it's "color-code" (Or hex-code)                                           @@//
//@@               - "returns string" -> This is the hex-code of the color the                           @@//
//@@               player uses (E.g "|c00ff0202")                                                        @@//
//@@                                                                                                     @@//
//@@               - That is it ! :D Hope you've understood all the functions clearly now !              @@//
//@@               If not, then just post in the thread and I'll update this documentation ;)            @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                    Requirements:                                                    @@//
//@@                                                                                                     @@//
//@@             # This snippet's only requirement is vJASS compilement, which is                        @@//
//@@               easiest achieved by downloading JASS Newgen Pack, at                                  @@//
//@@               [url]http://www.wc3c.net/showthread.php?t=90999[/url]                                            @@//
//@@               You'll also have to update JASS Helper to the latest version...                       @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                        Credits:                                                     @@//
//@@                                                                                                     @@//
//@@                                   TheHelper.net guys:                                               @@//
//@@             # - Azlier, for helping me out alot with several bugfixes and tweaking !                @@//
//@@               - Jesus4Lyf, for also helping me out alot ! :D                                        @@//
//@@               - Quraji, for helping me add the "GetPlayerByColor" function ! :D                     @@//
//@@               - Darthfett, for giving me some pointers on this documentation :D                     @@//
//@@                                                                                                     @@//
//@@                                   HiveWorkshop guys:                                                @@//
//@@               - YourNameHere, for a lot of help, critique and tweaks :D                             @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@             # And credits, if you use this that is, is not needed to give me                        @@//
//@@               though it's always welcome ;)                                                         @@//
//@@                                                                                                     @@//
//@@/////////////////////////////////////////////////////////////////////////////////////////////////////@@//
//*********************************************************************************************************//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////


// Configuration, though it isn't much :P

    globals
        private constant string EndString = "|r"     // This actually shouldn't be changeable XD
                                                     // But I made it so anyways :P
    endglobals

// End of Configuration !!!! DON'T TOUCH BELOW THIS !!!!!
// End of Configuration !!!! DON'T TOUCH BELOW THIS !!!!!
// End of Configuration !!!! DON'T TOUCH BELOW THIS !!!!!
// End of Configuration !!!! DON'T TOUCH BELOW THIS !!!!!

    globals
        private integer array Red                      // This is used to keep track of the "redness" in each player's the hex-codes
        private integer array Green                    // This is used to keep track of the "greenness" in each player's the hex-codes
        private integer array Blue                     // This is used to keep track of the "blueness" in each player's the hex-codes
        private integer array RedString                // And this is the the "redness" in all hex-codes :D
        private integer array GreenString              // And this is the the "greenness" in all hex-codes :D
        private integer array BlueString               // And this is the the "blueness" in all hex-codes :D
        
        private string array PlayerColor               // This is used to keep track of which player-color is used by which player :D
        private string array PlayerColorString         // And this is the same thing, but not bound to a player ;)
        private string array PlayerColorWord           // This is used to keep track of which player-color-string (Like "red", or "teal") is used by which player :D
        private string array PlayerColorWordString     // And, yet again, this is the same thing, but not bound to a player ;)
        
        private player array StoredPlayers
    endglobals
    
    function PlayerColoredStringById takes integer playerId, string coloredString returns string
        return PlayerColor[playerId] + coloredString + EndString
    endfunction
    
    function PlayerColoredString takes player p, string coloredString returns string
        return PlayerColor[GetPlayerId( p )] + coloredString + EndString
    endfunction
    
    function GetPlayerNameColored takes player p returns string
        return PlayerColor[GetPlayerId( p )] + GetPlayerName( p ) + EndString
    endfunction
    
    function PlayerColoredTextTag takes texttag coloredTag, player p, integer alpha returns nothing
        local integer id
        
        if p != null then // We don't want to use a 'null' player, do we ? :o
            set id = GetPlayerId( p ) // Gets the id of the inputted player
            call SetTextTagColor( coloredTag, Red[id], Green[id], Blue[id], alpha ) // Setting the color of the used texttag to the specified player's color
        endif

    endfunction
    
    function PlayerColoredTextTagById takes texttag coloredTag, integer playerId, integer alpha returns nothing
        call SetTextTagColor( coloredTag, Red[playerId], Green[playerId], Blue[playerId], alpha ) // Simply sets the color of the texttag to the wanted player's one ;)
    endfunction
    
    function GetPlayerColorString takes player p returns string
        return PlayerColor[GetPlayerId( p )]
    endfunction
    
    function GetPlayerColorStringById takes integer playerId returns string
        return PlayerColor[playerId]
    endfunction
    
    function GetPlayerByColor takes string color returns player
        return StoredPlayers[ StringHash( color ) / 20000000 + 96 ]
    endfunction
    
    function GetPlayerColorStringByColor takes string color returns string
        return PlayerColor[ GetPlayerId( StoredPlayers[ StringHash( color ) / 20000000 + 96 ] ) ]
    endfunction
    
    private function OnColorChange takes player whichPlayer, playercolor color returns nothing
        local integer id = GetPlayerId( whichPlayer )
        local integer pc = GetHandleId( color )

        set PlayerColor[id] = PlayerColorString[pc]
        set Red[id] = RedString[pc]
        set Green[id] = GreenString[pc]
        set Blue[id] = BlueString[pc]
        set PlayerColorWord[id] = PlayerColorWordString[pc]
        set StoredPlayers[ StringHash( PlayerColorWordString[ pc ] ) / 20000000 + 96 ] = whichPlayer
    endfunction
    
    hook SetPlayerColor OnColorChange
    
    private function Init takes nothing returns nothing
        local integer i = 12
        local integer i2
    
        set PlayerColorString[0] = "|c00ff0202"
        set RedString[0] = 0xff
        set GreenString[0] = 0x02
        set BlueString[0] = 0x02
        set PlayerColorWordString[0] = "red"
        
        set PlayerColorString[1] = "|c000041ff"
        set RedString[1] = 0x00
        set GreenString[1] = 0x41
        set BlueString[1] = 0xff
        set PlayerColorWordString[1] = "blue"
        
        set PlayerColorString[2] = "|c001be5b8"
        set RedString[2] = 0x1b
        set GreenString[2] = 0xe5
        set BlueString[2] = 0xb8
        set PlayerColorWordString[2] = "teal"
        
        set PlayerColorString[3] = "|c00530080"
        set RedString[3] = 0x53
        set GreenString[3] = 0x00
        set BlueString[3] = 0x80
        set PlayerColorWordString[3] = "purple"
        
        set PlayerColorString[4] = "|c00fffc00"
        set RedString[4] = 0xff
        set GreenString[4] = 0xfc
        set BlueString[4] = 0x00
        set PlayerColorWordString[4] = "yellow"
        
        set PlayerColorString[5] = "|c00fe890d"
        set RedString[5] = 0xfe
        set GreenString[5] = 0x89
        set BlueString[5] = 0x0d
        set PlayerColorWordString[5] = "orange"
        
        set PlayerColorString[6] = "|c001fbf00"
        set RedString[6] = 0x1f
        set GreenString[6] = 0xbf
        set BlueString[6] = 0x00
        set PlayerColorWordString[6] = "green"
        
        set PlayerColorString[7] = "|c00e45aaf"
        set RedString[7] = 0xe4
        set GreenString[7] = 0x5a
        set BlueString[7] = 0xaf
        set PlayerColorWordString[7] = "pink"
        
        set PlayerColorString[8] = "|c00949596"
        set RedString[8] = 0x94
        set GreenString[8] = 0x95
        set BlueString[8] = 0x96
        set PlayerColorWordString[8] = "grey"
        
        set PlayerColorString[9] = "|c007dbef1"
        set RedString[9] = 0x7d
        set GreenString[9] = 0xbe
        set BlueString[9] = 0xf1
        set PlayerColorWordString[9] = "lightblue"
        
        set PlayerColorString[10] = "|c000f6145"
        set RedString[10] = 0x0f
        set GreenString[10] = 0x61
        set BlueString[10] = 0x45
        set PlayerColorWordString[10] = "darkgreen"
        
        set PlayerColorString[11] = "|c004d2903"
        set RedString[11] = 0x4d
        set GreenString[11] = 0x29
        set BlueString[11] = 0x03
        set PlayerColorWordString[11] = "brown"

        set PlayerColorString[12] = "|c00272727"
        set RedString[12] = 0x27
        set GreenString[12] = 0x27
        set BlueString[12] = 0x27
        set PlayerColorWordString[12] = "darkgrey"
        
        set PlayerColorWordString[13] = "gray"
        set PlayerColorWordString[14] = "aqua"
        set PlayerColorWordString[15] = "cyan"
        set PlayerColorWordString[16] = "darkgray"
        set PlayerColorWordString[17] = "neutral"
    
        loop
            exitwhen i < 0   
            
            set StoredPlayers[ StringHash( PlayerColorWordString[ i ] ) / 20000000 + 96 ] = Player( i )
            set i2 = GetHandleId( GetPlayerColor( Player( i ) ) )
            set PlayerColor[i] = PlayerColorString[ i2 ]
            set Red[ i ] = RedString[ i2 ]
            set Green[ i ] = GreenString[ i2 ]
            set Blue[ i ] = BlueString[ i2 ]
            set PlayerColorWord[ i ] = PlayerColorWordString[ i ]
            
            set i = i - 1
        endloop
        
        set StoredPlayers[ StringHash( PlayerColorWordString[ 13 ] ) / 20000000 + 96 ] = Player( 8 )
        set StoredPlayers[ StringHash( PlayerColorWordString[ 14 ] ) / 20000000 + 96 ] = Player( 2 )
        set StoredPlayers[ StringHash( PlayerColorWordString[ 15 ] ) / 20000000 + 96 ] = Player( 2 )
        set StoredPlayers[ StringHash( PlayerColorWordString[ 16 ] ) / 20000000 + 96 ] = Player( 12 )
        set StoredPlayers[ StringHash( PlayerColorWordString[ 17 ] ) / 20000000 + 96 ] = Player( 12 )
    endfunction
    
endlibrary

Now, I would simply like this to either get graveyarded or approved... Sorry for being so straight forward, but I've had the longest thread about this on TheHelper, and they won't say if it'll get approved or not, so I would simply like to get a straightforward answer here, if that's possible :S

Anyways, thanks for all of your suggestions here, really appreciate it ! :D
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
Now, I would simply like this to either get graveyarded or approved... Sorry for being so straight forward, but I've had the longest thread about this on TheHelper, and they won't say if it'll get approved or not, so I would simply like to get a straightforward answer here, if that's possible :S
It was already approved by TriggerHappy; that's why your thread is in the Jass section. =P
 
Top