• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Floating Text

Status
Not open for further replies.
Level 12
Joined
Oct 16, 2010
Messages
680
Not too familiar with FT's so I don't really know why is it never appears in the game

the trigger works just fine, only the FT drives me crazy

JASS:
public function GetDamageCalc takes unit tu,unit au, real d returns real
    local real cd
    local texttag tt
    local integer x = 0
    local integer y = 0
    local real c = 1
    set tt = CreateTextTag()
    call SetTextTagVisibility(tt,true)
    call SetTextTagPermanent(tt,false)
    call SetTextTagLifespan(tt,1.5)
    call SetTextTagFadepoint(tt,1.0)
    call SetTextTagVelocity(tt,0.5,0)
    call SetTextTagAge(tt,1.5)
    call SetTextTagPosUnit(tt,tu,30.0)
    //---------------------------------PLAYER VS. MOB---------------------------------------
    if GetOwningPlayer(tu) == Player(11) then
    loop
        exitwhen GetPlayerName(Player(x)) == GetPlayerName(GetOwningPlayer(au))
        set x = x + 1
    endloop
        if GetUnitLevel(tu) == GetUnitLevel(au) then
            set cd = udg_DamageEventPrevAmt*(1+(HStat[x*10+1]/10*GetUnitLevel(au)))
                if GetRandomInt(0,100)<HStat[x*10+4] then
                    set cd = cd * 2
                    set c = 1.8
                endif
                call DisplayTimedTextToPlayer(Player(0),0,0,20,"hero damage mob")
                call SetTextTagText(tt,R2S(cd),0.03*c)
        elseif GetUnitLevel(tu) > GetUnitLevel(au) then
            set cd = (udg_DamageEventPrevAmt*(1-((GetUnitLevel(tu)-GetUnitLevel(au))*0.1)))*(1+(HStat[x*10+1]/10*GetUnitLevel(au)))
            if (GetRandomInt(1,100)+Pow(GetUnitLevel(tu)-GetUnitLevel(au),2.0)) > 100 then
                set cd = 0
            endif
            if cd == 0 then
            call DisplayTimedTextToPlayer(Player(0),0,0,20,"hero miss to mob")
                call SetTextTagText(tt,"Miss!",0.03*c)
            else
                if GetRandomInt(0,100)<HStat[x*10+4] then
                    set cd = cd * 2
                    set c = 1.8
                endif 
                call DisplayTimedTextToPlayer(Player(0),0,0,20,"hero damage mob")
                call SetTextTagText(tt,R2S(cd),0.03*c)
            endif
        else
            set cd = (udg_DamageEventPrevAmt*(1+((GetUnitLevel(au)-GetUnitLevel(tu))*0.05)))*(1+(HStat[x*10+1]/10*GetUnitLevel(au)))
            if GetRandomInt(0,100)<HStat[x*10+4] then
                set cd = cd * 2
                set c = 1.8
            endif
            call DisplayTimedTextToPlayer(Player(0),0,0,20,"hero damage mob")
            call SetTextTagText(tt,R2S(cd),0.03*c)
        endif    
        //---------------------------------MOB VS. PLAYER---------------------------------------
    elseif GetOwningPlayer(au) == Player(11) then
        loop
            exitwhen GetPlayerName(Player(y)) == GetPlayerName(GetOwningPlayer(tu))
            set y = y + 1
        endloop
        if GetUnitLevel(tu) == GetUnitLevel(au) then
            set cd = udg_DamageEventPrevAmt*(1-(HStat[y*10+3]/100*GetUnitLevel(tu)))
                if GetRandomInt(0,100)<10 then
                    set cd = cd * 2
                    set c = 1.8
                endif
                call DisplayTimedTextToPlayer(Player(0),0,0,20,"mob damage hero")
                call SetTextTagText(tt,R2S(cd),0.03*c)
        elseif GetUnitLevel(tu) > GetUnitLevel(au) then
            set cd = (udg_DamageEventPrevAmt*(1-((GetUnitLevel(tu)-GetUnitLevel(au))*0.1)))*(1-(HStat[y*10+3]/100*GetUnitLevel(tu)))
            if (GetRandomInt(1,100)+Pow(GetUnitLevel(tu)-GetUnitLevel(au),2.0)) > 100 then
                set cd = 0
            endif
            if cd == 0 then
                call DisplayTimedTextToPlayer(Player(0),0,0,20,"mob miss hero")
                call SetTextTagText(tt,"Miss!",0.03*c)
            else
                if GetRandomInt(0,100)<10 then
                    set cd = cd * 2
                    set c = 1.8
                endif
                call DisplayTimedTextToPlayer(Player(0),0,0,20,"mob damage hero")
                call SetTextTagText(tt,R2S(cd),0.03*c)
            endif
        else   
            set cd = (udg_DamageEventPrevAmt*(1+((GetUnitLevel(au)-GetUnitLevel(tu))*0.05)))*(1-(HStat[y*10+3]/100*GetUnitLevel(tu)))
            if GetRandomInt(0,100)<10 then
                set cd = cd * 2
                set c = 1.8
            endif
            call DisplayTimedTextToPlayer(Player(0),0,0,20,"mob damage hero")
            call SetTextTagText(tt,R2S(cd),0.03*c)
        endif
        //---------------------------------PLAYER VS. PLAYER---------------------------------------
    else    
        loop
            exitwhen GetPlayerName(Player(y)) == GetPlayerName(GetOwningPlayer(tu))
            set y = y + 1
        endloop
        if GetUnitLevel(tu) == GetUnitLevel(au) then
            set cd = (udg_DamageEventPrevAmt*(1+(HStat[x*10+1]/10*GetUnitLevel(au))))*(1-(HStat[y*10+3]/100*GetUnitLevel(tu)))
            if GetRandomInt(0,100)<HStat[x*10+4] then
                    set cd = cd * 2
                    set c = 1.8
                endif
                call DisplayTimedTextToPlayer(Player(0),0,0,20,"hero damage hero")
                call SetTextTagText(tt,R2S(cd),0.03*c)
        elseif GetUnitLevel(tu) > GetUnitLevel(au) then
            set cd = ((udg_DamageEventPrevAmt*(1-((GetUnitLevel(tu)-GetUnitLevel(au))*0.1)))*HStat[x*10+1]/10*GetUnitLevel(au))*(1-(HStat[y*10+3]/100*GetUnitLevel(tu)))
            if (GetRandomInt(1,100)+Pow(GetUnitLevel(tu)-GetUnitLevel(au),2.0)) > 100 then
                set cd = 0
            endif
            if cd == 0 then
                call DisplayTimedTextToPlayer(Player(0),0,0,20,"hero miss to hero")
                call SetTextTagText(tt,"Miss!",0.03*c)
            else
                if GetRandomInt(0,100)<HStat[x*10+4] then
                    set cd = cd * 2
                    set c = 1.8
                endif
                call DisplayTimedTextToPlayer(Player(0),0,0,20,"hero damage hero")
                call SetTextTagText(tt,R2S(cd),0.03*c)
            endif
        else
            set cd = ((udg_DamageEventPrevAmt*(1+((GetUnitLevel(au)-GetUnitLevel(tu))*0.05)))*HStat[x*10+1]/10*GetUnitLevel(au))*(1-(HStat[y*10+3]/100*GetUnitLevel(tu)))
            if GetRandomInt(0,100)<HStat[x*10+4] then
                set cd = cd * 2
                set c = 1.8
            endif 
            call DisplayTimedTextToPlayer(Player(0),0,0,20,"hero damage hero")
            call SetTextTagText(tt,R2S(cd),0.03*c)
        endif
    endif
    return cd
