[System] Player Color Utils (PCU)

Level 4
Joined
Jan 29, 2007
Messages
98
Hi!

I though I'd submit this snippet, which (By many different ways) will use players current colors to, for example, convert a string to use that color...

Requires: vJASS compiler, which supports "hook" (Latest version of JassHelper)

Da Code! :

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

Please, come with ideas of more features for this, and I'll consider adding them ;)
(If they're worth it, that is :p)
 
Last edited:
Level 11
Joined
Nov 4, 2007
Messages
337
You know what? I made a script with exactly the same purpouse yesterday.
And do you know why I didn't submit it?
A) we already have this twice
B) the script is too easy.
If we already have this twice, why didn't I use other systems?
I tried ARGB but when I saw how inaccurate the colorcodes are ingame, I used my own ones. I didn't use GetPlayerColored because it's a too small and easy script. You don't have to put effort in something like that and I don't want to credit anybody for sth. like that.

Also the implementation totally sucks. Less would have been more
 
Level 4
Joined
Jan 29, 2007
Messages
98
You know what? I made a script with exactly the same purpouse yesterday.
And do you know why I didn't submit it?
A) we already have this twice
B) the script is too easy.
If we already have this twice, why didn't I use other systems?
I tried ARGB but when I saw how inaccurate the colorcodes are ingame, I used my own ones. I didn't use GetPlayerColored because it's a too small and easy script. You don't have to put effort in something like that and I don't want to credit anybody for sth. like that.

Also the implementation totally sucks. Less would have been more

Are you stalking me, or what ?!
 
Level 11
Joined
Nov 4, 2007
Messages
337
Err, why should I write different posts for the same submissions?
Why do you think I'm stalking you?
This:

JASS:
       private string array ColorString

        set ColorString[0] = "|cffff0000"    //red
        set ColorString[1] = "|cff0000ff"    //blue
        set ColorString[2] = "|cff00f5ff"    //Teal
        set ColorString[3] = "|cff551A8B"    //Purple
        set ColorString[4] = "|cffffff00"    //Yellow
        set ColorString[5] = "|cffEE9A00"    //Orange
        set ColorString[6] = "|cff00CD00"    //Green
        set ColorString[7] = "|cffFF69B4"    //Pink
        set ColorString[8] = "|cffC0C0C0"    //Gray
        set ColorString[9] = "|cffB0E2FF"    //Light Blue
        set ColorString[10] = "|cff006400"    //Dark Green
        set ColorString[11] = "|cff8B4513"    //Brown

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

is from my thing and this:

JASS:
        if label == "red" then
            return Player(0)
        elseif label == "blue" then
            return Player(1)
        elseif label == "teal" then
            return Player(2)
        elseif label == "purple" then
            return Player(3)
        elseif label == "yellow" then
            return Player(4)
        elseif label == "orange" then
            return Player(5)
        elseif label == "green" then
            return Player(6)
        elseif label == "pink" then
            return Player(7)
        elseif label == "grey" then
            return Player(8)
        elseif label == "gray" then
            return Player(8)
        elseif label == "lightblue" then
            return Player(9)
        elseif label == "light blue" then
            return Player(9)
        elseif label == "light-blue" then
            return Player(9)
        elseif label == "darkgreen" then
            return Player(10)
        elseif label == "dark green" then
            return Player(10)
        elseif label == "dark-green" then
            return Player(10)
        elseif label == "brown" then
            return Player(11)
        endif

and it would've been the better implementation.
And this is too simple to become approved. I wrote that in 3 minutes.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Are you stalking me, or what ?!

MapperMalte is a guy that always tries to take down your system by promoting his own, and tries to make you feel like it is unapprovable for some reasons he mostly makes up.

Meh he is just competetive, a little Too competetive in my opinion some times but that is just him.

Now, about the system

in GetPlayerByColor, you check wether it is PlayerColorWordString[13], [14] or [15] in every loop, you should get that last part of the if out the loop, like you did in GetPlayerColorByColor.
Rest seems fine to me, but i just took a quick look.
 
Last edited:
Level 4
Joined
Jan 29, 2007
Messages
98
MapperMalte is a guy that always tries to take down your system by promoting his own, and tries to make you feel like it is unapprovable for some reasons he mostly makes up.

Meh he is just competetive, a little Too competetive in my opinion some times but that is just him.

Hehe XD Ok...
(About the stalking part, he said the exact same thing on wc3c.net where I also submitted this XD)

Have updated it now ;)
 
Level 11
Joined
Nov 4, 2007
Messages
337
MapperMalte is a guy that always tries to take down your system by promoting his own

