Help with floating text

Status
Not open for further replies.
Level 3
Joined
Sep 9, 2009
Messages
658
I'm using a damage detector so I can show damage as floating text. However, I want the color of the text to match the damaging player's color. But this is the only function I know which can set color to floating text. Is there a way I can link player color to floating text? My map will have players change colors often.

JASS:
native SetTextTagColor takes texttag t, integer red, integer green, integer blue, integer alpha returns nothing
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
You could create integer array variables for each player, e.g. Red[1] = 255, Green[1] = 0, Blue[1] = 0 which mean player 1's color is 255 red, 0 green, 0 blue. Do the same for other players, then on your floating text, do something like this:
local integer id = GetPlayerId(player) + 1
call SetTextTagColor(t, Red[id], Green[id], Blue[id], 255)
You can also just use the 0 index for player 1 so that you don't have to +1 on the id. Choose what you prefer.
 

Ardenian

A

Ardenian

So if I understand correctly, the array would be for the colors? So I'll have 12 arrays for each color?

(You have one variable with an array for a real value for one color )x 3.

-> 3 different variables for all color tones.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
You can have 3 real arays[] ; red[], green[], blue[] and use the player number as index.

Just for example for player 1:

Init trigger:
  • Set red[1] = 255.00
  • Set green[1] = 0
  • Ser blue[1] = 0
^ Would be red only.

And then you change colours then you need to adabt the colour values of course.

Edit: Flux:)


Why real type and not integer??

@OP, btw, if you know the color tag (e.g. |cffff0000) of players, you can also know how much redness, greeness, blueness there is. Just convert the hexadecimal into decimal.
The first hexadecimal after '|c' refers to alpha. Then red, then green then blue.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
Ahh I phrased my question wrong. What I mean was would the script be something like this?

  • Set Red[1] = 255
  • Set Red[2] = 128
  • Set Red[3] = 64
  • Set Green[1] = 255
  • Set Green[2] = 128
  • Set Green[3] = 64
  • Set Blue[1] = 255
  • Set Blue[2] = 128
  • Set Blue[3] = 64
etc?

Correct, if you have 12 players, that's a total of 36 initialized variables. I suggest grouping them like this
Red[1]
Green[1]
Blue[1]
Red[2]
Green[2]
...

And why are your values wrong? Player 1 should be Red and Player 2 should be Blue.
 
Level 3
Joined
Sep 9, 2009
Messages
658
Oh that's just an example. I'm looking up the correct values now.

EDIT: Btw...what do you mean by local integer id = GetPlayerId(player)? I keep getting an error with it.

I got the script to work but player 1 has red floating text even though player 1 is changed to purple at initialization. Is there another way to check for actual player color?
 
Last edited by a moderator:
Level 15
Joined
Oct 29, 2012
Messages
1,474
Open up Magos' model editor and go to Text Colourer option (Misc)

when you click on any colour, RedGreenBlue values will show up to the right of the new window.

You can use this online tool for fast converting : Colour RGB Picker

There is a little problem... In the GUI function, Colours' RGB values are used as "percentage"... so 100% = 255

If you have another value rather than 255 (Let's assume it's R=75, G=75, B=75); We have to convert this into a percentage value, all you have to do is divide 75 by 2.55...
SO we get ( R=29, G=29, B=29 )... I don't know if the jass function deals with percentage too.

Cheerz
 
Level 3
Joined
Sep 9, 2009
Messages
658
^I don't feel you are reading carefuly what people suggest here and don't try hard enough yourself.

With player color comparison you obviosly can compare the color of a player with an other color.

Um...riiight >_>

What I mean is...I need colored floating text not based on player number but actual player colors. So if used trigger to change Player 1's color to green midgame, I want the change to reflect in the floating text.

Now, your suggestion confused me since GetPlayerColor() returns player color but from what the suggestions here are saying, I need to use arrays. So how do I translate GetPlayerColor() into a number?

