Snippet String2PlayerColoredString

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, what is it that this needs to be approved, or at least thoroughly reviewed ? :S

(BumP ! :p)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
PLEASE !!!!

Review it, because I *need it for my current system ! :D

* I could do it without the library, but it reduces the length of the code quite a bit ! :D
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Bump it up !

C'mon people, am I being ignored somehow ?!
(I can't seem to get any attention on my posts lately :()
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah, I know !!!

That's why I think t's enough now, and this would be more than enough to get a good and thorough review, and also get approved... Right ?!
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Why not use a struct? I'd rather see something like that, imo.

JASS:

library Colors initializer onInit

    struct Color
        integer Redstring
        integer Bluestring
        integer Greenstring
        string PlayerC
        string word
        method PlayerString takes Color int, string txt returns string
            local Color good = int - 1
            return good.PlayerC + txt + "|r"
        endmethod
        
        private static method onInit takes nothing returns nothing
            local Color d = Color.create()
            set d.PlayerC = "|c00ff0202"
            set d.Redstring = 0xff
            set d.Bluestring = 0x02
            set d.Greenstring = 0x02
            set d.word = "red"
            
            set d = Color.create()
            set d.PlayerC = "|c000041ff"
            set d.Redstring = 0x00
            set d.Bluestring = 0x41
            set d.Greenstring = 0xff
            set d.word = "blue"
            
            set d = Color.create()
            /* etc... */
        endmethod
    endstruct
        
        private function Color_onChange takes player p, playercolor c returns nothing
            local Color pId = GetPlayerId(p)
            local Color cId = GetHandleId(c)
            
            set pId.Redstring = cId.Redstring
            set pId.Bluestring = cId.Bluestring
            set pId.Greenstring = cId.Greenstring
            set pId.PlayerC = cId.PlayerC
            set pId.word = cId.word
        endfunction
        
        hook SetPlayerColor Color_onChange
    
    // call functions
    /*
    
    local string s = Color.PlayerString(0, "<3 Komaqtion")
    
    */

endlibrary
 

Komaqtion

You can change this now in User CP.
Reaction score
469
I'm actually becoming pretty irritated about these two submissions I've got here !
I've recieved a lot of help, and both of these have gotten updated [a lot] !!!
I just don't see why it can't be approved ?!

I mean this on in particular has recieved 145 replies !!! (Now 146 :p)
And it still isn't good enough ?!?!
That's just wrong :(

(And, sorry GetTriggerUnit, but I'm not gonna redo the whole thing just like that... Sorry :()
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
call SetTextTagColor( tag, Red[GetPlayerId( p )], Green[GetPlayerId( p )], Blue[GetPlayerId( p )], alpha )

Repeating GetPlayerId( p )... better to store it. :)

JASS:
function PlayerColoredTextTag takes integer alpha, player p, texttag tag returns nothing

Hmm. It's kind of up to you, but I don't find the order of these parameters intuitive. I'd actually have them in the exact opposite order. Most important thing first (subject - texttag), then the next most important thing (player) then the thing that is there because you needed to put it there, alpha. It would also match better with Blizzard's convention. Same for the other text tag one.

JASS:
    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 &gt;= 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</i>

Should inline (use stringhash, some math perhaps and an array read).

JASS:
if SubString( compstring, i, i + 1 ) != &quot; &quot; or SubString( compstring, i, i + 1 ) != &quot;.&quot; or SubString( compstring, i, i + 1 ) != &quot;,&quot; then

Your CompressString function is not useful. That clause will always return true, because it will always pass at least one of those [LJASS]!=[/LJASS] checks and you have used [LJASS]or[/LJASS]. I don't think you need this anyway.

JASS:
function PlayerColoredString takes integer playerId, string s returns string

Doesn't follow your own convention, it's not intuitive - it should have ById on the end to match your other functions, and there should be a PlayerColoredString which takes a player.

JASS:
function GetPlayerColorByColor takes string s returns string

Wut?

Thanks for your patience.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
JASS:
call SetTextTagColor( tag, Red[GetPlayerId( p )], Green[GetPlayerId( p )], Blue[GetPlayerId( p )], alpha )

Repeating GetPlayerId( p )... better to store it. :)

Yeah, will do ;)

JASS:
function PlayerColoredTextTag takes integer alpha, player p, texttag tag returns nothing

