[Solved] Tracking Multiple Special Effects on units to remove when they die

Level 9
Joined
Mar 2, 2014
Messages
160
I have units in row to die one by one.
I would like create special effect on them like this:
  • Ensnare
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in Ensnared 1 <gen>) and do (Special Effect - Create a special effect at (Position of (Picked unit)) using Abilities\Spells\Orc\Ensnare\ensnareTarget.mdl)
Now when those units start dying one by one I want remove that special effect on them one by one.
Since I have red basically every tutorial on hive I know I have to make special effect array right?
Since those units will be dying in row I can just remove those effects one by one when units die? I can track which unit died by integer + 1 and then connect it to special effect variable?

Well I created speciall effect array variable, integer variable and everytime I try to continue my brain just freezes, any help would be appreciated.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
For starters, you want to use the Pick Every Unit action that has MULTIPLE actions. Always use the "Multiple" version if it exists.

That'll give you something like this:
  • Actions
    • Unit Group - Pick every unit in (Units in Ensnared 1 <gen>) and do (Actions)
      • Loop - Actions
Now you can add multiple Actions here giving you full control over what happens.

Using that let's introduce some Variables:
  • Ensnare
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Countdown Timer - Start Ensnare_Timer as a Repeating timer that will expire in 1.00 seconds
      • Set Variable Ensnare_Counter = 0
      • Unit Group - Pick every unit in (Units in Ensnared 1 <gen>) and do (Actions)
        • Loop - Actions
          • Special Effect - Create a special effect at (Position of (Picked unit)) using Abilities\Spells\Orc\Ensnare\ensnareTarget.mdl
          • Set Variable Ensnare_Counter = (Ensnare_Counter + 1)
          • Set Variable Ensnare_Sfx[Counter] = (Last created special effect)
          • Set Variable Ensnare_Target[Counter] = (Picked unit)
Ensnare_Counter = Integer
Ensnare_Sfx = Special Effect (array)
Ensnare_Target = Unit (array)
Ensnare_Timer = Timer

Then use another trigger to kill them one by one:
  • Events
    • Time - Ensnare_Timer expires
  • Conditions
  • Actions
    • Unit - Kill Ensnare_Target[Counter]
    • Special Effect - Destroy Ensnare_Sfx[Counter]
    • Set Variable Ensnare_Counter = (Ensnare_Counter - 1)
    • If all Conditions are True then do (Actions)
      • If - Conditions
        • Ensnare_Counter Equal to 0
      • Then - Actions
        • Countdown Timer - Pause Ensnare_Timer
      • Else - Actions

If that's not what you meant then I think you're interested in a concept called Unit Indexing. Here's an example:
You can attach Arrays to your Units using this system, which takes advantage of a special stat called Custom Value.

Also, you might want to use an attachment point for these Special Effects, like "origin".
 
Last edited:
Level 9
Joined
Mar 2, 2014
Messages
160
Thanks it worked, I simplifed it a bit since I did not mean kill them by trigger they will just die one by one as they will get run over by trolley xD

  • Ensnare
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set VariableSet Ensnare_counter = 0
      • Set VariableSet Remove_counter = 1
      • Unit Group - Pick every unit in (Units in Ensnared 1 <gen>) and do (Actions)
        • Loop - Actions
          • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Orc\Ensnare\ensnareTarget.mdl
          • Set VariableSet Ensnare_counter = (Ensnare_counter + 1)
          • Set VariableSet EnsnareSfx[Ensnare_counter] = (Last created special effect)
          • Set VariableSet Ensnare_Target[0] = (Picked unit)
  • Ensnare remove
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Special Effect - Destroy EnsnareSfx[Remove_counter]
      • Set VariableSet Remove_counter = (Remove_counter + 1)
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I see, if everything is being precisely "controlled" like during a cinematic then you can simplify it even further:
  • Ensnare
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in Ensnared 1 <gen>) and do (Actions)
        • Loop - Actions
          • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Orc\Ensnare\ensnareTarget.mdl
          • Set VariableSet Ensnare_counter = (Ensnare_counter + 1)
          • Set VariableSet EnsnareSfx[Ensnare_counter] = (Last created special effect)
      • Set VariableSet Ensnare_counter = 0
  • Ensnare remove
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set VariableSet Ensnare_counter= (Ensnare_counter + 1)
      • Special Effect - Destroy EnsnareSfx[Ensnare_counter]
But if you want 100% precision then I suggest using Unit Indexing.

It's basically the same concept just our Units already have a unique Number assigned to them that we can leverage:
  • Ensnare
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in Ensnared 1 <gen>) and do (Actions)
        • Loop - Actions
          • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Orc\Ensnare\ensnareTarget.mdl
          • Set VariableSet Ensnare_counter = (Custom value of (Picked unit))
          • Set VariableSet EnsnareSfx[Ensnare_counter] = (Last created special effect)
  • Ensnare remove
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set VariableSet Ensnare_counter= (Custom value of (Picked unit))
      • Special Effect - Destroy EnsnareSfx[Ensnare_counter]
You HAVE to paste the Unit Indexer trigger into your map, though. That's what handles the assigning of Custom Value which is what makes all of this work.
 
Last edited:
Top