What's with the units in region owned by player trigger?

Level 12
Joined
Jul 5, 2014
Messages
551
This is not the first time that condition doesn't seem to work. I checked it and the trigger runs without the "units owned by Player 11" condition, so it has to be the problem. Am I doing something wrong or is it bugged?

  • Merc Saved
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Number of units in (Units owned by Player 11 (Dark Green))) Equal to 0) and ((Reanimated Mercenary 0001 <gen> is alive) Equal to True)
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Wait 1.00 seconds
          • If ((Reanimated Mercenary 0001 <gen> is alive) Equal to False) then do (Skip remaining actions) else do (Do nothing)
          • Cinematic - Send transmission to (All players) from Reanimated Mercenary 0001 <gen> named Reanimated Mercenary: Play No sound and display I don't know who yo.... Modify duration: Set to 10.00 seconds and Don't wait
          • Wait 10.00 seconds
          • If ((Reanimated Mercenary 0001 <gen> is alive) Equal to False) then do (Skip remaining actions) else do (Do nothing)
          • Set SingleUsePoint3 = (Position of Reanimated Mercenary 0001 <gen>)
          • Item - Create Heavy Maul at SingleUsePoint3
          • Custom script: call RemoveLocation(udg_SingleUsePoint3)
          • Unit - Order Reanimated Mercenary 0001 <gen> to Move To (Center of Merc_Leaves <gen>)
          • Wait until ((Merc_Leaves <gen> contains Reanimated Mercenary 0001 <gen>) Equal to True), checking every 0.40 seconds
          • Unit - Remove Reanimated Mercenary 0001 <gen> from the game
        • Else - Actions
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Nowhere are you using "Units in region owned by player".

One important thing to remember is that Dead units are counted when checking a group of units like this.

Here's a setup that takes that into consideration as well as being more efficient and avoiding a bad memory leak:
  • Merc Saved
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
      • (Reanimated Mercenary 0001 <gen> is alive) Equal to True
    • Actions
      • Set Temp_Group = (Units in (Playable map area)) matching (Owner of (Matching unit)) Equal to Player 11 (Dark Green)) and (Matching unit) is Alive Equal to True
      • Set Temp_Integer = (Number of units in Temp_Group)
      • Custom script: call DestroyGroup( udg_Temp_Group )
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Wait 1.00 seconds
          • If ((Reanimated Mercenary 0001 <gen> is alive) Equal to False) then do (Skip remaining actions) else do (Do nothing)
          • Cinematic - Send transmission to (All players) from Reanimated Mercenary 0001 <gen> named Reanimated Mercenary: Play No sound and display I don't know who yo.... Modify duration: Set to 10.00 seconds and Don't wait
          • Wait 10.00 seconds
          • If ((Reanimated Mercenary 0001 <gen> is alive) Equal to False) then do (Skip remaining actions) else do (Do nothing)
          • Set SingleUsePoint3 = (Position of Reanimated Mercenary 0001 <gen>)
          • Item - Create Heavy Maul at SingleUsePoint3
          • Custom script: call RemoveLocation(udg_SingleUsePoint3)
          • Unit - Order Reanimated Mercenary 0001 <gen> to Move To (Center of Merc_Leaves <gen>)
          • Wait until ((Merc_Leaves <gen> contains Reanimated Mercenary 0001 <gen>) Equal to True), checking every 0.40 seconds
          • Unit - Remove Reanimated Mercenary 0001 <gen> from the game
        • Else - Actions
 
Level 12
Joined
Jul 5, 2014
Messages
551
Nowhere are you using "Units in region owned by player".

One important thing to remember is that Dead units are counted when checking a group of units like this.

