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

[Trigger] Issue with targeting a unit group.

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
  • Attack nearby slayers
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to (Number of units in HellHounds), do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in HellHounds and do (Actions)
            • Loop - Actions
              • Unit Group - Pick every unit in (Units within 512.00 of (Position of (Picked unit))) and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Unit-type of (Picked unit)) Equal to Slayer) or ((Unit-type of (Picked unit)) Equal to Slayeress)
                    • Then - Actions
                      • Unit - Order (Picked unit) to Attack (Picked unit)
                    • Else - Actions
So when this trigger runs the goal is to get all units in the HellHounds unit group to attack nearby within 512 range heroes matching my unit type "Slayer or Slayeress". I'm not sure how to go about this properly. Any help? Thanks.
 
Level 11
Joined
Jun 2, 2004
Messages
849
Yikes that's a mess...
  • Attack nearby slayers
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in HellHounds and do (Actions)
        • Loop - Actions
          • Set TempUnit to Picked Unit
          • Set TempPoint to Position of Picked Unit
          • Set TempUnitGroup to Units within 512.00 of TempPoint
          • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Unit-type of (Picked unit)) Equal to Slayer) or ((Unit-type of (Picked unit)) Equal to Slayeress)
                • Then - Actions
                  • Unit - Order (TempUnit) to Attack (Picked unit)
                • Else - Actions
          • Custom script: call RemoveLocation(udg_TempPoint)
          • Custom script: call DestroyGroup(udg_TempUnitGroup)

It would also probably be faster to keep track of all Slayer(ess) units in a unit group, similar to how you're keeping the hell hounds in their own unit group, and loop over that instead of the "Units within 512 of TempPoint" groups.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
I just want to point out that there is some redundant code in there.

For example, let's say you find 20 units around a specific hellhound.
This means that the hellhound will be given 20 orders in a span of a moment, not really ideal.

So you'd want to cancel the unit group once a valid target is found.
There are multiple ways to do it.
I think destroying the group from the inside might work, but I have never tried it.

Alternatively, loop instead of a unit group. This probably requires jass though.But it is easy to cancel.
 
Level 12
Joined
Dec 2, 2016
Messages
733
Yikes that's a mess...
  • Attack nearby slayers
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in HellHounds and do (Actions)
        • Loop - Actions
          • Set TempUnit to Picked Unit
          • Set TempPoint to Position of Picked Unit
          • Set TempUnitGroup to Units within 512.00 of TempPoint
          • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Unit-type of (Picked unit)) Equal to Slayer) or ((Unit-type of (Picked unit)) Equal to Slayeress)
                • Then - Actions
                  • Unit - Order (TempUnit) to Attack (Picked unit)
                • Else - Actions
          • Custom script: call RemoveLocation(udg_TempPoint)
          • Custom script: call DestroyGroup(udg_TempUnitGroup)

It would also probably be faster to keep track of all Slayer(ess) units in a unit group, similar to how you're keeping the hell hounds in their own unit group, and loop over that instead of the "Units within 512 of TempPoint" groups.

thanks.
 
Status
Not open for further replies.
Top