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

[Trigger] Countdown on top of a unit's head

Status
Not open for further replies.
Level 6
Joined
Aug 30, 2005
Messages
161
i am updating an old map of mine that has a spell thats suppose to kill a unit within 60 seconds. it would display a countdown timer on top of the unit's head in a descending order. I thought of doing this with floating text, however, i am not sure on how to attack the floating text to the unit's head with triggers. Any thoughts on the matter? Thanks in advance.
 
Level 19
Joined
Feb 25, 2009
Messages
2,004
  • Start
    • Events
    • Conditions
    • Actions
      • Set timer = 60
      • Set target = (Unit)
      • Floating Text - Create floating text that reads (String(timer)) above target with Z offset 0.00, using font size 12.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Floating Text - Change (Last created floating text): Enable permanence
      • Set text = (Last created floating text)
      • Trigger - Turn on Timer <gen>
  • Timer
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set timer = (timer - 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • timer Equal to 0
        • Then - Actions
          • Unit - Kill target
          • Floating Text - Destroy text
          • Trigger - Turn off (This Trigger)
        • Else - Actions
 
Level 19
Joined
Feb 25, 2009
Messages
2,004
  • Start
    • Events
    • Conditions
    • Actions
      • Set timer = 60
      • Set target = (Unit)
      • Floating Text - Create floating text that reads (String(timer)) above target with Z offset 0.00, using font size 12.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Set text = (Last created floating text)
      • Trigger - Turn on Timer <gen>
  • Timer
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set timer = (timer - 1)
      • Floating Text - Change text of text to (String(timer)) using font size 12.00
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • timer Equal to 0
        • Then - Actions
          • Unit - Kill target
          • Floating Text - Destroy text
          • Trigger - Turn off (This trigger)
        • Else - Actions
 
Level 6
Joined
Aug 30, 2005
Messages
161
  • Start
    • Events
    • Conditions
    • Actions
      • Set timer = 60
      • Set target = (Unit)
      • Floating Text - Create floating text that reads (String(timer)) above target with Z offset 0.00, using font size 12.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Set text = (Last created floating text)
      • Trigger - Turn on Timer <gen>
  • Timer
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set timer = (timer - 1)
      • Floating Text - Change text of text to (String(timer)) using font size 12.00
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • timer Equal to 0
        • Then - Actions
          • Unit - Kill target
          • Floating Text - Destroy text
          • Trigger - Turn off (This trigger)
        • Else - Actions

That solves the issue of the text updating as time passes by but it doesn't remain attached to the unit's head. Like GhostThruster said, you need to keep destroying it and creating it, however, a unit doesn't take one step every 1 second, it takes at least 2 to 3 steps depending on the speed, thus leaving the floating text behind for at least 0.30 seconds making it seem choppy. Currently trying to find a solution.
 
Level 5
Joined
Jan 4, 2007
Messages
103
Either this:
  • Events
    • Unit - A unit Begins casting an ability
  • Conditions
    • (Ability being cast) Equal to Your Ability
  • Actions
    • Set Timer = 120
    • Set Unit = Targeted Unit of Ability Being Cast
    • Trigger - Turn on (Second Trigger)
Second trigger:
  • Events
    • Time - Every 0.50 seconds of game time
  • Conditions
  • Actions
    • Set Timer = (Timer - 1)
    • Floating Text - Create floating text that reads (String(Timer/2)) above (Unit) with Z offset 0.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency
    • Floating Text - Change (Last created floating text): Disable permanence
    • Floating Text - Change the lifespan of (Last created floating text) to 0.50 seconds
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Timer Equal to 0
      • Then - Actions
        • Unit - Kill (Unit)
        • Trigger - Turn off (This trigger)
      • Else - Actions
        • Do nothing
in the first the timer is 120 but it changes every 0.50 seconds and it's still 60. The text in the Floating Text is a Integer Converted to String with an Arthimetric Timer/2 because of the timer 120 not 60.

Or this, as Mortar said:

  • Events
    • Time - Every 0.50 seconds of game time
  • Conditions
  • Actions
    • Floating Text - Change the position of Text to (Unit) with Z offset 0.00
Hope it helps:)
 