Here's the script so far...
JASS:
scope DamageText initializer Init
    globals
        private constant integer array Red[]
        private constant integer array Green[]
        private constant integer array Blue[]
    endglobals
    
    private function Actions takes nothing returns nothing
        local texttag tt = CreateTextTag()
        local integer id = GetPlayerId(GetOwningPlayer(udg_DamageEventSource)) + 1
        
        //---Player 1---\\
        set Red[1] = 255
        set Green[1] = 3
        set Blue[1] = 3
        //---Player 2---\\
        set Red[2] = 0
        set Green[2] = 66
        set Blue[2] = 255
        //---Player 3---\\
        set Red[3] = 28
        set Green[3] = 230
        set Blue[3] = 185
        //---Player 4---\\
        set Red[4] = 84
        set Green[4] = 0
        set Blue[4] = 129
        //---Player 5---\\
        set Red[5] = 255
        set Green[5] = 252
        set Blue[5] = 1
        //---Player 6---\\
        set Red[6] = 254
        set Green[6] = 186
        set Blue[6] = 14
        //---Player 7---\\
        set Red[7] = 32
        set Green[7] = 192
        set Blue[7] = 0
        //---Player 8---\\
        set Red[8] = 229
        set Green[8] = 91
        set Blue[8] = 176
        //---Player 9---\\
        set Red[9] = 149
        set Green[9] = 150
        set Blue[9] = 151
        //---Player 10---\\
        set Red[10] = 126
        set Green[10] = 191
        set Blue[10] = 241
        //---Player 11---\\
        set Red[11] = 16
        set Green[11] = 98
        set Blue[11] = 70
        //---Player 12---\\
        set Red[12] = 78
        set Green[12] = 42
        set Blue[12] = 4
        //---Player 13---\\
        set Red[13] = 255
        set Green[13] = 255
        set Blue[13] = 255
        //---Player 14---\\
        set Red[14] = 255
        set Green[14] = 255
        set Blue[14] = 255
        
        call SetTextTagText(tt, I2S(R2I(udg_DamageEventAmount)), 0.023)
        call SetTextTagPosUnit(tt, udg_DamageEventTarget, 50.00)
        call SetTextTagColor(tt, Red[id], Green[id], Blue[id], 255)
        call SetTextTagVelocityBJ(tt, 75.0, 90)
        call SetTextTagPermanent(tt, false)
        call SetTextTagLifespan(tt, 5.0)
        call SetTextTagFadepoint(tt, 4.0)
        
        set tt = null
    endfunction

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterVariableEvent( t, "udg_DamageEvent", EQUAL, 1.00 )
        call TriggerAddAction( t, function Actions )
        set t = null
    endfunction
endscope
 
Okay, I got ya.

So let's assume these are your default values for player colours 1-14.
JASS:
//---Player 1---\\
        set Red[1] = 255
        set Green[1] = 3
        set Blue[1] = 3
        //---Player 2---\\
        set Red[2] = 0
        set Green[2] = 66
        set Blue[2] = 255
        //---Player 3---\\
        set Red[3] = 28
        set Green[3] = 230
        set Blue[3] = 185
        //---Player 4---\\
        set Red[4] = 84
        set Green[4] = 0
        set Blue[4] = 129
        //---Player 5---\\
        set Red[5] = 255
        set Green[5] = 252
        set Blue[5] = 1
        //---Player 6---\\
        set Red[6] = 254
        set Green[6] = 186
        set Blue[6] = 14
        //---Player 7---\\
        set Red[7] = 32
        set Green[7] = 192
        set Blue[7] = 0
        //---Player 8---\\
        set Red[8] = 229
        set Green[8] = 91
        set Blue[8] = 176
        //---Player 9---\\
        set Red[9] = 149
        set Green[9] = 150
        set Blue[9] = 151
        //---Player 10---\\
        set Red[10] = 126
        set Green[10] = 191
        set Blue[10] = 241
        //---Player 11---\\
        set Red[11] = 16
        set Green[11] = 98
        set Blue[11] = 70
        //---Player 12---\\
        set Red[12] = 78
        set Green[12] = 42
        set Blue[12] = 4
        //---Player 13---\\
        set Red[13] = 255
        set Green[13] = 255
        set Blue[13] = 255
        //---Player 14---\\
        set Red[14] = 255
        set Green[14] = 255
        set Blue[14] = 255

OnChange you simply can do something like, example:

Assume for example Player 1 types "-colour 7" to get green and this is the function trigger:
JASS:
function ColourSwitch takes nothing returns nothing
    local integer i = GetPlayerId(GetTriggerPlayer())
    set PlayerRed[i] = Red[colour_int]
    set PlayerGreen[i] = Green[colour_int]
    set PlayerBlue[i] = Blue[colour_int]
    // colour_int should be the converted substring to integer in this case , = 7
endfunction
So you see now, we have 3 new arrays int variable which represent the actual/current colour for the player, not the default ones:

PlayerRed[]
PlayerGreen[]
PlayerBlue[]

Then when you create a text you use these ones instead of default ones Red[], Green[], Blue[].
 
Status
Not open for further replies.
Top