Too bad I didn't upload my own system, because I think something like this is too simple to be approved.

Dude, your system has too many useless 'uber'features.
Cut this out:

JASS:
    function PlayerColoredString takes integer playerId, string s returns string
        return PlayerColor[playerId] + s + EndString
endfunction
    function PlayerColoredTextTag takes integer alpha, player p, texttag tag returns nothing

if p == null then
            debug call BJDebugMsg( "An invalid player was used!" )
            return
        endif

        call SetTextTagColor( tag, Red[GetPlayerId( p )], Green[GetPlayerId( p )], Blue[GetPlayerId( p )], alpha )
    endfunction

function PlayerColoredTextTagById takes integer alpha, integer playerId, texttag tag 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

    function CompressString takes string compstring returns string
        local integer w = StringLength( compstring )
        local integer i = 0
        local string s = ""

        loop

if not( 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

and make this func:

JASS:
GetPlayerNameColored takes player p returns string

or this:

JASS:
ColorPlayer takes player p returns string
 
I know there are a lot of "String-Manipulating-Systems" out there, which are a lot more complicated and have more features than this one, though maybe someone only needs this simple conversion.

That's your mission statement. Your utility doesn't exactly do that does it? ^_-

Simplicity is man's best friend. While your other features are nice, it'd be better if it were more modularized ^_^. Let people use exactly what they need.


Furthermore, you have some extra useless code in there leading to your system not really being all that efficient.

JASS:
        if p == null then
            debug call BJDebugMsg( "An invalid player was used!" )
            return
        endif

that's one small example, but you have a not in there when you should just be using !=, etc ^_-.
 
JASS:
    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]
    endfunction

    hook SetPlayerColor OnColorChange

I see no point to that > <. It slows down the actual native by turning it into an evaluation ><. SetPlayerColor can only be done in the programming end.... so people know exactly when it's happening....

I suggest you take that out ; ).
 
Level 11
Joined
Apr 29, 2007
Messages
826
You mean like at "Map Initialization" ? :S

I don't really understand you there...
I mean I hook it because it can be used after this library is declared, so it'll change the values accordingly...

No, I mean that if you hook any function, your hooked one will be executed before the native. (Means the trigger has to execute your stuff first)

In this case it really doesn't matter, so whatever.
 
I'm talking about there's absolutely no need for an event on a native that's only ever done from the JASS.... there are natives for in-game events, but there aren't any for native uses -.-. Why? Because there's absolutely no need for them ><.


If you use a native, you already know you're using it so why would you need an event ><. Just call the functions whenever you use it ><.
 
Yeah, that's what I thought too...
Thanks :D

It's actually not fine. When I set a player color, I know when I'm setting it, so having an event fire off whenever I set it seems pointless to me because I know when it's firing.

If it's an in-game event, that is an event controlled by players or aspects of the game, I don't know when it may fire so having a trigger for that seems logical.


When you control the code, you know when stuff happens. When you don't control the code, you don't know when stuff happens. It's as simple as that ><.

Now, there could be other systems out there that may be setting player color, and so a hook would be appropriate, but not every map is like that.

Thus, the hook should be 100% optional.

Only include features that are needed. Exclude features that aren't needed. Whenever you force someone into doing extra operations, that hurts the entire design of the map as a whole. The simple solution is generally the best solution, that is the solution that only does what you need and does it very simply.


As it stands with the forced hooking, I can tell you right now that I'd never use this ><, I'd make my own with optional hooking and release it ><.

So, instead of doing a hook, you could just do SetPlayerColorx and have it do all of your extra things, and then in cases where people needed the hook (using resources that change player colors), they can use a hook to make it easy ; ).


However, only way to do optional adding and removing of functions (change what they do etc) and hooks is through cJASS : \. static ifs won't do it unless it's in a function, so you realy need definitions.
 
Level 11
Joined
Nov 4, 2007
Messages
337
Actually a function is around 6 to 7x faster than a Trigger Evaluation, and it's around 11x faster than a vJASS trigger evaluation.


The idea here is to minimize extra operations ><. You don't need a tank to mow your lawn ><.

Where do you always get those stupid facts from?
Are you doing 10000 function calls and sit with a clock next to the computer counting the elapsing seconds?
A vJass evalaute is not slower than a normal trigger evaluation.

It doesn't matter at all how much faster it is.
God!
It matters if users do things like this:

  • Zeit - Every 0.01 seconds of game time
  • For each (Integer A) from 1 to 500, do (Actions)
    • Schleifen - Aktionen
      • Spielergruppe - Pick every player in (All players) and do (Actions)
        • Schleifen - Aktionen
          • Spieler - Set name of (Picked player) to Bernd