Hmm. It's kind of up to you, but I don't find the order of these parameters intuitive. I'd actually have them in the exact opposite order. Most important thing first (subject - texttag), then the next most important thing (player) then the thing that is there because you needed to put it there, alpha. It would also match better with Blizzard's convention. Same for the other text tag one.

Hehe, yeah I just noticed that now XD
Will change :D

JASS:
    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 &gt;= 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</i>

Should inline (use stringhash, some math perhaps and an array read).


Hmm... I'm sorry but I don't really get what you mean :S
How could all that possibly inline ? XD

JASS:
if SubString( compstring, i, i + 1 ) != &quot; &quot; or SubString( compstring, i, i + 1 ) != &quot;.&quot; or SubString( compstring, i, i + 1 ) != &quot;,&quot; then

Your CompressString function is not useful. That clause will always return true, because it will always pass at least one of those [LJASS]!=[/LJASS] checks and you have used [LJASS]or[/LJASS]. I don't think you need this anyway.

Oh, so I should just remove it ?
But what if I write something like "Bl Ue", isn't it useful to be able to interpret that ? :eek:

JASS:
function PlayerColoredString takes integer playerId, string s returns string

Doesn't follow your own convention, it's not intuitive - it should have ById on the end to match your other functions, and there should be a PlayerColoredString which takes a player.

Yeah, ok will add ;)

JASS:
function GetPlayerColorByColor takes string s returns string

Wut?

What ?!
What's wrong with that one ?
If I just need a color, I'd use that...

Thanks for your patience.

Hehe XD Thanks for yours ! ;)
I'll work on the changes now ! :D
 

Jesus4Lyf

Good Idea™
Reaction score
397
Hmm... I'm sorry but I don't really get what you mean :S
How could all that possibly inline ? XD
JASS:
return MyArray[StringHash(s)/100+200/*or something to make a valid index*/]

Oh, so I should just remove it ?
But what if I write something like "Bl Ue", isn't it useful to be able to interpret that ? :eek:
I'd say yes. At the moment it doesn't work, so it seems no one cares anyway.
What ?!
What's wrong with that one ?
If I just need a color, I'd use that...
You misunderstand - I have no idea what that function does.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
JASS:
return MyArray[StringHash(s)/100+200/*or something to make a valid index*/]

I'm sorry, but I don't know what [ljass]StringHash[/ljass] is :S
Please, could you give me a better example...
And, what variable type should MyArray be ?

I'd say yes. At the moment it doesn't work, so it seems no one cares anyway.

Well, why not just fix it to make it work then ?!

You misunderstand - I have no idea what that function does.

That function simply gives you the color code of the color you type...

Like if you type [ljass]call GetPlayerColorByColor( "blue" )[/ljass] then it'd return "|c001be5b8" hopefully XD
 

Jesus4Lyf