endfunction
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Just a thought :

JASS:
call SetTextTagLifespan(tt,1.5)
call SetTextTagAge(tt,1.5)

Doesn't it make instantly the texttag enough "aged" to be destroyed ?
Check the GUI functions (i can't remember how handle a texttag properly).

Also display the id of the created textag (GetHandleId), if the value is 0, then you have reached the hardcoded limit of 100 texttags.

Btw texttags can safely be created in a local block (GetLocalPlayer).
That means if a texttag should be visible only for player X, then create it only for him.
This way you will reach this limit later or even never.

Some people tell to care about strings (use them before the local block to avoid a desync with the string table, all players have the same string table).
But personnaly i've already used them in a local block, all i can say is at least it doesn't desync instantly, and i don't see how it would desync, even later, since some strings are already locals by nature (different wc3 languages).
For example GetObjectName returns a local string if you don't have changed the default name of the object, but thet are also the string used by the game, such when a victory/defeat occurs, ...

But i suppose there is nothing wrong to be paranoid with jass, moar safety is always good.
 
Level 12
Joined
Oct 16, 2010
Messages
680
thanks a lot for u guys hope this will work properly without desyncs

JASS:
local texttag tt2 = null
    local integer x = 0
    local integer y = 0
    local real c = 1
    if GetLocalPlayer() == GetOwningPlayer(au) then
        set tt2 = CreateTextTag()
    endif
    if GetLocalPlayer() == GetOwningPlayer(tu) then
        set tt2 = CreateTextTag()
        call SetTextTagColor(tt2,150,10,10,255)
    endif
 
Level 12
Joined
Oct 16, 2010
Messages
680
It will. there is the rest of the script too like in the first post.I was just too lazy to copy all of it:D

just one more question. How can i destroy the texttag properly?

if i use simple call DestroyTextTag(tt) at the bottom of the script , the texttag won't be visible enough time to be able to recognize
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
If it's a static time (known as since it's created) you can simply use SetTextTagLifespan(tt,duration), where tt == your textag, and duration a real in second.

If you need more control you can make it permanent and destroy when needed.
 
Status
Not open for further replies.
Top