Snippet String2PlayerColoredString

Reaction score
341
He means;

JASS:
globals
    private string array PlayerColor
    private player array PLAYER
    private constant string EndColor = "|r"
endglobals

function S2PCS takes string s, integer playerId returns string    
    return PlayerColor[GetHandleId( GetPlayerColor(PLAYER[playerId]))] + s + EndColor
endfunction

function GetPlayerColorString takes player p returns string   
    return PlayerColor[GetHandleId( GetPlayerColor(p))]
endfunction

function GetPlayerColorStringById takes integer playerId returns string    
    return PlayerColor[GetHandleId( GetPlayerColor(PLAYER[playerId]))]
endfunction

private function Init takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i > 10
        set PLAYER<i> = Player(i)
        set i = i + 1
    endloop
    set PlayerColor[0] = &quot;|c00ff0202&quot;
    set PlayerColor[1] = &quot;|c000041ff&quot;
    set PlayerColor[2] = &quot;|c001be5b8&quot;
    set PlayerColor[3] = &quot;|c00530080&quot;
    set PlayerColor[4] = &quot;|c00fffc00&quot;
    set PlayerColor[5] = &quot;|c00fe890d&quot;
    set PlayerColor[6] = &quot;|c001fbf00&quot;
    set PlayerColor[7] = &quot;|c00e45aaf&quot;
    set PlayerColor[8] = &quot;|c00949596&quot;
    set PlayerColor[9] = &quot;|c007dbef1&quot;
    set PlayerColor[10] = &quot;|c000f6145&quot;
    set PlayerColor[11] = &quot;|c004d2903&quot;
    
endfunction

endlibrary</i>
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, changed that now :D Thanks !

Though, I've now discovered that the GetPlayerColorString doesn't really work :S

Here's how I test it, and nothing shows...
Trigger:
  • For each (Integer A) from 0 to 11, do (Actions)
    • Loop - Actions
      • Custom script: call BJDebugMsg(GetPlayerColorString(Player(bj_forLoopAIndex)))
      • Wait 0.10 seconds


Oh, btw... Here's how the code looks like now:
JASS:
library PlayerColors initializer Init


///////////////////////////////////////////////////////////////////////////////////////////////////
//                               //String2PlayerColoredString\\                                  //
//                                  //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 snipper, simply type &quot;call S2PCS(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 constant string EndString = &quot;|r&quot;
    private constant string StartString = &quot;|c&quot;
endglobals

function S2PCS takes string s, integer playerId returns string    
    return StartString + PlayerColor[GetHandleId( GetPlayerColor(Players[playerId]))] + s + EndString
endfunction

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

function GetPlayerColorStringById takes integer playerId returns string    
    return StartString + PlayerColor[GetHandleId( GetPlayerColor(Players[playerId]))]
endfunction

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 PlayerColor[0] = &quot;00ff0202&quot;
    set PlayerColor[1] = &quot;000041ff&quot;
    set PlayerColor[2] = &quot;001be5b8&quot;
    set PlayerColor[3] = &quot;00530080&quot;
    set PlayerColor[4] = &quot;00fffc00&quot;
    set PlayerColor[5] = &quot;00fe890d&quot;
    set PlayerColor[6] = &quot;001fbf00&quot;
    set PlayerColor[7] = &quot;00e45aaf&quot;
    set PlayerColor[8] = &quot;00949596&quot;
    set PlayerColor[9] = &quot;007dbef1&quot;
    set PlayerColor[10] = &quot;000f6145&quot;
    set PlayerColor[11] = &quot;004d2903&quot;
    
endfunction

endlibrary</i>



EDIT: Nvw... Artificial "helped" me XD


EDIT2: Btw, what takes for this to get approved (If it's even approvable XD :S) ? :eek:
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah, sure :D Will use then ;)

Is it ok if I use "PlayerColoredString" ? :eek:
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Adding an Endstring there would just negate the color code, making the call pointless.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
:confused:

This
Trigger:
  • For each (Integer A) from 0 to 11, do (Actions)
    • Loop - Actions
      • Custom script: call BJDebugMsg(GetPlayerColorString(Player(bj_forLoopAIndex)))
      • Wait 0.10 seconds

does not work because of missing Endstring?
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Read what I posted, lol. The entire point of that call is to cause text following it to be colored in the color of the entered player.
GetPlayerColorString(Player(bj_forLoopAIndex)) just causes any text following it in that string to be colored in whatever color the current player is.

Try GetPlayerColorString(Player(bj_forLoopAIndex)) + "HELLO WORLD".

:)

Should display a bunch of coloured 'HELLO WORLD's.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok... But any thoughts about the actuall code ? :eek:
Any chance of approving it ? :eek:
 

Azlier

Old World Ghost
Reaction score
461
Instead of calling GetHandleId(GetPlayerColor()), you could hook SetPlayerColor() (or whatever the native is) and save the proper things in an array. You get a nice efficiency gain there.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Actuallt, I've never used the "Hook" functionality :S

But I'll try :D Thanks :thup:
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, got the "Hook" stuff working now, I believe :S

Please take a look ;)

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[GetPlayerId(Players[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[GetPlayerId(Players[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 = 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
    
endfunction

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

Azlier

Old World Ghost
Reaction score
461
JASS:
function GetPlayerColorStringById takes integer playerId returns string    
    return StartString + PlayerColor[GetPlayerId(Players[playerId])]
endfunction

I should hit you!
JASS:
function GetPlayerColorStringById takes integer playerId returns string    
    return StartString + PlayerColor[playerId]
endfunction
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ouch :(

Sorry 'bout that XD

This then ? :S
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 = 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
    
endfunction

endlibrary</i></i></i>
 
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