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

Open Gate when all units in region are dead?

Status
Not open for further replies.
Level 3
Joined
May 24, 2012
Messages
57
I want to create a dungeon trap where when you enter a room the gate closes behind you and enemies spawn and the gate only reopens after all the enemies that spawned are dead. How would I go about creating this? I tried creating a unit group but couldnt figure out how to get the # of units in that unit group, so then I tried to create a REAL variable value and -1 for each unit until it reaches 0 but that didnt work either. Thanks in advance
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
If you want to use a counter like that, use an integer. A real variable isn't good for such a thing.
It should still work, though.

  • Open Gate
    • Events
      • Unit - Unit1 Dies
      • Unit - Unit2 Dies
      • Unit - Unit3 Dies
      • Unit - Unit4 Dies
    • Conditions
    • Actions
      • Set UnitCounter = (UnitCounter - 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • UnitCounter Equal to 0
        • Then - Actions
          • Destructible - Open MyGate
        • Else - Actions
Where "UnitCounter" is an integer variable.

No unit group required (getting the unit count of a unit group is possible (this also uses an integer), but it's slower and not recommended.)
 
Level 7
Joined
Jan 29, 2010
Messages
213
  • Unit - Dies
  • Conditions
    • Owner of dying unit is Player X
  • Actions
    • Set MOBS_Count = Count living units in region X matching Owner of the maching unit equal to Player X
    • If then else do
      • conditions
        • Integer MOBS_Count is equal to 0
      • then do
        • Your actions
        • ===Try adding "Game Display to Players Integer MOBS_Count" these things help a lot===
      • Else do
I think this trigger has a group leak
Better use this one

  • Unit - Dies
  • Conditions
    • Owner of dying unit is Player X
  • Actions
    • Set MOBS_Group = Pick every unit in region X matching Owner of the maching unit equal to Player X
    • Set MOBS_Count = Count living units in MOBS_Group
    • If then else do
      • conditions
        • Integer MOBS_Count is equal to 0
      • then do
        • Your actions
        • Custom script: call DestroyGroup (udg_MOBS_Group)
        • ===Try adding "Game Display to Players Integer MOBS_Count" these things help a lot===
      • Else do
I dont think it has Point leak so u may use this (LOL):

  • Unit - Dies
  • Conditions
    • Owner of dying unit is Player X
  • Actions
    • Set MOBS_Point = Region X
    • Set MOBS_Group = Pick every unit in MOBS_Point matching Owner of the maching unit equal to Player X
    • Set MOBS_Count = Count living units in MOBS_Group
    • If then else do
      • conditions
        • Integer MOBS_Count is equal to 0
      • then do
        • Your actions
        • ===Try adding "Game Display to Players Integer MOBS_Count" these things help a lot===
        • Custom script: call DestroyGroup (udg_MOBS_Group)
        • Custom script: call RemoveLocation (udg_MOBS_Point)
      • Else do
 
Last edited:
Level 7
Joined
Jan 29, 2010
Messages
213
DOW3R, the leak removals should be done after the if/hen/else.

RemoveLocation works for point type variables, you are mixing it with region type object.

So I have to use:
  • Custom script: call RemoveRect (udg_Temp_Region)
Instead of
  • Custom script: call RemoveLocation (udg_Temp_Point)
as much as I can understand.

So is it OK now?
  • Unit - Dies
  • Conditions
    • Owner of dying unit is Player X
  • Actions
    • Set MOBS_Region = Region X
    • Set MOBS_Group = Pick every unit in MOBS_Point matching Owner of the maching unit equal to Player X
    • Set MOBS_Count = Count living units in MOBS_Group
    • If then else do
      • conditions
        • Integer MOBS_Count is equal to 0
      • then do
        • Your actions
        • ===Try adding "Game Display to Players Integer MOBS_Count" these things help a lot===
      • Else do
    • Custom script: call DestroyGroup (udg_MOBS_Group)
    • Custom script: call RemoveRect (udg_MOBS_Region)
 
Last edited:
Level 3
Joined
May 24, 2012
Messages
57
What about if part of the units are created from other events? example as in the game. 4 magic runes activate tombs that summon skeletons and all the skeletons must be killed in order for the gate to open.
 
Status
Not open for further replies.
Top