Here's a setup that takes that into consideration as well as being more efficient and avoiding a bad memory leak:
  • Merc Saved
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
      • (Reanimated Mercenary 0001 <gen> is alive) Equal to True
    • Actions
      • Set Temp_Group = (Units in (Playable map area)) matching (Owner of (Matching unit)) Equal to Player 11 (Dark Green)) and (Matching unit) is Alive Equal to True
      • Set Temp_Integer = (Number of units in Temp_Group)
      • Custom script: call DestroyGroup( udg_Temp_Group )
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Wait 1.00 seconds
          • If ((Reanimated Mercenary 0001 <gen> is alive) Equal to False) then do (Skip remaining actions) else do (Do nothing)
          • Cinematic - Send transmission to (All players) from Reanimated Mercenary 0001 <gen> named Reanimated Mercenary: Play No sound and display I don't know who yo.... Modify duration: Set to 10.00 seconds and Don't wait
          • Wait 10.00 seconds
          • If ((Reanimated Mercenary 0001 <gen> is alive) Equal to False) then do (Skip remaining actions) else do (Do nothing)
          • Set SingleUsePoint3 = (Position of Reanimated Mercenary 0001 <gen>)
          • Item - Create Heavy Maul at SingleUsePoint3
          • Custom script: call RemoveLocation(udg_SingleUsePoint3)
          • Unit - Order Reanimated Mercenary 0001 <gen> to Move To (Center of Merc_Leaves <gen>)
          • Wait until ((Merc_Leaves <gen> contains Reanimated Mercenary 0001 <gen>) Equal to True), checking every 0.40 seconds
          • Unit - Remove Reanimated Mercenary 0001 <gen> from the game
        • Else - Actions
Apparently, during my last attempt, I've used the wrong trigger. It used to check a region for player owned unit but I didn't know that unit groups count dead unit too.

EDIT: I don't understand why "matching unit" makes difference and why the "alive check" is also in the unit group.

This is my revised trigger based on your suggestion but it still doesn't work. Merc_Attacked is a false default boolean that becomes true if you attack the mercenary.

  • Merc Saved
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
      • (Reanimated Mercenary 0001 <gen> is alive) Equal to True
    • Actions
      • Set TempGroup = (Units in Merc Zone <gen> matching ((Owner of (Matching unit)) Equal to Player 11 (Dark Green)))
      • Set Spider_number = (Number of units in TempGroup)
      • Custom script: call DestroyGroup(udg_TempGroup)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Spider_number Equal to 0) and (Merc_Attacked Equal to False)
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Wait 1.00 seconds
          • If ((Reanimated Mercenary 0001 <gen> is alive) Equal to False) then do (Skip remaining actions) else do (Do nothing)
          • Cinematic - Send transmission to (All players) from Reanimated Mercenary 0001 <gen> named Reanimated Mercenar...: Play No sound and display I don't know who yo.... Modify duration: Set to 10.00 seconds and Don't wait
          • Wait 10.00 seconds
          • If ((Reanimated Mercenary 0001 <gen> is alive) Equal to False) then do (Skip remaining actions) else do (Do nothing)
          • Set SingleUsePoint3 = (Position of Reanimated Mercenary 0001 <gen>)
          • Item - Create Heavy Maul at SingleUsePoint3
          • Custom script: call RemoveLocation(udg_SingleUsePoint3)
          • Unit - Order Reanimated Mercenary 0001 <gen> to Move To (Center of Merc_Leaves <gen>)
          • Wait until ((Merc_Leaves <gen> contains Reanimated Mercenary 0001 <gen>) Equal to True), checking every 0.40 seconds
          • Unit - Remove Reanimated Mercenary 0001 <gen> from the game
        • Else - Actions
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
(Matching unit) is used in combination with the matching keyword. Just like how (Casting unit) goes along with the "A unit Casts an ability" Events and (Dying unit) goes along with the "A unit Dies" Event. It's also similar to how you need to use (Picked unit) to reference the units inside of the "Pick Every Unit" Loop - Actions. The game needs to know which Unit you're trying to interact with and ask questions about, it does not and in some cases cannot assume anything. This is a good thing because it gives the user much more control and flexibility.

Anyway, you're including Dead units again in your Unit Group:
  • Set TempGroup = (Units in Merc Zone <gen> matching ((Owner of (Matching unit)) Equal to Player 11 (Dark Green)))
Perhaps you're certain that there are no Dead units there but I would never assume something like that.

Unit Groups work like this:
  • You Set the Unit Group variable. This creates a brand new Unit Group object which is then tracked by the variable. The variable can only track one object at a time so if a previous object was present then it will be forgotten (memory leaks come into play here).
  • The Unit Group object then gets filled with Units that match the function you've used when setting the variable. In this case it's being filled with any Units in Merc Zone owned by P11.
  • You may want Dead units in your Unit Group so the game doesn't make any assumptions. For example, you could be triggering something like a custom Raise Dead spell that requires a corpse. So it's not going to exclude these without your explicit instructions to do so.


Here's some examples of different ways to use a Unit Group variable:

1) You can choose to NEVER set a Unit Group variable and instead manually Add/Remove units to and from it.
  • Unit Group - Add (Triggering unit) to My_Constant_Unit_Group
  • Unit Group - Remove (Triggering unit) from My_Constant_Unit_Group
