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

[Trigger] [Solved] Unit Indexer MUI

Status
Not open for further replies.
Level 6
Joined
Jul 12, 2021
Messages
95
I have two triggers:

  • Trigger 1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Howl of Terror (Skeleton Magi)
    • Actions
      • Unit Group - Pick every unit in (Units within 750.00 of (Position of (Triggering unit)) matching ((((Matching player) is an ally of (Owner of (Triggering unit)).) Not equal to True) and ((Owner of (Matching unit)) Not equal to (Owner of (Triggering unit)))).) and do (Actions)
        • Loop - Actions
          • Unit - Cause (Triggering unit) to damage (Picked unit), dealing 10.00 damage of attack type Spells and damage type Normal
          • Set VariableSet HowlOfTerrorInteger[(Custom value of (Picked unit))] = 15
          • Unit Group - Add (Picked unit) to HowlOfTerrorUnitGroup
          • Trigger - Turn on Untitled Trigger 00 <gen>
  • Trigger 2
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in HowlOfTerrorUnitGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet HowlOfTerrorInteger[(Custom value of (Picked unit))] = (HowlOfTerrorInteger[(Custom value of (Picked unit))] - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HowlOfTerrorInteger[(Custom value of (Picked unit))] Greater than or equal to 1
            • Then - Actions
              • Unit - Cause (Triggering unit) to damage (Picked unit), dealing 10.00 damage of attack type Spells and damage type Normal
            • Else - Actions
              • Unit Group - Remove (Picked unit) from HowlOfTerrorUnitGroup.
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in HowlOfTerrorUnitGroup) Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
There's an error in Trigger 2; triggering unit does not exist. The trigger I want to do is MUI. What can I do to make the triggering unit of Trigger 1 to be the unit causing damage in Trigger 2?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,516
See how you set HowlOfTerrorInteger to 15 for each Picked unit? You can also keep track of the Unit that cast Howl of Terror using the same method.

Create a new Unit array variable, let's call it HowlOfTerrorCaster, and Set it like so:
  • Set Variable HowlOfTerrorInteger[(Custom value of (Picked unit))] = 15
  • Set Variable HowlOfTerrorCaster[(Custom value of (Picked unit))] = Triggering unit

Now you have a reference to the unit that cast Howl of Terror, so when it comes time to dealing damage:
  • Unit - Cause HowlOfTerrorCaster[(Custom value of (Picked unit))] to damage (Picked unit), dealing 10.00 damage of attack type Spells and damage type Normal

Also, make sure that you're turning on the correct trigger:
  • Trigger - Turn on Untitled Trigger 00 <gen>
 
Last edited:
Level 6
Joined
Jul 12, 2021
Messages
95
Thank you!

I have one more question. Trigger 2 causes damage every 1 second of game time. This means the first tick of damage will happen in less than a second; it could even be 0.01 seconds. Is there a way to always have the first tick of damage 1 second after casting the spell?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,516
Just delete this line from the first trigger to delay the first damage tick:
  • Unit - Cause (Triggering unit) to damage (Picked unit), dealing 10.00 damage of attack type Spells and damage type Normal

But understand that exact precision is tough to achieve. You can use a smaller Periodic Interval, let's say every 0.04 seconds, and use an Integer array to keep track of this elapsed time. If this Integer reaches 25 (0.04*25 = 1.00) then we know a second has passed.

Using this technique will result in the periodic damage being dealt anywhere from 0.96 -> 1.04 seconds, but it's close enough to the desired goal. When using GUI you don't really have a choice but to be imprecise.
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,516
In Jass/Lua you can create timers. Each of these timers can be created and used exclusively for a single unit instead of how we do it in GUI with one timer for ALL of the units. You can also group multiple units to the same timer which would make the most sense for an Area of Effect ability like yours where every unit is added to the group at the same time, therefore they use the same timer interval.

So you'd do something like this:
Create a new timer each time you cast the ability, then create a unit group to store the nearby enemy units, and finally link that group to the newly created timer. This timer would then function similar to your Periodic Interval trigger above, handling what happens every period and eventually destroying itself once it's finished.

In Jass people use a system called TimerUtils to achieve this data linking effect with timers. Lua may not need such a system since it can create local functions and easily retain local data over time.

Then comes the question of how multiple casts of the ability and "stacking" work. I assume you want the ability to work like a standard Warcraft 3 ability. An example of what I mean: If I cast Acid Bomb on a group of enemies and then my ally casts Acid Bomb on the SAME group of enemies a second later, his Acid Bomb will replace mine. The buff duration gets reset, the stats of his Acid Bomb are applied, and his Alchemist becomes the new source of the damage.

If we're using the standard design then you would need to remove the enemy units from their previous Howl of Terror unit group whenever you cast the ability. This would prevent them from being affected by multiple instances of the same ability. In other words, it would prevent stacking effects.
 
Last edited:
Status
Not open for further replies.
Top