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

Better way to make unit group?

Status
Not open for further replies.
Level 10
Joined
Sep 25, 2013
Messages
521
Hi! I have a lot of triggers in my map that use temporary unit groups. The problem is that many of these specify that the matching unit can not be many different units. For example, if i cast the traitor spell, which in an AOE spell that changes the units ownership to that of the casting unit's, I have specify that the affected units aren't any type of worker, aren't structures or mechanical, aren't heroes, and aren't certain elite units. The way i do this is by using the "and" function multiple times within the temp unit group setup.

Is there a way I can achieve this outside of the matching unit thing, like how you can create a list of conditions normally.

Heres an example:

  • Generate Gold
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set tempUnitGroup = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Equal to Farm (Gondor)) or (((Unit-type of (Matching unit)) Equal to Mine Shaft (Dwarves)) or (((Unit-type of (Matching unit)) Equal to Slaughter House (Isengard)) or (((Unit-type of (Mat
      • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Human Priest - Inner Fire (Picked unit)
      • Custom script: call DestroyGroup(udg_tempUnitGroup)
      • Set tempUnitGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Fishing Ship))
      • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Human Priest - Inner Fire (Picked unit)
      • Custom script: call DestroyGroup(udg_tempUnitGroup)
 
Level 12
Joined
May 22, 2015
Messages
1,051
Oh man I used to do something like this for item recipes and it was paaaaaiiinnful to work with.

I came up with an idea at one point to add abilities to units to mark them. You base it off of an ability that has no icon (such Item Damage Bonus) and have it add 0 stats. Then you add this to units that shouldn't be affected by certain things.

The issue is you might end up with a ton of abilities like this. It depends on how these things work.

An alternative for something like the fishing ship one, you could just manage a constant group called something like FishingShips. When you make a fishing ship, you add it to the group. When one dies, you remove it from the group.

Then you just use that group each time and never destroy it. It is more efficient in a frequently running trigger like this.
 
Level 12
Joined
Jan 2, 2016
Messages
973
you can add an "if" INSIDE the loop:
if all conditions are true do (then) actions, else do (else) actions:
conditions:
condition 1
condition 2
condition 3
....
then actions:
your actions
else actions:
-Blank-

By the way, does your trigger really work? Last 3 times I destroyed a unit group (variable) this way - I couldn't use it anymore.
 
Level 10
Joined
Sep 25, 2013
Messages
521
you can add an "if" INSIDE the loop:
if all conditions are true do (then) actions, else do (else) actions

Oh my god of triggering... how could i have been such a fool this WHOLE TIME! Thank you for showing me the light! Thank you both for your assistance! +rep all around

and yeah it works, i believe because it is recreating the unit group every 5 seconds anyway

Edit:
Should I, instead of using temp unit group, say all unit in playable map area?
 
Level 10
Joined
Sep 25, 2013
Messages
521
Here's what i did. Does this look okay?

  • Generate Gold
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set tempUnitGroup = (Units in (Playable map area))
      • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
        • Loop - Actions
          • Set PickedUnit = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Unit-type of PickedUnit) Equal to Amon Amarth
                  • (Unit-type of PickedUnit) Equal to Cirith Ungol
                  • (Unit-type of PickedUnit) Equal to Ephel Dúath
                  • (Unit-type of PickedUnit) Equal to Ered Lithui
                  • (Unit-type of PickedUnit) Equal to Harondor
                  • (Unit-type of PickedUnit) Equal to Karna
                  • (Unit-type of PickedUnit) Equal to Kyzilkum
                  • (Unit-type of PickedUnit) Equal to Lithlad
                  • (Unit-type of PickedUnit) Equal to Lower Khand
                  • (Unit-type of PickedUnit) Equal to Lower Minas Morgul
                  • (Unit-type of PickedUnit) Equal to Upper Minas Morgul
                  • (Unit-type of PickedUnit) Equal to Lower Ovatharac
                  • (Unit-type of PickedUnit) Equal to Mogurakh
                  • (Unit-type of PickedUnit) Equal to Morgul Vale
                  • (Unit-type of PickedUnit) Equal to East Morgul Vale
                  • (Unit-type of PickedUnit) Equal to North Gorgoth Pass
                  • (Unit-type of PickedUnit) Equal to North Thaurband
                  • (Unit-type of PickedUnit) Equal to West Thaurband
                  • (Unit-type of PickedUnit) Equal to Northern Port of Nurn
                  • (Unit-type of PickedUnit) Equal to Nurnen Battle Plain
                  • (Unit-type of PickedUnit) Equal to Nurnen Slave Farm
                  • (Unit-type of PickedUnit) Equal to Orc War Camp
                  • (Unit-type of PickedUnit) Equal to Port of Umbar
                  • (Unit-type of PickedUnit) Equal to Sammath Naur
                  • (Unit-type of PickedUnit) Equal to South Gorgoth Pass
                  • (Unit-type of PickedUnit) Equal to Southern Port of Nurn
                  • (Unit-type of PickedUnit) Equal to The Hidden Stair
                  • (Unit-type of PickedUnit) Equal to Upper Khand
                  • (Unit-type of PickedUnit) Equal to Upper Ovatharac
                  • (Unit-type of PickedUnit) Equal to Uruk-Hai Fortress (Isengard)
                  • (Unit-type of PickedUnit) Equal to Wall of Gorgoth Pass
            • Then - Actions
              • Unit - Order PickedUnit to Human Priest - Inner Fire PickedUnit
            • Else - Actions
      • Custom script: call DestroyGroup (udg_tempUnitGroup)
      • Set tempUnitGroup = (Units in (Playable map area))
      • Unit Group - Pick every unit in tempUnitGroup and do (Actions)
        • Loop - Actions
          • Set PickedUnit = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of PickedUnit) Equal to Fishing Ship
            • Then - Actions
              • Unit - Order PickedUnit to Human Priest - Inner Fire PickedUnit
            • Else - Actions
      • Custom script: call DestroyGroup (udg_tempUnitGroup)
 
Level 12
Joined
Jan 2, 2016
Messages
973
Oh, no no no, this isn't good:
1) you need to add these conditions under an "or" - a unit can't possibly be all these unit-types at once :D EDIT: didn't notice there was one 1-st time I look at the trigger.
2) You totally shouldn't destroy the unit group inside the loop, you need to do it after the loop is done.
3) You are picking all the units in the map and then each time you pick a unit - you are picking all the units in the map. You need to end the 1-st loop before starting the next one.
4) Instead of making a new unit group every time - you can just store all these units in a unit group, that doesn't get destroyed, and pick all the units from this unit group instead.
You can add newly spawned units to that group, and remove dead ones from it in other triggers.
 
