Snippet String2PlayerColoredString

Komaqtion

You can change this now in User CP.
Reaction score
469
Hi!
I though I'd submit this snippet/system (It's gotten quite big now ! :D), solves all of you player-color problems ! ;)

I know there are a lot of "String-Manipulating-Systems" out there, which are a lot more complicated and have more features than this one, but I'm not sure if they use this way of handling stuff...

That's why I've created this (Though I don't know if there are many of this kind of systems out there, but still...)

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

Da Code! :

JASS:
library PlayerColors initializer Init


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//*********************************************************************************************************//
//@@/////////////////////////////////// *//PlayerColorUtils\\* //////////////////////////////////////////@@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                      @@//
//@@                  %%                                                         %%                      @@//
//@@                  %%    //\\\\\               /////////  ///          \\\    %%                      @@//
//@@                  %%    //\\   \\\        //////         ///          \\\    %%                      @@//
//@@                  %%    //\\     \\\     /////           ///          \\\    %%                      @@//
//@@                  %%    //\\     ///   ////              ///          \\\    %%                      @@//
//@@                  %%    //\\   ///    ////               ///          \\\    %%                      @@//
//@@                  %%    //\\///      ////                ///          \\\    %%                      @@//
//@@                  %%    //\\         \\\\                ////        \\\\    %%                      @@//
//@@                  %%    //\\          \\\\               ////        \\\\    %%                      @@//
//@@                  %%    //\\           \\\\              ////        \\\\    %%                      @@//
//@@                  %%    //\\             \\\\\            ////      \\\\     %%                      @@//
//@@                  %%    //\\               \\\\\\          ////    \\\\      %%                      @@//
//@@                  %%    //\\                  \\\\\\\\\       ///\\\         %%                      @@//
//@@                  %%                                                         %%                      @@//
//@@                  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                      @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                     Made by , Komaqtion                                             @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                         Purpose:                                                    @@//
//@@                                                                                                     @@//
//@@         # This snippet is supposed to help people to, with ease, to use the actual ARGB             @@//
//@@           colors of players in all aspects they'd possibly want.                                    @@//
//@@                                                                                                     @@//
//@@                                         Usage:                                                      @@//
//@@                                                                                                     @@//
//@@         # The function provided by this small system is:                                            @@//
//@@           *NOTE* If you input an invalid player in any of the functions, it'll                      @@//
//@@           automatically work as if you inputted Player( 0 ), or Player (Red)...                     @@//
//@@                                                                                                     @@//
//@@      function PlayerColoredString takes player p, string coloredString returns string               @@//
//@@                                                                                                     @@//
//@@               - "player p" -> The player of which you want to use the color for the                 @@//
//@@               inputted string.                                                                      @@//
//@@               - "string coloredString" -> The string which is to be returned                        @@//
//@@               in the wanted playercolor.                                                            @@//
//@@               - "returns string" -> This function will return the inputted string,                  @@//
//@@               but in the playercolor of the player with the inputted playerid.                      @@//
//@@                                                                                                     @@//
//@@      function PlayerColoredStringById takes integer playerId, string coloredString returns string   @@//
//@@                                                                                                     @@//
//@@               - "integer playerId" -> The player-number of the player's color                       @@//
//@@               you wish to use.                                                                      @@//
//@@               - "string coloredString" -> The string which is to be returned                        @@//
//@@               in the wanted playercolor.                                                            @@//
//@@               - "returns string" -> This function will return the inputted string,                  @@//
//@@               but in the playercolor of the player with the inputted playerid.                      @@//
//@@                                                                                                     @@//
//@@      function GetPlayerNameColored takes player p returns string                                    @@//
//@@                                                                                                     @@//
//@@               - "player p" -> The player of which you want to use the color for the                 @@//
//@@               inputted string. (And also the name <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />)                                               @@//
//@@               - &quot;returns string&quot; -&gt; This function will return the player&#039;s name you                 @@//
//@@               inputted, but in the playercolor of that player.                                      @@//
//@@                                                                                                     @@//
//@@      function PlayerColoredTextTag takes texttag coloredTag,                                        @@//
//@@               player p, integer alpha returns nothing                                               @@//
//@@                                                                                                     @@//
//@@               - &quot;texttag coloredTag&quot; -&gt; The texttag of which the color is to be changed.            @@//
//@@               - &quot;player p&quot; -&gt; The player of which color the texttag is to be changed to.            @@//
//@@               - &quot;integer alpha&quot; -&gt; The amount of transparency the text (texttag) should have.       @@//
//@@               /\ THIS RANGES FROM 0 TO 255, WITH 255 BEING 100% SEETHROUGH ! /\                     @@//
//@@               - &quot;returns nothing&quot; -&gt; This function will not return anything, as it just             @@//
//@@               modifies the existing texttag, and can&#039;t be used in any variable or so.               @@//
//@@                                                                                                     @@//
//@@      function PlayerColoredTextTagById takes texttag coloredTag,                                    @@//
//@@               integer playerId, integer alpha returns nothing                                       @@//
//@@                                                                                                     @@//
//@@               - &quot;texttag coloredTag&quot; -&gt; The texttag of which the color is to be changed.            @@//
//@@               - &quot;integer playerId&quot; -&gt; The playerid of the player of which color the texttag         @@//
//@@               is to be changed to.                                                                  @@//
//@@               - &quot;integer alpha&quot; -&gt; The amount of transparency the text (texttag) should have.       @@//
//@@               /\ THIS RANGES FROM 0 TO 255, WITH 255 BEING 100% SEETHROUGH ! /\                     @@//
//@@               - &quot;returns nothing&quot; -&gt; This function will not return anything, as it just             @@//
//@@               modifies the existing texttag, and can&#039;t be used in any variable or so.               @@//
//@@                                                                                                     @@//
//@@      function GetPlayerColorString takes player p returns string                                    @@//
//@@                                                                                                     @@//
//@@               - &quot;player p&quot; -&gt; The player we will be getting the &quot;color-code&quot; of.                    @@//
//@@               - &quot;returns string&quot; -&gt; This function will return the actual ARGB code                  @@//
//@@               (Not the system, but the hex-code).                                                   @@//
//@@                                                                                                     @@//
//@@      function GetPlayerColorStringById takes integer playerId returns string                        @@//
//@@                                                                                                     @@//
//@@               - &quot;integer playerId&quot; -&gt; The id of the player we will be getting                       @@//
//@@               the &quot;color-code&quot; of.                                                                  @@//
//@@               - &quot;returns string&quot; -&gt; This function will return the actual ARGB code                  @@//
//@@               (Not the system, but the hex-code).                                                   @@//
//@@                                                                                                     @@//
//@@      function GetPlayerByColor takes string color returns player                                    @@//
//@@                                                                                                     @@//
//@@               - &quot;string color&quot; -&gt; This is where you put the color of the player                     @@//
//@@                you want to get (E.g &quot;blue&quot;)                                                         @@//
//@@               - &quot;returns player&quot; -&gt; As said, this is the player who has                             @@//
//@@               the color you inputted.                                                               @@//
//@@                                                                                                     @@//
//@@      function GetPlayerColorStringByColor takes string color returns string                         @@//
//@@                                                                                                     @@//
//@@               - &quot;string color&quot; -&gt; This is the player&#039;s color of which you                           @@//
//@@               want to get it&#039;s &quot;color-code&quot; (Or hex-code)                                           @@//
//@@               - &quot;returns string&quot; -&gt; This is the hex-code of the color the                           @@//
//@@               player uses (E.g &quot;|c00ff0202&quot;)                                                        @@//
//@@                                                                                                     @@//
//@@               - That is it ! <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" /> Hope you&#039;ve understood all the functions clearly now !              @@//
//@@               If not, then just post in the thread and I&#039;ll update this documentation <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />            @@//
//@@                                                                                                     @@//
//@@                                                                                                     @@//
//@@                                    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" />                     @@//
//@@               - Darthfett, for giving me some pointers on this documentation <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=";)" />                                                         @@//
//@@                                                                                                     @@//
//@@/////////////////////////////////////////////////////////////////////////////////////////////////////@@//
//*********************************************************************************************************//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////


// Configuration, though it isn&#039;t much <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />

    globals
        private constant string EndString = &quot;|r&quot;     // This actually shouldn&#039;t be changeable XD
                                                     // But I made it so anyways <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
    endglobals

// End of Configuration !!!! DON&#039;T TOUCH BELOW THIS !!!!!
// End of Configuration !!!! DON&#039;T TOUCH BELOW THIS !!!!!
// End of Configuration !!!! DON&#039;T TOUCH BELOW THIS !!!!!
// End of Configuration !!!! DON&#039;T TOUCH BELOW THIS !!!!!

    globals
        private integer array Red                      // This is used to keep track of the &quot;redness&quot; in each player&#039;s the hex-codes
        private integer array Green                    // This is used to keep track of the &quot;greenness&quot; in each player&#039;s the hex-codes
        private integer array Blue                     // This is used to keep track of the &quot;blueness&quot; in each player&#039;s the hex-codes
        private integer array RedString                // And this is the the &quot;redness&quot; in all hex-codes <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" />
        private integer array GreenString              // And this is the the &quot;greenness&quot; in all hex-codes <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" />
        private integer array BlueString               // And this is the the &quot;blueness&quot; in all hex-codes <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" />
        
        private string array PlayerColor               // This is used to keep track of which player-color is used by which player <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" />
        private string array PlayerColorString         // And this is the same thing, but not bound to a player <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        private string array PlayerColorWord           // This is used to keep track of which player-color-string (Like &quot;red&quot;, or &quot;teal&quot;) is used by which player <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" />
        private string array PlayerColorWordString     // And, yet again, this is the same thing, but not bound to a player <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        
        private player array StoredPlayers
    endglobals
    
    function PlayerColoredStringById takes integer playerId, string coloredString returns string
        return PlayerColor[playerId] + coloredString + EndString
    endfunction
    
    function PlayerColoredString takes player p, string coloredString returns string
        return PlayerColor[GetPlayerId( p )] + coloredString + EndString
    endfunction
    
    function GetPlayerNameColored takes player p returns string
        return PlayerColor[GetPlayerId( p )] + GetPlayerName( p ) + EndString
    endfunction
    
    function PlayerColoredTextTag takes texttag coloredTag, player p, integer alpha returns nothing
        local integer id
        
        if p != null then // We don&#039;t want to use a &#039;null&#039; player, do we ? <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite9" alt=":eek:" title="Eek!    :eek:" loading="lazy" data-shortname=":eek:" />
            set id = GetPlayerId( p ) // Gets the id of the inputted player
            call SetTextTagColor( coloredTag, Red[id], Green[id], Blue[id], alpha ) // Setting the color of the used texttag to the specified player&#039;s color
        endif

    endfunction
    
    function PlayerColoredTextTagById takes texttag coloredTag, integer playerId, integer alpha returns nothing
        call SetTextTagColor( coloredTag, Red[playerId], Green[playerId], Blue[playerId], alpha ) // Simply sets the color of the texttag to the wanted player&#039;s one <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
    endfunction
    
    function GetPlayerColorString takes player p returns string
        return PlayerColor[GetPlayerId( p )]
    endfunction
    
    function GetPlayerColorStringById takes integer playerId returns string
        return PlayerColor[playerId]
    endfunction
    
    function GetPlayerByColor takes string color returns player
        return StoredPlayers[ StringHash( color ) / 20000000 + 96 ]
    endfunction
    
    function GetPlayerColorStringByColor takes string color returns string
        return PlayerColor[ GetPlayerId( StoredPlayers[ StringHash( color ) / 20000000 + 96 ] ) ]
    endfunction
    
    private function OnColorChange takes player whichPlayer, playercolor color returns nothing
        local integer id = GetPlayerId( whichPlayer )
        local integer pc = GetHandleId( color )

        set PlayerColor[id] = PlayerColorString[pc]
        set Red[id] = RedString[pc]
        set Green[id] = GreenString[pc]
        set Blue[id] = BlueString[pc]
        set PlayerColorWord[id] = PlayerColorWordString[pc]
        set StoredPlayers[ StringHash( PlayerColorWordString[ pc ] ) / 20000000 + 96 ] = whichPlayer
    endfunction
    
    hook SetPlayerColor OnColorChange
    
    private function Init takes nothing returns nothing
        local integer i = 12
        local integer i2
    
        set PlayerColorString[0] = &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   
            
            set StoredPlayers[ StringHash( PlayerColorWordString[ i ] ) / 20000000 + 96 ] = Player( i )
            set i2 = GetHandleId( GetPlayerColor( Player( i ) ) )
            set PlayerColor<i> = PlayerColorString[ i2 ]
            set Red[ i ] = RedString[ i2 ]
            set Green[ i ] = GreenString[ i2 ]
            set Blue[ i ] = BlueString[ i2 ]
            set PlayerColorWord[ i ] = PlayerColorWordString[ i ]
            
            set i = i - 1
        endloop
        
        set StoredPlayers[ StringHash( PlayerColorWordString[ 13 ] ) / 20000000 + 96 ] = Player( 8 )
        set StoredPlayers[ StringHash( PlayerColorWordString[ 14 ] ) / 20000000 + 96 ] = Player( 2 )
        set StoredPlayers[ StringHash( PlayerColorWordString[ 15 ] ) / 20000000 + 96 ] = Player( 2 )
        set StoredPlayers[ StringHash( PlayerColorWordString[ 16 ] ) / 20000000 + 96 ] = Player( 12 )
        set StoredPlayers[ StringHash( PlayerColorWordString[ 17 ] ) / 20000000 + 96 ] = Player( 12 )
    endfunction
    
endlibrary</i>


And here are two small examples of use :D

JASS:
scope PlayerColorExamples initializer Init

    private function TimerActions takes nothing returns nothing
        local player p = Player( 0 )
        // The player we&#039;ll be using to show the message for/getting the color of <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" />
        
        call DisplayTextToPlayer( p, 0.0, 0.0, PlayerColoredString( p, &quot;This is how your color looks <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />&quot; ) )
        // This is how it would look using the &quot;PlayerColoredStringById&quot; function:
        call DisplayTextToPlayer( p, 0.0, 0.0, PlayerColoredStringById( GetPlayerId( p ), &quot;This is how your color looks <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />&quot; ) )
        // Remember ! You have to use &quot;JASS&quot; player-ids, ranging from 0 to 11 (Not including Neutrals), not GUI numbers (1 - 12) <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        
        // These two functions will display that text in the color of Player( 0 )... RED ! <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" />
        
        set p = null
        // Just some leak-cleaning <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
    endfunction
    
    private function DeathActions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        // Just getting the dying unit here <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        local player p = GetOwningPlayer( u )
        // And the owner of it <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" />
        local texttag tt = CreateTextTag()
        // And a texttag for some texting <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" />
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        // Just so we know ehere he is <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        
        call SetTextTagPos( tt, x, y, 20. ) // Putting the texttag on the unit
        call SetTextTagPermanent( tt, true )
        call SetTextTagText( tt, &quot;This is where your unit died !&quot;, 0.023 ) // Setting the text of it, and size (That number is the standard &quot;10&quot; in GUI ;D)
        call PlayerColoredTextTag( tt, p, 200 )
        
        // You can use &quot;ById&quot; here too... <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
        
        // Ok, so this whole thing will create a texttag (Floating Text in GUI) and set it&#039;s position on the dying unit (With a height of 20.).
        // It will be permanent, and will read &quot;This is where your unit dies !&quot; with the standard GUI size of 10 <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 it will also be colored in the owner of the unit&#039;s color <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" />
        
        set u = null
        set p = null
        set tt = null
        
        // Leak-cleaning ftw ! <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" />
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        // Just creating the trigger to register the event for <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" />
        
        call TriggerRegisterTimerEvent( t, 1.0, false )
        
        // Registering a &quot;meaningless&quot; event (By meaningless, I mean it&#039;s just a stupid example this one XD)
        
        call TriggerAddAction( t, function TimerActions )
        
        // And now we&#039;re adding the function which is to be run when the event occurs <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" />
        
        set t = CreateTrigger()
        
        // Yet another trigger <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
        
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
        
        // Registering when a unit dies !
        
        call TriggerAddAction( t, function DeathActions )
        
        // And adding another action <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink    ;)" loading="lazy" data-shortname=";)" />
    endfunction
    
endscope


Please, come with ideas of more features for this, and I'll consider adding them ;)
(If they're worth it, that is :p)
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
sorry but i think its shorter to type out the code that String2PlayerColouredString() cant you make it a shorter function name like S2PCS or something
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah... It's probably too long XD
It was just very self explanatory...

EDIT: Ok, changed now, and also added a description :D
 
Reaction score
341
GetPlayerColorString would be better. And it should just be this;

JASS:
function GetPlayerColorString takes player p returns string
    return PlayerColor[GetPlayerId(p)]
endfunction

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

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, ok then...
But can't I keep my function too ? :eek:
And just implement that also ? :S
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Let's pretend that I'm not in direct competition with you for a second. :p

Don't use static indicies here. Players can be in slot one and take green as their player color.

I'd use this:
JASS:
    local string array playerColorStr
    local string array playerColors

    set playerColorStr[0] = &quot;|cffff0303&quot;
    set playerColorStr[1] = &quot;|cff0042ff&quot;
    set playerColorStr[2] = &quot;|cff1ce6b9&quot;
    set playerColorStr[3] = &quot;|cff540081&quot;
    set playerColorStr[4] = &quot;|cfffffc01&quot;
    set playerColorStr[5] = &quot;|cfffeba0e&quot;
    set playerColorStr[6] = &quot;|cff20c000&quot;
    set playerColorStr[7] = &quot;|cffr55bb0&quot;
    set playerColorStr[8] = &quot;|cff959697&quot;
    set playerColorStr[9] = &quot;|cff7ebff1&quot;
    set playerColorStr[10] = &quot;|cff107246&quot;
    set playerColorStr[11] = &quot;|cff4e2a04&quot;
    
    loop
        exitwhen i &gt;= 12
        set playerColors<i> = PlayerColorStr[ GetHandleId( GetPlayerColor(Player(i)) ) ]
        set i = i + 1
    endloop
</i>



best wishes, Davey


*I changed the code he posted so it would fit your system better*

Basically, he showed me a really good way of setting up the colors so that if a player in slot 1 would not have green text when he actually chose the color green.

The biggest problem is that the GetHandleId function is not compatible with pre-patch 1.24.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Sorry, but I don't understand what you mean by:
Basically, he showed me a really good way of setting up the colors so that if a player in slot 1 would not have green text when he actually chose the color green.

Sorry :(

My snippet works fine...
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
I meant to say:

Basically, he showed me a really good way of setting up the colors so that a player in slot 1 would not have red text when he actually chose the color green.

Some games do not have locked colors, and during the Waiting for Players screen, you can change your color. However, your system defaults to player 1 = red, player 2 = blue... etc.

You can check what color a player is, by using GetPlayerColor with GetHandleId.

GetPlayerColor with default colors will return: for Player 1, Red. Using GetHandleId on this will return 0. However, if Player 1 changes his color to green before the game starts, it will actually return: . Using GetHandleId on this returns 6. However, with the way your system currently is, the game will only display red text for Player 1, Green.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Oh, ok ... Sure, I'll do that then :D
So no globals then ? :S
I'll just do that for both of the functions TriggerHappy gave me ? :eek:
 

Komaqtion

You can change this now in User CP.
Reaction score
469
But it's inside the "Init" dunction, so will only be called once... Right ? :S
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, then... Updated, though don't know if that's how you wanted it to look :S
 

Azlier

Old World Ghost
Reaction score
461
You could get the tiniest of efficiency gains, Darthfett, by saving all the players to a player array.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok then... But, then I would only need one of those globals, right ? :S
I can remove the "playerColorStr" one, and replace it with "PlayerColor" only ? :S

Looks like this now, and seems to work :D

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 string array PlayerColor
    private constant string EndColor = &quot;|r&quot;
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
    
    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
 
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