But normal people don't.


And now stop outfacing the poor guy!

You should remove everything except a GetPlayerColored function.
Then it's fine.
And don't call it Utils. Something so simple doesn't need Utils.
 
Where do you always get those stupid facts from?
Are you doing 10000 function calls and sit with a clock next to the computer counting the elapsing seconds?
A vJass evalaute is not slower than a normal trigger evaluation.

It doesn't matter at all how much faster it is.
God!
It matters if users do things like this:

  • Zeit - Every 0.01 seconds of game time
  • For each (Integer A) from 1 to 500, do (Actions)
    • Schleifen - Aktionen
      • Spielergruppe - Pick every player in (All players) and do (Actions)
        • Schleifen - Aktionen
          • Spieler - Set name of (Picked player) to Bernd
But normal people don't.


And now stop outfacing the poor guy!

You should remove everything except a GetPlayerColored function.
Then it's fine.
And don't call it Utils. Something so simple doesn't need Utils.


A vJass evalaute is not slower than a normal trigger evaluation.
Wrong -.- /sigh. Just some advice.. don't argue things you know nothing about -.-.

It doesn't matter at all how much faster it is.

Well, when designing a resource I'd hope it'd be as fast as possible. I know when I create a map, I care more about dev time, but with resources, I care more about quality so that my dev time can be really low and still produce a very high quality map. I mean, you only have to make the resource once and then you use it over and over again, so might as well make it perfect. With a map, you have to do constant updates, so you need to worry more about dev time/maintainability. Code Resources != Maps.


Also, speed does matter in certain systems like projectile systems. Yea, this system speed doesn't matter as much, but the idea is to keep resources free for other systems to use. Finish your operations with minimal effort and processing and people will be happy because they know that they can trust your resource : ). I know if a resource has flaws in it and the author refuses to fix them and I want to use it, I fix all the flaws (in some cases making it 2x faster and removing memory leaks the person just didn't care about), and then I sometimes submit it if it's actually useful.
 
Last edited:
Level 4
Joined
Jan 29, 2007
Messages
98
You should remove everything except a GetPlayerColored function.
Then it's fine.

I am really sorry, but I just won't do that !
Why should I remove a lot of hard work for me, and just keep 1 single function and then call it a resource ?!

And, what does it matter if I have some few more functionalities with this, it's not like you can't still use the "GetPlayerColored" function...

And, as Nestharus says, what is so wrong with a little speed in a snippet ?!
I mean, it might make the code a bit longer but still the users should only need to care about how to use the functions provided, and not the functionality around it, right ?
Isn't that why you make systems and snippets ?
So it'll be easy for the user to do more complicated stuff...

And, Nestharus, what is it that I can do to increase the speed a bit more ? :S
 
Ok, I'll go through all of your code and write suggestions ; )

#1, there's a really good header style I came up with that you might want to try out. It's a little more organize than the one's people normally use and at this point it's like my trademark: when people see it, they know who came up with it ^^.

To see different examples of the below-
http://www.thehelper.net/forums/showthread.php?t=135783
http://www.thehelper.net/forums/showthread.php?t=137848



#2- not all maps use all players. You should have a setting for people to check which players they want to use- COMPUTER, HUMAN, INACTIVE, EXTRA

To do this more easily, you could use Player Tracking ;). EXTRA is 12-15 btw.

If they want all, they just set all 4 to true. From here, you can do colored strings or w/e. You don't need to do ranges or w/e because these settings will do everything needed =).
JASS:
//if global settings, this goes inside of library, if not it goes above library
/*Information
===================================================================
Name: Name of the system (proper name)
Version: Version number. API Changes mean a new version (1.0 -> 2.0), internal changes mean new decimal version (1.0 -> 1.1)
Author: Author nickname

Settings:
This contains system settings
*///===================================================================
    private constant bool REMOVE_UNITS = false
