Snippet String2PlayerColoredString

Azlier

Old World Ghost
Reaction score
461
Blaaargh.
JASS:
private function Init takes nothing returns nothing
    local integer i = 0
    loop
        set Players<i> = Player(i)
        set i = i + 1
        exitwhen i == 12
    endloop
    
    set PlayerColorString[0] = &quot;00ff0202&quot;
    set PlayerColorString[1] = &quot;000041ff&quot;
    set PlayerColorString[2] = &quot;001be5b8&quot;
    set PlayerColorString[3] = &quot;00530080&quot;
    set PlayerColorString[4] = &quot;00fffc00&quot;
    set PlayerColorString[5] = &quot;00fe890d&quot;
    set PlayerColorString[6] = &quot;001fbf00&quot;
    set PlayerColorString[7] = &quot;00e45aaf&quot;
    set PlayerColorString[8] = &quot;00949596&quot;
    set PlayerColorString[9] = &quot;007dbef1&quot;
    set PlayerColorString[10] = &quot;000f6145&quot;
    set PlayerColorString[11] = &quot;004d2903&quot;
    
    set i = 0
    loop
        set PlayerColor<i> = PlayerColorString<i>
        set i = i + 1
        exitwhen i == 12
    endloop
    //NO NO NO NO NO.
endfunction</i></i></i>


JASS:
private function Init takes nothing returns nothing
    local integer i = 11

    set PlayerColorString[0] = &quot;00ff0202&quot;
    set PlayerColorString[1] = &quot;000041ff&quot;
    set PlayerColorString[2] = &quot;001be5b8&quot;
    set PlayerColorString[3] = &quot;00530080&quot;
    set PlayerColorString[4] = &quot;00fffc00&quot;
    set PlayerColorString[5] = &quot;00fe890d&quot;
    set PlayerColorString[6] = &quot;001fbf00&quot;
    set PlayerColorString[7] = &quot;00e45aaf&quot;
    set PlayerColorString[8] = &quot;00949596&quot;
    set PlayerColorString[9] = &quot;007dbef1&quot;
    set PlayerColorString[10] = &quot;000f6145&quot;
    set PlayerColorString[11] = &quot;004d2903&quot;

    loop
        exitwhen i &lt; 0
        set Players<i> = Player(i)
        set PlayerColor<i> = PlayerColorString<i>
        set i = i - 1
    endloop
    
endfunction</i></i></i>
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Nice :D
Yet again... SILLY ME ! XD

Ok then... Is this correct ? :eek:
(Please say, YES ! XD)

JASS:
library PlayerColors initializer Init


///////////////////////////////////////////////////////////////////////////////////////////////////
//                                  //PlayerColoredString\\                                      //
//                                  //Made by, Komaqtion\\                                       //
//                                                                                               //
//                                                                                               //
//                                        Purpose:                                               //
//                                                                                               //
//             ¤ This snippet is supposed to help people to, with ease, convert                  //
//               a string to use a desired player&#039;s own color!                                   //
//                                                                                               //
//                                         Usage:                                                //
//                                                                                               //
//             ¤ To use this snippet, simply type &quot;call PlayerColoredString(string, playerid)&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" />                                                        //
//                                                                                               //                                                                                //
//                                    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>                          //
//                                                                                               //
//                                        Credits:                                               //
//                                                                                               //
//             ¤ Well, at the moment, not that many has helped me really, so no                  //
//               credits has been given yet                                                      //
//                                                                                               //
//               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 player array Players
    private string array PlayerColor
    private string array PlayerColorString
    private constant string EndString = &quot;|r&quot;
    private constant string StartString = &quot;|c&quot;
endglobals

function PlayerColoredString takes string s, integer playerId returns string
    return StartString + PlayerColor[playerId] + s + EndString
endfunction

function GetPlayerColorString takes player p returns string
    return StartString + PlayerColor[GetPlayerId(p)]
endfunction

