1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Issue with targeting a unit group.

Discussion in 'Triggers & Scripts' started by Rugarus, Jun 26, 2018.

  1. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    718
    Resources:
    0
    Resources:
    0
    • 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.
     
  2. Kaijyuu

    Kaijyuu

    Joined:
    Jun 2, 2004
    Messages:
    848
    Resources:
    0
    Resources:
    0
    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.
     
  3. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,654
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    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.
     
  4. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    718
    Resources:
    0
    Resources:
    0
    thanks.