• 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.

Need help creating trigger for checking number of alive units

Status
Not open for further replies.
Level 7
Joined
Dec 5, 2013
Messages
280
I need trigger for boss checking number of alive units when enemies enter region.

Boss should summon 8 units, I have custom summon skeleton item. The number of summoned units should drop by 2 for each destroyed "towers". There are 4 towers in total.
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
One way is to do it like this:
  • Untitled Trigger 001
    • Events
      • Unit - Scout Tower 0000 <gen> Dies
      • Unit - Scout Tower 0001 <gen> Dies
      • Unit - Scout Tower 0002 <gen> Dies
      • Unit - Scout Tower 0003 <gen> Dies
    • Conditions
    • Actions
      • Set Alive_Towers = (Alive_Towers - 1)
with "Alive_Towers" being an integer variable that starts with value 4.
Then you just check the number in there.

Other options is to count all alive towers using unit group
  • Untitled Trigger 001
    • Events
      • Unit - A unit enters Region 000 <gen>
    • Conditions
    • Actions
      • Set group = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Scout Tower) and (((Matching unit) is alive) Equal to True)))
      • Set Alive_Towers = (Number of units in group)
      • Custom script: call DestroyGroup(udg_group)
Alive_Towers is integer variable, "group" is unit group variable.
You don't even need "Alive_Towers" variable in this trigger, I just used it to show how to get number of units in group.
 
Level 7
Joined
Dec 5, 2013
Messages
280
Boss still summons 8 units even though only 3/4 towers are alive. It shouldnt use the 8 unit item but instead 6 unit item which is separate item.
 
Level 7
Joined
Dec 5, 2013
Messages
280
  • Unit - A unit enters region
  • Triggering unit belongs to an enemy of player 1
  • alive towers equal to 4
  • hero - summon treant and give it to boss
  • hero - order boss to use last created item
That trigger still activates even if 3/4 towers are alive
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
Yes, but you need another trigger, for example the first one I posted in post #2, where when specific unit dies, an action "Set alive towers = alive towers -1" is used.

Else if you don't decrease the value "alive towers", it will still be 4, no matter how many towers are destroyed.
 
Level 7
Joined
Dec 5, 2013
Messages
280
The trigger is 100% identical to trigger in this thread

I managed to get it work with number of living units owned by player

But how to stop trigger looping? it continues to give the item as long as unit is in the region.
 
Last edited by a moderator:
Status
Not open for further replies.
Top