function GetPlayerColorStringById takes integer playerId returns string
    return StartString + PlayerColor[playerId]
endfunction

private function OnColorChange takes player whichplayer, playercolor color returns nothing
    set PlayerColor[GetPlayerId(whichplayer)] = PlayerColorString[GetHandleId(color)]
endfunction

hook SetPlayerColor OnColorChange

private function Init takes nothing returns nothing
    local integer i = 11

    set PlayerColorString[0] = &quot;00ff0202&quot;
    set PlayerColorString[1] = &quot;000041ff&quot;
    set PlayerColorString[2] = &quot;001be5b8&quot;
    set PlayerColorString[3] = &quot;00530080&quot;
    set PlayerColorString[4] = &quot;00fffc00&quot;
    set PlayerColorString[5] = &quot;00fe890d&quot;
    set PlayerColorString[6] = &quot;001fbf00&quot;
    set PlayerColorString[7] = &quot;00e45aaf&quot;
    set PlayerColorString[8] = &quot;00949596&quot;
    set PlayerColorString[9] = &quot;007dbef1&quot;
    set PlayerColorString[10] = &quot;000f6145&quot;
    set PlayerColorString[11] = &quot;004d2903&quot;

    loop
        exitwhen i &lt; 0
        set Players<i> = Player(i)
        set PlayerColor<i> = PlayerColorString<i>
        set i = i - 1
    endloop
    
endfunction

endlibrary</i></i></i>
 

Azlier

Old World Ghost
Reaction score
461
You should just manually put |c on all the strings and get rid of the concatenation. Save time and memory.
 

Azlier

Old World Ghost
Reaction score
461
Get rid of StartString completely.
JASS:
set PlayerColorString[0] = &quot;00ff0202&quot;
set PlayerColorString[1] = &quot;000041ff&quot;
set PlayerColorString[2] = &quot;001be5b8&quot;

->
JASS:
set PlayerColorString[0] = &quot;|c00ff0202&quot;
set PlayerColorString[1] = &quot;|c000041ff&quot;
set PlayerColorString[2] = &quot;|c001be5b8&quot;
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, changed ;)

JASS:
library PlayerColors initializer Init


///////////////////////////////////////////////////////////////////////////////////////////////////
//                                  //PlayerColoredString\\                                      //
//                                  //Made by, Komaqtion\\                                       //
//                                                                                               //
//                                                                                               //
//                                        Purpose:                                               //
//                                                                                               //
//             ¤ This snippet is supposed to help people to, with ease, convert                  //
//               a string to use a desired player&#039;s own color!                                   //
//                                                                                               //
//                                         Usage:                                                //
//                                                                                               //
//             ¤ To use this snippet, simply type &quot;call PlayerColoredString(string, playerid)&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" />                                                        //
//                                                                                               //                                                                                //
//                                    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>                          //
//                                                                                               //
//                                        Credits:                                               //
//                                                                                               //
//             ¤ Well, at the moment, not that many has helped me really, so no                  //
//               credits has been given yet                                                      //
//                                                                                               //
//               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 player array Players
    private string array PlayerColor
    private string array PlayerColorString
    private constant string EndString = &quot;|r&quot;
endglobals

function PlayerColoredString takes string s, integer playerId returns string
    return PlayerColor[playerId] + s + EndString
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 OnColorChange takes player whichplayer, playercolor color returns nothing
    set PlayerColor[GetPlayerId(whichplayer)] = PlayerColorString[GetHandleId(color)]
endfunction

hook SetPlayerColor OnColorChange