Good Idea™
Reaction score
397
I'm sorry, but I don't know what [ljass]StringHash[/ljass] is :S
Please, could you give me a better example...
And, what variable type should MyArray be ?
Look closely:
JASS:
scope X initializer OnInit
    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
    endglobals
    
    private function OnInit takes nothing returns nothing
        local integer i
        
        set PlayerColorString[0] = &quot;|c00ff0202&quot;
        set RedString[0] = 0xff
        set GreenString[0] = 0x02
        set BlueString[0] = 0x02
        set PlayerColorWordString[0] = &quot;red&quot;
        set PlayerColorString[1] = &quot;|c000041ff&quot;
        set RedString[1] = 0x00
        set GreenString[1] = 0x41
        set BlueString[1] = 0xff
        set PlayerColorWordString[1] = &quot;blue&quot;
        set PlayerColorString[2] = &quot;|c001be5b8&quot;
        set RedString[2] = 0x1b
        set GreenString[2] = 0xe5
        set BlueString[2] = 0xb8
        set PlayerColorWordString[2] = &quot;teal&quot;
        set PlayerColorString[3] = &quot;|c00530080&quot;
        set RedString[3] = 0x53
        set GreenString[3] = 0x00
        set BlueString[3] = 0x80
        set PlayerColorWordString[3] = &quot;purple&quot;
        set PlayerColorString[4] = &quot;|c00fffc00&quot;
        set RedString[4] = 0xff
        set GreenString[4] = 0xfc
        set BlueString[4] = 0x00
        set PlayerColorWordString[4] = &quot;yellow&quot;
        set PlayerColorString[5] = &quot;|c00fe890d&quot;
        set RedString[5] = 0xfe
        set GreenString[5] = 0x89
        set BlueString[5] = 0x0d
        set PlayerColorWordString[5] = &quot;orange&quot;
        set PlayerColorString[6] = &quot;|c001fbf00&quot;
        set RedString[6] = 0x1f
        set GreenString[6] = 0xbf
        set BlueString[6] = 0x00
        set PlayerColorWordString[6] = &quot;green&quot;
        set PlayerColorString[7] = &quot;|c00e45aaf&quot;
        set RedString[7] = 0xe4
        set GreenString[7] = 0x5a
        set BlueString[7] = 0xaf
        set PlayerColorWordString[7] = &quot;pink&quot;
        set PlayerColorString[8] = &quot;|c00949596&quot;
        set RedString[8] = 0x94
        set GreenString[8] = 0x95
        set BlueString[8] = 0x96
        set PlayerColorWordString[8] = &quot;grey&quot;
        set PlayerColorString[9] = &quot;|c007dbef1&quot;
        set RedString[9] = 0x7d
        set GreenString[9] = 0xbe
        set BlueString[9] = 0xf1
        set PlayerColorWordString[9] = &quot;lightblue&quot;
        set PlayerColorString[10] = &quot;|c000f6145&quot;
        set RedString[10] = 0x0f
        set GreenString[10] = 0x61
        set BlueString[10] = 0x45
        set PlayerColorWordString[10] = &quot;darkgreen&quot;
        set PlayerColorString[11] = &quot;|c004d2903&quot;
        set RedString[11] = 0x4d
        set GreenString[11] = 0x29
        set BlueString[11] = 0x03
        set PlayerColorWordString[11] = &quot;brown&quot;

        set PlayerColorString[12] = &quot;|c00272727&quot;
        set RedString[12] = 0x27
        set GreenString[12] = 0x27
        set BlueString[12] = 0x27
        set PlayerColorWordString[12] = &quot;darkgrey&quot;
        
        set i=13
        loop
            set i=i-1
            call BJDebugMsg(I2S( StringHash(PlayerColorWordString<i>)/29000000+73 ))
            exitwhen i==0
        endloop
    endfunction
endscope
</i>

Copy/paste and see what it displays. StringHash converts a string into an integer. You can, with some math, use the result in an array index, to make said function inline.
Well, why not just fix it to make it work then ?!
Because (my opinion) it's useless and a large performance hit which leaks strings.
That function simply gives you the color code of the color you type...
Document it. It should inline too, using the above method. :)

You've done nasty things to perfect functions to block them from inlining for unknown reasons. Please revert those changes.

Example:
JASS:
    function GetPlayerColorString takes player p returns string
        local integer id = GetPlayerId( p )
        
        return PlayerColor[id]
    endfunction

It was perfect before.
JASS:
    function GetPlayerColorString takes player p returns string
        return PlayerColor[GetPlayerId( p )]
    endfunction


