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

How to pick the three closest enemy units

Status
Not open for further replies.
Level 2
Joined
Dec 12, 2017
Messages
26
I have a skill (based on Taunt of the Mountain Giant) in a unit to provoke nearby enemy units. In level 1, provoke the nearest enemy unit by adding (200 x Skill Level) points of the Threat System that I have implemented (Zwiebelchen's Threat System 2.7), in level 2 it provokes the two closest enemies and in level 3 to the three enemies closest.
What I have is this:
  • Provoke
    • Events
      • Unit - A unit owned by Player 1 (Red) Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Provoke (Guerrero)
    • Actions
      • Wait 0.50 seconds
      • Unit Group - Pick every unit in (Units within 400.00 of (Position of (Triggering unit)) matching ((Owner of (Matching unit)) Equal to Neutral Hostile)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has buff Provoked ) Equal to True
            • Then - Actions
              • Custom script: call ZTS_ModifyThreat( GetTriggerUnit(), GetEnumUnit(), 200*GetUnitAbilityLevel(GetTriggerUnit(), GetSpellAbilityId()), true)
            • Else - Actions
              • Do nothing
The problem is that the Taunt skill crashes the game if it adds a buff (in this case "Provoked") to the affected enemy units, and I do not find the "Taunt" buff that it adds by default to the enemy units affected if I leave in blank the Buff space in the Object Editor:
provoke
Then I set out to do it using Triggers, but I do not know how to pick up more than one enemy unit closer for add the threat points, so I hope you can give me a hand with this.
 
Last edited:
Level 2
Joined
Dec 12, 2017
Messages
26
Hi man, glad to see ya. It used to work, but with the new patches that came out (i have 1.30.1.10211 by the way), if the Taunt skill applies a Buff crash the game, and I do not find the "Taunt" buff that skill applies by default if I leave the buff space in blank, so this way it does not work for me anymore, that's why I'm looking for a way to do it using triggers.
 
Level 7
Joined
Oct 3, 2008
Messages
183
You could store the units within range in a group, make an array that stores the distance between the caster and each unit in the group, and then filter out the three smallest values and pick the associated units.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
You could store the units within range in a group, make an array that stores the distance between the caster and each unit in the group, and then filter out the three smallest values and pick the associated units.
Not as efficient as it could be but:

  • Unit Group - Remove all units from CLOSEST
  • Set LVL = (Level of Provoke for (Triggering Unit))
  • Set POINT = (Position of (Triggering Unit))
  • Set GROUP = (Units within ...)
  • For each (Integer A) from 1 to LVL do (Actions)
    • Set MIN = 1000.00 //whatever the radius that you're grabbing unitsin for GROUP above
    • Unit Group - Pick all units in GROUP and do (Actions)
      • Loop - Actions
        • Set POINT_2 = (Position of (Picked Unit))
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (Distance between POINT and POINT_2) less than or equal to MIN
          • Then - Actions
            • Set UNIT = (Picked Unit)
          • Else - Actions
        • Unit Group - Add UNIT to CLOSEST
        • Unit Group - Remove UNIT from GROUP
  • Custom script: call DestroyGroup(udg_GROUP) //udg_CLOSEST is cleared and re-used, udg_GROUP needs to be cleaned up and destroyed)
  • Set UNIT = (Triggering Unit)
  • Unit Group - Pick all units in CLOSEST and do (Actions)
    • Loop - Actions
      • Custom script: call ZTS_ModifyThreat(udg_UNIT, GetEnumUnit(), 200*udg_LVL, true)
 
Level 2
Joined
Dec 12, 2017
Messages
26
That looks good, I tried to do it my way but it was unnecessarily more complicated than that. In your way it stayed like this:
  • Provoke
    • Events
      • Unit - A unit owned by Player 1 (Red) Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Taunt (Guerrero)
    • Actions
      • Unit Group - Remove all units from ProvokeClosest
      • Set ProvokeLvl = (Level of Taunt (Guerrero) for (Triggering unit))
      • Set ProvokeCasterPoint = (Position of (Triggering unit))
      • Set ProvokeGroup = (Units within 400.00 of ProvokeCasterPoint matching ((((Matching unit) is A structure) Equal to False) and (((Owner of (Matching unit)) Equal to Neutral Hostile) and (((Matching unit) is alive) Equal to True))))
      • For each (Integer A) from 1 to ProvokeLvl, do (Actions)
        • Loop - Actions
          • Set ProvokeMin = 400.00
          • Unit Group - Pick every unit in ProvokeGroup and do (Actions)
            • Loop - Actions
              • Set ProvokeEnemyPoint = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between ProvokeCasterPoint and ProvokeEnemyPoint) Less than or equal to ProvokeMin
                • Then - Actions
                  • Set ProvokeUnit = (Picked unit)
                • Else - Actions
              • Unit Group - Add ProvokeUnit to ProvokeClosest
              • Unit Group - Remove ProvokeUnit from ProvokeGroup
      • Custom script: call DestroyGroup(udg_ProvokeGroup)
      • Set ProvokeUnit = (Triggering unit)
      • Unit Group - Pick every unit in ProvokeClosest and do (Actions)
        • Loop - Actions
          • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Other\SoulBurn\SoulBurnbuff.mdl
          • Special Effect - Destroy (Last created special effect)
I added that special effect at the end to see which units were affected, and it turns out that the special effect appears on all the enemy units nearby, regardless of the level of the skill, curious, I can not see why
 
Level 7
Joined
Oct 3, 2008
Messages
183
You're not actually only picking the closest units, you're adding all of them to ProvokeClosest. You gotta add ProvokeUnit to ProvokeClosest after you go over ProvokeGroup, not in it. It should be in the loop actions for the Integer A loop after the group loop, not in the group loop if that makes sense?

GWU7RK3.png


These two lines should be moved to be in the For Each (Integer A) loop instead of the Unit Group loop.
 
Status
Not open for further replies.
Top