/*//===================================================================

Description:
    What it does-
        This tells what this system does (goals etc)

    How it does it-
        This tells how it does it (optional) if people really want to know : )

Requirements have the name and URL to get it
Requirements: NA

Installation includes steps on how to put into a map and general map reqs
Installation: NA

Variable Settings
------------------------------------------------------------------
This includes all variable settings that are located at the top of the thing. Variable settings may add/remove code and features or may set limitations or starting points or well, whatever ; ).

-REMOVE_UNITS
    refers to whether or not units should be removed if a player is in the map.
    
API
------------------------------------------------------------------
This includes all public/normal functions and methods. Methods are separated by the objects they are inside of. It also includes all public/normal variables that are not settings.

constant function GetHiddenPlayer takes nothing returns player
    Returns a hidden player with all player features working (Player 14).

    Example-
    local player myHiddenPlayer = GetHiddenPlayer()

Syntax Features
    Any new syntax features, like new loops or w/e. This is only for cJASS, and possibly Zinc if Zinc adds definitions.

JASS:
library PlayerColors initializer Init
    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 constant string EndString = "|r"
    endglobals
    
    function PlayerColoredString takes integer playerId, string s returns string
        return PlayerColor[playerId] + s + EndString
    endfunction
    
    function PlayerColoredTextTag takes integer alpha, player p, texttag tag returns nothing
    
        if p != null then //should be debug
            call SetTextTagColor( tag, Red[GetPlayerId( p )], Green[GetPlayerId( p )], Blue[GetPlayerId( p )], alpha )
        endif //should be debug

    endfunction
    
    function PlayerColoredTextTagById takes integer alpha, integer playerId, texttag tag 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
    
//store the searching into a hashtable so that you can retrieve everything without going through a loop

//very trivial, but globals are faster than locals in most cases. Wc3 runs on a single thread, so you might as well remove all the local declarations and just make a couple of global declarations and use those. As I said, it's very trivial.

    //try making this a definition if you can : )
    private function CompressString takes string compstring returns string
        local integer w = StringLength( compstring )
        local integer i = 0
        local string s = ""
        
        loop
        //direct values = a bad practice. Use constants
        //SPACE = " ", COMMA = ",", etc
                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
    
    //I'd seriously remove this because two+ players could be the same color. 
    //this is extremely unstable -.-
    function GetPlayerByColor takes string s returns player
        local integer i = 0
        
        set s = StringCase( s, false )
        set s = CompressString( s ) //inline this?
        
        loop 
        //hashtable??
            if s == PlayerColorWordString[i] then
                return Player( i )
            endif
            
            set i = i + 1
            
        exitwhen ( i >= 13 )
        endloop
        
        //one hashtable would also remove all of this code ><
        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
    //same deal here with 2+ players on same color. Maybe make these 2
    //functions optional as not all maps can use these
    function GetPlayerColorByColor takes string s returns string
        local integer i = 0
        
        set s = StringCase( s, false )
        set s = CompressString( s )
        
        loop 
            //hashtable
            if s == PlayerColorWordString[i] then
                return PlayerColor[i]
            endif
            
            set i = i + 1
            exitwhen ( i >= 13 )
        endloop
        //again hashtable would clean this all up
        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
    //don't make this private, open this up. People know when they are changing a color, so let them make their own stuff with this.
    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]
    endfunction
    //make this optional. People only need this if they are using a resource that doesn't use player color change events.
    hook SetPlayerColor OnColorChange
    
    private function Init takes nothing returns nothing
        local integer i = 12
        local integer i2
        //how do you know the default player colors in any given map???
        //fact is you don't.
        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 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

And those are my comments ; )
 
Last edited:
Level 14
Joined
Nov 18, 2007
Messages
816
i doubt texttags do. Ive seen images do so, but texttags count down from 99 to 0, and every subsequent call to CreateTextTag returns null (which is 0).

When you pass invalid parameters to CreateImage then it returns an object with the ID -1, I suspect texttags would do the same, if 0 was reserved for a valid object.
 
Level 11
Joined
Apr 29, 2007
Messages
826
i doubt texttags do. Ive seen images do so, but texttags count down from 99 to 0, and every subsequent call to CreateTextTag returns null (which is 0).

When you pass invalid parameters to CreateImage then it returns an object with the ID -1, I suspect texttags would do the same, if 0 was reserved for a valid object.

I was referring to the fact that texttags behave differently from other handles, not that they should start from 0.
 
Level 4
Joined
Jan 29, 2007
Messages
98
Well done.

Thanks ! :D

GetPlayerColorByColor, erm whats the point of this function?

Just an extra feature...
Why not have it ?
It's easy to type "blue" and get Player 2 (Blue) :D

GetPlayerByColor - I'm fairly sure you can get an inlinable version of this. A hashtable may even be faster then the O(n) check.

Yeah, but I'm unsure how :S
Could you help ? :eek:

However, despite those two minor things this is good enough to be approved.

Thanks ! Finally ! :D:D
This hasn't even been approved at TheHelper.net yet, and there I've had a very big thread about it XD

I also have an update in stock, so I'll upload that right away ! :D
 
Top