This works because Warcraft 3 automatically creates a new Unit Group object for all of your Unit Group variables by default.

2) When dealing with Unit Group arrays, the above rule about automatic objects doesn't apply. Instead, you need to either set the variable's Size to how many objects you want to create. A Size of 10 for example will create automatic objects for indexes [1] -> [10]. Or you can manually create a Unit Group object using Custom Script and assign that to a variable:
  • Custom script: set udg_My_Unit_Group_Array[5] = CreateGroup()
^ This is particularly useful when your [index] can be a random number with no apparent limit. For example, when you're using Unit Indexing and you plug the unit's custom value into the [index].

3) You can Add a range of Units to your constant Unit Groups as well:
  • Set TempGroup = (Units owned by Player 1 (Red))
  • Unit Group - Add all units of TempGroup to My_Constant_Unit_Group
  • Custom script: call DestroyGroup( udg_TempGroup )
4) In a lot of cases you'll see people use this design which I find very convenient and efficient:
  • Actions
    • Set VariableSet TempGroup = (Units in (Playable map area))
    • Unit Group - Pick every unit in TempGroup and do (Actions)
      • Loop - Actions
        • Set PickedUnit = (Picked unit)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Owner of PickedUnit) Equal to Player 11 (Dark Green)
            • (PickedUnit is alive) Equal to True
          • Then - Actions
            • Unit - Cause (Some unit) to damage PickedUnit, dealing 500.00 damage of attack type Spells and damage type Normal
          • Else - Actions
    • Custom script: call DestroyGroup( udg_TempGroup )
Adding on more Conditions is MUCH easier since you don't have to deal with a bunch of nested windows.
 
Last edited:
Level 12
Joined
Jul 5, 2014
Messages
551
(Matching unit) is used in combination with the matching keyword. Just like how (Casting unit) goes along with the "A unit Casts an ability" Events and (Dying unit) goes along with the "A unit Dies" Event. It's also similar to how you need to use (Picked unit) to reference the units inside of the "Pick Every Unit" Loop - Actions. The game needs to know which Unit you're trying to interact with and ask questions about, it does not and in some cases cannot assume anything. This is a good thing because it gives the user much more control and flexibility.

Anyway, you're including Dead units again in your Unit Group:
  • Set TempGroup = (Units in Merc Zone <gen> matching ((Owner of (Matching unit)) Equal to Player 11 (Dark Green)))
Perhaps you're certain that there are no Dead units there but I would never assume something like that.

Unit Groups work like this:
  • You Set the Unit Group variable. This creates a brand new Unit Group object which is then tracked by the variable. The variable can only track one object at a time so if a previous object was present then it will be forgotten (memory leaks come into play here).
  • The Unit Group object then gets filled with Units that match the function you've used when setting the variable. In this case it's being filled with any Units in Merc Zone owned by P11.
  • You may want Dead units in your Unit Group so the game doesn't make any assumptions. For example, you could be triggering something like a custom Raise Dead spell that requires a corpse. So it's not going to exclude these without your explicit instructions to do so.


Here's some examples of different ways to use a Unit Group variable:

1) You can choose to NEVER set a Unit Group variable and instead manually Add/Remove units to and from it.
  • Unit Group - Add (Triggering unit) to My_Constant_Unit_Group
  • Unit Group - Remove (Triggering unit) from My_Constant_Unit_Group
This works because Warcraft 3 automatically creates a new Unit Group object for all of your Unit Group variables by default.

2) When dealing with Unit Group arrays, the above rule about automatic objects doesn't apply. Instead, you need to either set the variable's Size to how many objects you want to create. A Size of 10 for example will create automatic objects for indexes [1] -> [10]. Alternatively, you can manually create a Unit Group object using Custom Script and assign that to a variable:
  • Custom script: set_udg_My_Unit_Group_Array[5] = CreateGroup()
^ This is particularly useful when your [index] can be a random number with no apparent limit. For example, when you're using Unit Indexing and you plug the unit's custom value into the [index].

3) You can Add a range of Units to your constant Unit Groups as well:
  • Set TempGroup = (Units owned by Player 1 (Red))
  • Unit Group - Add TempGroup to My_Constant_Unit_Group
  • Custom script: call DestroyGroup( udg_TempGroup )
Okay, for some reason I thought that your "matching unit is alive" refers to the mercenary, which is why I omitted it. I haven't messed around with unit group array yet, it seems a little confusing. However, the trigger's working now, so thanks for the help.
 
Top