• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Detecting number of units hit with aoe ability

Status
Not open for further replies.
Level 2
Joined
May 19, 2017
Messages
7
Hi

I have an ability that is supposed to heal the caster a certain amount for each unit hit with the ability. How would I detect the number of units hit with the ability?
 
Level 13
Joined
Oct 12, 2016
Messages
769
Well, to put it simply:
  • Counting Units In Area
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Generic Area Spell
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Set TempGroup = (Units within 175.00 of TempPoint)
      • Set TempInt = 0
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked Unit) is A structure) Equal to False
            • Then - Actions
              • Set TempInt = (TempInt + 1)
            • Else - Actions
      • Custom script: call DestroyGroup(udg_TempGroup)
      • Custom script: call RemoveLocation(udg_TempPoint)
Something like this will count everything in a 175 diameter circle around the "TempPoint."
You can change the location of the TempPoint to "target point of ability being cast" if it's a point target spell.

"TempInt" at the end of that function is how many units are in that area.
I highly recommend adding more conditions to the if/then/else statement to limit what gets counted.
 
Last edited:
Level 2
Joined
May 19, 2017
Messages
7
I'm trying to understand, by looking at the trigger above, how this would work as I'm still mediocre at some of this stuff... so please bear with me.

How does it actually detect how many units are in the area though? I see that TempInt (I'm assuming is the number of units) is set to 0 originally, then you have a basic arithmetic action adding +1 to it. But how does it actually set it to the number of units?
 
Level 13
Joined
May 10, 2009
Messages
868
The action below creates a unit group and adds all units within a certain area at a specific point (TempPoint).
  • Set TempGroup = (Units within 175.00 of TempPoint)
Then, the following
  • Unit Group - Pick every unit in TempGroup and do (Actions)
...enumerates all units stored in that unit group; It loops through all units in it. However, we don't want to simply count all units that are in it. We just want to know which one is NOT a Structure. If so, we increment TempInt. Otherwise, nothing is done.

Also, Wark probably overlooked that condition as he is comparing the triggering unit, and it should have been Picked Unit instead.

  • ((Picked Unit) is A structure) Equal to False
In the end, he avoids leaks by destroying those values that are not needed anymore - Unit Group and Point.
 
Level 2
Joined
May 19, 2017
Messages
7
So since I want the ability to heal the caster for, say, 100 hp per unit picked, what variable do I reference to? Would it be the TempInt as in ((TempInt)x100)? And if this is true, then what's the +1 for on the TempInt? I think this is where I'm confused at.

Sorry for all the questions but since I will probably be using this setup again in the future I would like to understand how it works instead of just copying/pasting.

EDIT: Ok nevermind, I see what it's doing; it loops and if each picked unit is NOT a structure, it simply adds +1 to TempInt... that's where the number is coming from. Gotchya ;)

EDIT 2: It works great but it's including my hero as one of the units picked so I just need to add a condition or two, no biggie.

Thanks a ton for helping (and being patient), much appreciated. +Rep to you both!
 
Last edited:
Status
Not open for further replies.
Top