Last edited:
Level 16
Joined
Mar 27, 2011
Messages
1,349
Yes your trigger is picking every unit on the map TWICE every 0.5 seconds. Depending on how many units you have, this could be extremely heavy. Do what WereElf suggested in point 4.

Instead of creating a new unit group every 0.5 seconds, just pick from an existing group which doesn't get destroyed. You can add units to this group when they enter the map and remove them when they die. I had to do this in a map where I moved about 80+ units every 5 seconds. It lagged heavily!

Edit: I made the triggers for you.

  • Add Units
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • Or - Any (Conditions) are true
        • (Unit-type of PickedUnit) Equal to Amon Amarth
        • (Unit-type of PickedUnit) Equal to Cirith Ungol
        • (Unit-type of PickedUnit) Equal to Ephel Dúath
        • (Unit-type of PickedUnit) Equal to Ered Lithui
        • (Unit-type of PickedUnit) Equal to Harondor
        • (Unit-type of PickedUnit) Equal to Karna
        • (Unit-type of PickedUnit) Equal to Kyzilkum
        • (Unit-type of PickedUnit) Equal to Lithlad
        • (Unit-type of PickedUnit) Equal to Lower Khand
        • (Unit-type of PickedUnit) Equal to Lower Minas Morgul
        • (Unit-type of PickedUnit) Equal to Upper Minas Morgul
        • (Unit-type of PickedUnit) Equal to Lower Ovatharac
        • (Unit-type of PickedUnit) Equal to Mogurakh
        • (Unit-type of PickedUnit) Equal to Morgul Vale
        • (Unit-type of PickedUnit) Equal to East Morgul Vale
        • (Unit-type of PickedUnit) Equal to North Gorgoth Pass
        • (Unit-type of PickedUnit) Equal to North Thaurband
        • (Unit-type of PickedUnit) Equal to West Thaurband
        • (Unit-type of PickedUnit) Equal to Northern Port of Nurn
        • (Unit-type of PickedUnit) Equal to Nurnen Battle Plain
        • (Unit-type of PickedUnit) Equal to Nurnen Slave Farm
        • (Unit-type of PickedUnit) Equal to Orc War Camp
        • (Unit-type of PickedUnit) Equal to Port of Umbar
        • (Unit-type of PickedUnit) Equal to Sammath Naur
        • (Unit-type of PickedUnit) Equal to South Gorgoth Pass
        • (Unit-type of PickedUnit) Equal to Southern Port of Nurn
        • (Unit-type of PickedUnit) Equal to The Hidden Stair
        • (Unit-type of PickedUnit) Equal to Upper Khand
        • (Unit-type of PickedUnit) Equal to Upper Ovatharac
        • (Unit-type of PickedUnit) Equal to Uruk-Hai Fortress (Isengard)
        • (Unit-type of PickedUnit) Equal to Wall of Gorgoth Pass
    • Actions
      • Unit Group - Add (Triggering unit) to UnitGroup
  • Remove Units
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in UnitGroup) Equal to True
    • Actions
      • Unit Group - Remove (Triggering unit) from UnitGroup
  • Generate Gold
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in UnitGroup and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Human Priest - Inner Fire (Picked unit)
 
Level 10
Joined
Sep 25, 2013
Messages
521
Thanks guys, I'm really trying to optimize my map and I'm glad to be learning better ways of doing things. +rep

LOL here is my updated trigger! All the units where added to the group at .10 time elapsed

  • Generate Gold
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Regions and do (Actions)
        • Loop - Actions
          • Unit - Order PickedUnit to Human Priest - Inner Fire PickedUnit
Edit: Thanks a bunch! I'm going to revamp all my other triggers that need it now
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
No worries.

All the units where added to the group at .10 time elapsed

Just remember, if you build or create new units that need to "Generate Gold" or whatever, rememeber to add them to your "Regions" group somehow. And if they die or no longer need to generate gold, remove them from the group. Easiest way to do that is mentioned above. Make 2 triggers like mine.
 
Level 11
Joined
Dec 19, 2012
Messages
411
Units which is added into a unit group won't be removed automatically, you can only remove them manually. So :

Remove unit from game - unit still remains in the group

Unit transform into bear form (druid as an example) - unit still remains in the group correctly, if the unit name "A" before transform, and after transform name "B", getting the unit name would be "B" from a unit group.

Unit is replaced via trigger - original unit remains in group, replaced unit is new unit, so it is not in the unit group

Will unit leaves region work as well?
I'm not too sure what you mean, if you want the unit get removed from unit ground once leaves a specific region, just add an event Unit - Leaves region, and action with removing the unit from group
 
Status
Not open for further replies.
Top