private function Init takes nothing returns nothing
    local integer i = 11

    set PlayerColorString[0] = &quot;|c00ff0202&quot;
    set PlayerColorString[1] = &quot;|c000041ff&quot;
    set PlayerColorString[2] = &quot;|c001be5b8&quot;
    set PlayerColorString[3] = &quot;|c00530080&quot;
    set PlayerColorString[4] = &quot;|c00fffc00&quot;
    set PlayerColorString[5] = &quot;|c00fe890d&quot;
    set PlayerColorString[6] = &quot;|c001fbf00&quot;
    set PlayerColorString[7] = &quot;|c00e45aaf&quot;
    set PlayerColorString[8] = &quot;|c00949596&quot;
    set PlayerColorString[9] = &quot;|c007dbef1&quot;
    set PlayerColorString[10] = &quot;|c000f6145&quot;
    set PlayerColorString[11] = &quot;|c004d2903&quot;

    loop
        exitwhen i &lt; 0
        set Players<i> = Player(i)
        set PlayerColor<i> = PlayerColorString<i>
        set i = i - 1
    endloop
    
endfunction

endlibrary</i></i></i>


Btw... Any ideas on what else this snippet/system could do ? :S
I'm out of imagination, and need ideas for more features :D
 

Azlier

Old World Ghost
Reaction score
461
It seems to be perfect, except for one final thing...
[ljass]function PlayerColoredString takes string s, integer playerId returns string[/ljass]
Switch the arguments around, and that function will be inlined.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Done :D

JASS:
library PlayerColors initializer Init


///////////////////////////////////////////////////////////////////////////////////////////////////
//                                  //PlayerColoredString\\                                      //
//                                  //Made by, Komaqtion\\                                       //
//                                                                                               //
//                                                                                               //
//                                        Purpose:                                               //
//                                                                                               //
//             ¤ This snippet is supposed to help people to, with ease, convert                  //
//               a string to use a desired player&#039;s own color!                                   //
//                                                                                               //
//                                         Usage:                                                //
//                                                                                               //
//             ¤ To use this snippet, simply type &quot;call PlayerColoredString(string, playerid)&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" />                                                        //
//                                                                                               //                                                                                //
//                                    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>                          //
//                                                                                               //
//                                        Credits:                                               //
//                                                                                               //
//             ¤ Well, at the moment, not that many has helped me really, so no                  //
//               credits has been given yet                                                      //
//                                                                                               //
//               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 player array Players
    private string array PlayerColor
    private string array PlayerColorString
    private constant string EndString = &quot;|r&quot;
endglobals

function PlayerColoredString takes integer playerId, string s returns string
    return PlayerColor[playerId] + s + EndString
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 OnColorChange takes player whichplayer, playercolor color returns nothing
    set PlayerColor[GetPlayerId(whichplayer)] = PlayerColorString[GetHandleId(color)]
endfunction

hook SetPlayerColor OnColorChange

private function Init takes nothing returns nothing
    local integer i = 11

    set PlayerColorString[0] = &quot;|c00ff0202&quot;
    set PlayerColorString[1] = &quot;|c000041ff&quot;
    set PlayerColorString[2] = &quot;|c001be5b8&quot;
    set PlayerColorString[3] = &quot;|c00530080&quot;
    set PlayerColorString[4] = &quot;|c00fffc00&quot;
    set PlayerColorString[5] = &quot;|c00fe890d&quot;
    set PlayerColorString[6] = &quot;|c001fbf00&quot;
    set PlayerColorString[7] = &quot;|c00e45aaf&quot;
    set PlayerColorString[8] = &quot;|c00949596&quot;
    set PlayerColorString[9] = &quot;|c007dbef1&quot;
    set PlayerColorString[10] = &quot;|c000f6145&quot;
    set PlayerColorString[11] = &quot;|c004d2903&quot;

    loop
        exitwhen i &lt; 0
        set Players<i> = Player(i)
        set PlayerColor<i> = PlayerColorString<i>
        set i = i - 1
    endloop
    
endfunction

endlibrary</i></i></i>


Anything else ? :S
 

Azlier

Old World Ghost
Reaction score
461
Ahh. This is perhaps more efficient than any other player color string snippet out there, and this one works correctly when players switch colors. And now, I take my leave of you.