I think it's time for you to read this. :)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, I've done this now:
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&#039;d possibly want.                                            @@//
//@@                                                                                               @@//
//@@                                         Usage:                                                @@//
//@@                                                                                               @@//
//@@             ¤ To use this snippet, simply type &quot;call PlayerColoredString(playerid, string)&quot;   @@//
//@@               where &quot;string&quot; is the string you want to colorize, and &quot;playerid&quot;               @@//
//@@               is the player number of the player, whose color you wan to use.                 @@//
//@@               Note: This uses JASS&#039; player number range, meaning that                         @@//
//@@               Player 1(Red)&#039;s number is 0, and Player 2(Blue)&#039;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 &quot;GetPlayerColorString&quot;               @@//
//@@               which takes the player to get the string, or you can also use                   @@//
//@@               the GetPlayerColorStringById function, which takes the player&#039;s                 @@//
//@@               Id, or number instead <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                                                        @@//
//@@               You can also change the color of texttags using this snippet...                 @@//
//@@               The function is called &quot;PlayerColoredTextTag&quot; 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 &quot;GetPlayerByColor&quot; which takes a string (color)   @@//
//@@               and returns the player which has that specific color. You can even type         @@//
//@@               &quot;ReD&quot; or &quot;REd&quot; or even &quot;..,,  R, e.., d&quot; and it&#039;ll return Player(0) or          @@//
//@@               player red in all three cases. And, you can also get the player&#039;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 &quot;Red&quot; !                                   @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                    Requirements:                                              @@//
//@@                                                                                               @@//
//@@             ¤ This snippet&#039;s only requirement is vJASS compilement, which is                  @@//
//@@               easiest achieved by downloading JASS Newgen Pack, at                            @@//
//@@               <a href="http://www.thehelper.net/forums/showthread.php?t=73936" class="link link--internal">http://www.thehelper.net/forums/showthread.php?t=73936</a>                          @@//
//@@               You&#039;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 ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                                    @@//
//@@               Quraji, for helping me add the &quot;GetPlayerByColor&quot; function ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                 @@//
//@@                                                                                               @@//
//@@               And credits, if you use this that is, is not needed to give me                  @@//
//@@               though it&#039;s always welcome <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />                                                   @@//
//@@                                                                                               @@//
//@@///////////////////////////////////////////////////////////////////////////////////////////////@@//
//***************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////


    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 = &quot;|r&quot;
    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 = &quot;&quot;
        
        loop
        
                if SubString( compstring, i, i + 1 ) != &quot; &quot; or SubString( compstring, i, i + 1 ) != &quot;.&quot; or SubString( compstring, i, i + 1 ) != &quot;,&quot; then
                    set s = s + SubString( compstring, i, i + 1 )
                endif
                
            set i = i + 1
            
        exitwhen i &gt; 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] = &quot;|c00ff0202&quot;
        set RedString[0] = 0xff
        set GreenString[0] = 0x02
        set BlueString[0] = 0x02
        set PlayerColorWordString[0] = &quot;red&quot;
        set PlayerColorString[1] = &quot;|c000041ff&quot;
        set RedString[1] = 0x00
        set GreenString[1] = 0x41
        set BlueString[1] = 0xff
        set PlayerColorWordString[1] = &quot;blue&quot;
        set PlayerColorString[2] = &quot;|c001be5b8&quot;
        set RedString[2] = 0x1b
        set GreenString[2] = 0xe5
        set BlueString[2] = 0xb8
        set PlayerColorWordString[2] = &quot;teal&quot;
        set PlayerColorString[3] = &quot;|c00530080&quot;
        set RedString[3] = 0x53
        set GreenString[3] = 0x00
        set BlueString[3] = 0x80
        set PlayerColorWordString[3] = &quot;purple&quot;
        set PlayerColorString[4] = &quot;|c00fffc00&quot;
        set RedString[4] = 0xff
        set GreenString[4] = 0xfc
        set BlueString[4] = 0x00
        set PlayerColorWordString[4] = &quot;yellow&quot;
        set PlayerColorString[5] = &quot;|c00fe890d&quot;
        set RedString[5] = 0xfe
        set GreenString[5] = 0x89
        set BlueString[5] = 0x0d
        set PlayerColorWordString[5] = &quot;orange&quot;
        set PlayerColorString[6] = &quot;|c001fbf00&quot;
        set RedString[6] = 0x1f
        set GreenString[6] = 0xbf
        set BlueString[6] = 0x00
        set PlayerColorWordString[6] = &quot;green&quot;
        set PlayerColorString[7] = &quot;|c00e45aaf&quot;
        set RedString[7] = 0xe4
        set GreenString[7] = 0x5a
        set BlueString[7] = 0xaf
        set PlayerColorWordString[7] = &quot;pink&quot;
        set PlayerColorString[8] = &quot;|c00949596&quot;
        set RedString[8] = 0x94
        set GreenString[8] = 0x95
        set BlueString[8] = 0x96
        set PlayerColorWordString[8] = &quot;grey&quot;
        set PlayerColorString[9] = &quot;|c007dbef1&quot;
        set RedString[9] = 0x7d
        set GreenString[9] = 0xbe
        set BlueString[9] = 0xf1
        set PlayerColorWordString[9] = &quot;lightblue&quot;
        set PlayerColorString[10] = &quot;|c000f6145&quot;
        set RedString[10] = 0x0f
        set GreenString[10] = 0x61
        set BlueString[10] = 0x45
        set PlayerColorWordString[10] = &quot;darkgreen&quot;
        set PlayerColorString[11] = &quot;|c004d2903&quot;
        set RedString[11] = 0x4d
        set GreenString[11] = 0x29
        set BlueString[11] = 0x03
        set PlayerColorWordString[11] = &quot;brown&quot;

        set PlayerColorString[12] = &quot;|c00272727&quot;
        set RedString[12] = 0x27
        set GreenString[12] = 0x27
        set BlueString[12] = 0x27
        set PlayerColorWordString[12] = &quot;darkgrey&quot;
        
        set PlayerColorWordString[13] = &quot;gray&quot;
        set PlayerColorWordString[14] = &quot;aqua&quot;
        set PlayerColorWordString[15] = &quot;cyan&quot;
        set PlayerColorWordString[16] = &quot;darkgray&quot;
        set PlayerColorWordString[17] = &quot;neutral&quot;
    
        loop
            exitwhen i &lt; 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</i></i></i></i></i></i>