Level 19
Joined
Feb 25, 2009
Messages
2,004
  • Start
    • Events
    • Conditions
    • Actions
      • Set timer = 60
      • Set target = (Unit)
      • Floating Text - Create floating text that reads (String(timer)) above target with Z offset 0.00, using font size 12.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Set text = (Last created floating text)
      • Trigger - Turn on Timer <gen>
  • Timer
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
  • set timer2 = (timer2 - 0.06)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Condition
      • timer2 Equal to 0.00
    • Then - Actions
      • Set timer = (timer - 1)
      • Set timer2 = 3.00
    • Else - Actions
    • Floating Text - Change text of text to (String(timer)) using font size 12.00
    • Floating Text - Change the position of text to target with Z offset 0.00
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • timer Equal to 0
      • Then - Actions
        • Unit - Kill target
        • Floating Text - Destroy text
        • Trigger - Turn off (This trigger)
      • Else - Actions
 
Here's your MUI version:
  • Countdown
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Countdown
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Target unit of ability being cast) is in CT_Group) Equal to False
        • Then - Actions
          • Set CT_When = 60.00
          • Unit Group - Add (Target unit of ability being cast) to CT_Group
          • Hashtable - Save CT_When as (Key ct) of (Key (Target unit of ability being cast)) in CT_Hash
          • Hashtable - Save 1.00 as (Key every) of (Key (Target unit of ability being cast)) in CT_Hash
          • Floating Text - Create floating text that reads <Empty String> above (Target unit of ability being cast) with Z offset 0.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 30.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Hashtable - Save Handle Of(Last created floating text) as (Key txt) of (Key (Target unit of ability being cast)) in CT_Hash
          • Trigger - Turn on Countdown 2 <gen>
        • Else - Actions
  • Countdown 2
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (CT_Group is empty) Equal to True
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Unit Group - Pick every unit in CT_Group and do (Actions)
            • Loop - Actions
              • Set CT_Duration = (Load (Key ct) of (Key (Picked unit)) from CT_Hash)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • CT_Duration Greater than 0.00
                • Then - Actions
                  • Set CT_T = (Load (Key txt) of (Key (Picked unit)) in CT_HashIf the label is not found, this function returns NULL.)
                  • Set CT_Every = (Load (Key every) of (Key (Picked unit)) from CT_Hash)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • CT_Every Greater than 0.00
                    • Then - Actions
                      • Hashtable - Save (CT_Every - 0.03) as (Key every) of (Key (Picked unit)) in CT_Hash
                    • Else - Actions
                      • Hashtable - Save 1.00 as (Key every) of (Key (Picked unit)) in CT_Hash
                      • Hashtable - Save (CT_Duration - 1.00) as (Key ct) of (Key (Picked unit)) in CT_Hash
                      • Floating Text - Change text of CT_T to (String((Integer(CT_Duration)))) using font size 10.00
                  • Custom script: call SetTextTagPos (udg_CT_T, GetUnitX (GetEnumUnit()) - 30 * Cos(0), GetUnitY (GetEnumUnit()) - 30 * Sin (0), 100)
                • Else - Actions
                  • Unit Group - Remove (Picked unit) from CT_Group
                  • Floating Text - Destroy (Load (Key txt) of (Key (Picked unit)) in CT_HashIf the label is not found, this function returns NULL.)
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in CT_Hash
                  • Unit - Kill (Picked unit)
 

Attachments

  • Death Countdown.w3x
    18.9 KB · Views: 45
Level 6
Joined
Aug 30, 2005
Messages
161
Here's your MUI version...

and we have a winner! Rep for everyone that helped!
I need to relearn everything once again and clean the mess of codes in my old map, thank you all for showing me the way.


EDIT: does it work the same if the ability is in an item ability instead of a hero ability?
EDIT: I also noticed that if you kill the unit while the countdown is still going it remains visible even after the unit is dead, can i set then a trigger that checks if the unit is dead to remove the timer?
 
Last edited:
Status
Not open for further replies.
Top