• 🏆 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!

[JASS] Fading Floating texts

Status
Not open for further replies.
Level 3
Joined
Nov 18, 2007
Messages
48
I made a shield skill that blocks x damage and shows with a floating text the % of the shield above the unit then disappears in the span of 2 seconds (until the unit is attacked or the shield skill is casted again), it works well for the most part, the problem is that I don't know how to tell when a floating text is destroyed.
I could Destroy/Create a floating text every time but it's wasteful, these are the things that work/do not work that I want.

Floating text when shield skill is cast = ✓
Floating text when shield skill is recast in less than 2 seconds = ✓
Floating text when unit takes damage in less than 2 seconds = ✓
Floating text when shield skill is recast after more than 2 seconds = X
Floating text when unit takes damage after more than 2 seconds = X

this is the part that happens when the skill is casted

JASS:
// i is the custom value of the unit
// all works well here
set udg_t[i]=CreateTextTag()
            call SetTextTagText(udg_t[i],I2S(R2I((udg_currentshield[id]/udg_maxshield)*100.0))+"%",0.035)
            call SetTextTagPosUnit(udg_t[i],udg_shieldunit,16)
            call SetTextTagColor(udg_t[i],255-(PercentTo255((udg_currentshield[id]/udg_maxshield)*100.0)/2),127+(PercentTo255((udg_currentshield[id]/udg_maxshield)*100.0)/2),127+(PercentTo255((udg_currentshield[id]/udg_maxshield)*100.0)/2),100)
            call SetTextTagVelocity(udg_t[i], 0, 0.01)
            call SetTextTagVisibility(udg_t[i],true)
            call SetTextTagFadepoint(udg_t[i],0.01)
            call SetTextTagLifespan(udg_t[i],2.0)
            call SetTextTagPermanent(udg_t[i],false)

A floating text appears when something I mentioned happens, I made it so that it starts vanishing as soon as it appears, and vanishes completely in 2 seconds.
The problem is that after the floating text disappears I don't know how to tell if it disappeared (so that I can create it again.

this is the part that happens when the skill is cast on an unit that already has the shield

JASS:
// i is the custom value of the unit
if udg_t[i]==null then // Doesn't work. Need this to be true when more than 2 seconds pass = floating text expired.
                set udg_t[i]=CreateTextTag()
                call SetTextTagVelocity(udg_t[i], 0, 0.01)
                call SetTextTagVisibility(udg_t[i],true)
                call SetTextTagFadepoint(udg_t[i],0.01)
                call SetTextTagLifespan(udg_t[i],2.0)
                call SetTextTagPermanent(udg_t[i],false)
endif
//stuff below this works well
            set udg_currentshield[i] = udg_currentshield[i] + udg_maxshield
            call SetTextTagText(udg_t[i],I2S(R2I((udg_currentshield[i]/udg_maxshield)*100.0))+"%",0.035)
            call SetTextTagPosUnit(udg_t[i],udg_shieldunit,16)
            call SetTextTagColor(udg_t[i],255-(PercentTo255((udg_currentshield[i]/udg_maxshield)*100.0)/2),127+(PercentTo255((udg_currentshield[i]/udg_maxshield)*100.0)/2),127+(PercentTo255((udg_currentshield[i]/udg_maxshield)*100.0)/2),100)
            call SetTextTagAge(udg_t[i],0.0)
 
Level 3
Joined
Nov 18, 2007
Messages
48
I guess that's it, I've made it so they are destroyed/created everytime and it works ok. However it seems a bit lacking that you can't get the age of a texttag or some other stuff.
 
Level 39
Joined
Feb 27, 2007
Messages
5,015
If you really want to reuse them you can still give them a fading age, but just don't disable their permanence. When the same unit casts again just set their current age to 0 (as if they were new), move them, and change their text. But that's not better than letting themselves auto-recycle.
 
Status
Not open for further replies.
Top