And it seems to be working :D
Is it how you meant ? :eek:
 

Jesus4Lyf

Good Idea™
Reaction score
397

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah, but how would I make an array link the PlayerColorWordString´[ 13 through 17 ] to the stuff they should be linked to ? :S

The only solution I see there is, hashtables...
But please, if you know of anything else, share it ! :D
 

Jesus4Lyf

Good Idea™
Reaction score
397
StringHash converts a string into an integer. You can, with some math, use the result in an array index
I don't think it's that hard. Do you need me to take my example and put an array in instead of BJDebugMsg(I2S(...))?

Edit: Well, just in case:
JASS:
set myAttachmentArray[StringHash(myString)/29000000+73]=myValue // saving attachment
call DoSomethingWithResult(myAttachmentArray[StringHash(myString)/29000000+73]) // loading attachment

You must make sure there are no collisions with the math involved. That's all. (As in, each string you wish to attach to returns a unique value. Else divide by a lower number.)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, is this something of what you thought ? :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&#039;d possibly want.                                            @@//
//@@                                                                                               @@//
//@@                                         Usage:                                                @@//
//@@                                                                                               @@//
//@@             ¤ To use this snippet, simply type &quot;call PlayerColoredString(playerid, string)&quot;   @@//
//@@               where &quot;string&quot; is the string you want to colorize, and &quot;playerid&quot;               @@//
//@@               is the player number of the player, whose color you wan to use.                 @@//
//@@               Note: This uses JASS&#039; player number range, meaning that                         @@//
//@@               Player 1(Red)&#039;s number is 0, and Player 2(Blue)&#039;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 &quot;GetPlayerColorString&quot;               @@//
//@@               which takes the player to get the string, or you can also use                   @@//
//@@               the GetPlayerColorStringById function, which takes the player&#039;s                 @@//
//@@               Id, or number instead <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                                                        @@//
//@@               You can also change the color of texttags using this snippet...                 @@//
//@@               The function is called &quot;PlayerColoredTextTag&quot; 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 &quot;GetPlayerByColor&quot; which takes a string (color)   @@//
//@@               and returns the player which has that specific color. You can even type         @@//
//@@               &quot;ReD&quot; or &quot;REd&quot; or even &quot;..,,  R, e.., d&quot; and it&#039;ll return Player(0) or          @@//
//@@               player red in all three cases. And, you can also get the player&#039;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 &quot;Red&quot; !                                   @@//
//@@                                                                                               @@//
//@@                                                                                               @@//
//@@                                    Requirements:                                              @@//
//@@                                                                                               @@//
//@@             ¤ This snippet&#039;s only requirement is vJASS compilement, which is                  @@//
//@@               easiest achieved by downloading JASS Newgen Pack, at                            @@//
//@@               <a href="http://www.thehelper.net/forums/showthread.php?t=73936" class="link link--internal">http://www.thehelper.net/forums/showthread.php?t=73936</a>                          @@//
//@@               You&#039;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 ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                                    @@//
//@@               Quraji, for helping me add the &quot;GetPlayerByColor&quot; function ! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />                 @@//
//@@                                                                                               @@//
//@@               And credits, if you use this that is, is not needed to give me                  @@//
//@@               though it&#039;s always welcome <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />                                                   @@//
//@@                                                                                               @@//
//@@///////////////////////////////////////////////////////////////////////////////////////////////@@//
//***************************************************************************************************//
///////////////////////////////////////////////////////////////////////////////////////////////////////


    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 player array StoredPlayers
        
        private constant string EndString = &quot;|r&quot;
    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 = &quot;&quot;
        
        loop
        
                if SubString( compstring, i, i + 1 ) != &quot; &quot; or SubString( compstring, i, i + 1 ) != &quot;.&quot; or SubString( compstring, i, i + 1 ) != &quot;,&quot; then
                    set s = s + SubString( compstring, i, i + 1 )
                endif
                
            set i = i + 1
            
        exitwhen i &gt; w
        endloop
        
        return s
    endfunction*/
    
    function GetPlayerByColor takes string s returns player
        //return LoadPlayerHandle( StoredColors, 1, StringHash( StringCase( s, false ) ) / 20000000 + 96 )
        return StoredPlayers[ 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 ) ) ]
        return PlayerColor[ GetPlayerId( StoredPlayers[ 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]
        set StoredPlayers[ StringHash( PlayerColorWordString[ pc ] ) / 20000000 + 96 ] = whichPlayer
        
        //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] = &quot;|c00ff0202&quot;
        set RedString[0] = 0xff
        set GreenString[0] = 0x02
        set BlueString[0] = 0x02
        set PlayerColorWordString[0] = &quot;red&quot;
        set PlayerColorString[1] = &quot;|c000041ff&quot;
        set RedString[1] = 0x00
        set GreenString[1] = 0x41
        set BlueString[1] = 0xff
        set PlayerColorWordString[1] = &quot;blue&quot;
        set PlayerColorString[2] = &quot;|c001be5b8&quot;
        set RedString[2] = 0x1b
        set GreenString[2] = 0xe5
        set BlueString[2] = 0xb8
        set PlayerColorWordString[2] = &quot;teal&quot;
        set PlayerColorString[3] = &quot;|c00530080&quot;
        set RedString[3] = 0x53
        set GreenString[3] = 0x00
        set BlueString[3] = 0x80
        set PlayerColorWordString[3] = &quot;purple&quot;
        set PlayerColorString[4] = &quot;|c00fffc00&quot;
        set RedString[4] = 0xff
        set GreenString[4] = 0xfc
        set BlueString[4] = 0x00
        set PlayerColorWordString[4] = &quot;yellow&quot;
        set PlayerColorString[5] = &quot;|c00fe890d&quot;
        set RedString[5] = 0xfe
        set GreenString[5] = 0x89
        set BlueString[5] = 0x0d
        set PlayerColorWordString[5] = &quot;orange&quot;
        set PlayerColorString[6] = &quot;|c001fbf00&quot;
        set RedString[6] = 0x1f
        set GreenString[6] = 0xbf
        set BlueString[6] = 0x00
        set PlayerColorWordString[6] = &quot;green&quot;
        set PlayerColorString[7] = &quot;|c00e45aaf&quot;
        set RedString[7] = 0xe4
        set GreenString[7] = 0x5a
        set BlueString[7] = 0xaf
        set PlayerColorWordString[7] = &quot;pink&quot;
        set PlayerColorString[8] = &quot;|c00949596&quot;
        set RedString[8] = 0x94
        set GreenString[8] = 0x95
        set BlueString[8] = 0x96
        set PlayerColorWordString[8] = &quot;grey&quot;
        set PlayerColorString[9] = &quot;|c007dbef1&quot;
        set RedString[9] = 0x7d
        set GreenString[9] = 0xbe
        set BlueString[9] = 0xf1
        set PlayerColorWordString[9] = &quot;lightblue&quot;
        set PlayerColorString[10] = &quot;|c000f6145&quot;
        set RedString[10] = 0x0f
        set GreenString[10] = 0x61
        set BlueString[10] = 0x45
        set PlayerColorWordString[10] = &quot;darkgreen&quot;
        set PlayerColorString[11] = &quot;|c004d2903&quot;
        set RedString[11] = 0x4d
        set GreenString[11] = 0x29
        set BlueString[11] = 0x03
        set PlayerColorWordString[11] = &quot;brown&quot;

        set PlayerColorString[12] = &quot;|c00272727&quot;
        set RedString[12] = 0x27
        set GreenString[12] = 0x27
        set BlueString[12] = 0x27
        set PlayerColorWordString[12] = &quot;darkgrey&quot;
        
        set PlayerColorWordString[13] = &quot;gray&quot;
        set PlayerColorWordString[14] = &quot;aqua&quot;
        set PlayerColorWordString[15] = &quot;cyan&quot;
        set PlayerColorWordString[16] = &quot;darkgray&quot;
        set PlayerColorWordString[17] = &quot;neutral&quot;
    
        loop
            exitwhen i &lt; 0
            //call SavePlayerHandle( StoredColors, 1, StringHash( PlayerColorWordString[ i ] ) / 20000000 + 96, Player( i ) )
            
            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
        
        //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 ) )
        
        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</i>
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Hehe, thanks !
Hmm... Hard choice there :S
Which way do you lean more at ? :eek:
Maybe we can somehow work this out together ? :eek:
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top