Though, you may want to set initial colors appropriately on MapInit, using GetHandleId. I don't know if hooks get the calls inside functions created by the World Editor.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Like this ? :S

JASS:
private function Init takes nothing returns nothing
    local integer i = 11

    set PlayerColorString[0] = &quot;|c00ff0202&quot;
    set PlayerColorString[1] = &quot;|c000041ff&quot;
    set PlayerColorString[2] = &quot;|c001be5b8&quot;
    set PlayerColorString[3] = &quot;|c00530080&quot;
    set PlayerColorString[4] = &quot;|c00fffc00&quot;
    set PlayerColorString[5] = &quot;|c00fe890d&quot;
    set PlayerColorString[6] = &quot;|c001fbf00&quot;
    set PlayerColorString[7] = &quot;|c00e45aaf&quot;
    set PlayerColorString[8] = &quot;|c00949596&quot;
    set PlayerColorString[9] = &quot;|c007dbef1&quot;
    set PlayerColorString[10] = &quot;|c000f6145&quot;
    set PlayerColorString[11] = &quot;|c004d2903&quot;

    loop
        exitwhen i &lt; 0
        set Players<i> = Player(i)
        set PlayerColor<i> = PlayerColorString[GetHandleId(GetPlayerColor(Players<i>))]
        set i = i - 1
    endloop
    
endfunction</i></i></i>
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok then :D Thanks ! ;)

So now, any suggestions for more features for it ? :eek:
 

Komaqtion

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

Is there no other features you want this system/snippet to contain ? :(
 

Azlier

Old World Ghost
Reaction score
461
You should really update the first post with the latest and greatest version.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah, wonder why I haven't done that... :S

Will do now ! ;)
Thanks :D
 

Jesus4Lyf

Good Idea™
Reaction score
397
Fixing time. This is looking good. :thup:
JASS:
loop
    set PlayerColor<i> = PlayerColorString[GetHandleId(GetPlayerColor(Player(i)))]
    exitwhen i == 0
    set i = i - 1
endloop</i>

Steal please. Get rid of Players array (??).
This won't work for Neutral Passive/Neutral Hostile, etc. Please fix for all 0-15 players (16 players). :thup:
Requires: vJASS compiler (JassHelper, which is included in JASS Newgen Pack)
Untrue - this requires an updated JassHelper, the one that comes with NewGen will not compile this as it uses hooks.

And in regards to your "credits" section, pretty sure I had to explicitly teach you how to use hooks and more or less tell you what to write. Not that I care much, but you said no one really helped... so at least remove that, if not thank. ;)

Edit: Hate to say it but this will probably get graveyarded, as this was released long ago...
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Steal please. Get rid of Players array (??).

Shouldn't I use it there, instead ? :S

This won't work for Neutral Passive/Neutral Hostile, etc. Please fix for all 0-15 players (16 players).

Will do ! ;)

Untrue - this requires an updated JassHelper, the one that comes with NewGen will not compile this as it uses hooks.

Which version is it that gives you the ability to "Hook" ? :S

And in regards to your "credits" section, pretty sure I had to explicitly teach you how to use hooks and more or less tell you what to write. Not that I care much, but you said no one really helped... so at least remove that, if not thank.

Changed now ! :D
Forgot to update that XD (Sorry, you've been very helpful, believe me ! ;)

Edit: Hate to say it but this will probably get graveyarded, as this was released long ago...

Yeah, I also almost "know" that, but I'll atleast try to do as much with this as I can, until it get graveyarded, because I'm learning alot !!! :D
 

Komaqtion

You can change this now in User CP.
Reaction score
469
>Shouldn't I use it there, instead ? :S
What for?

You could get the tiniest of efficiency gains, Darthfett, by saving all the players to a player array.

?

>Which version is it that gives you the ability to "Hook" ? :S
The latest (the actual version where it was added isn't really relevant, point is the user must update JassHelper). :thup:

Ok :D Thanks ! ;)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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