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

Cast ensnare on nearest unit type..

Status
Not open for further replies.
Level 9
Joined
Jul 20, 2009
Messages
427
How do I make a trigger that would order my unit to cast ensnare on the nearest unit of certain type..
I already did the triggers on how to cast the spell but I want it such that it would cast it to the specific unit nearest from its location..
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
This was already solved over PM :)

  • Untitled Trigger 052 Copy
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Animate Dead
    • Actions
      • Set Temp_Unit_1 = Triggering Unit
      • Set Temp_Loc_1 = (Position of Temp_Unit_1)
      • Set Temp_Real_1 = 9999999.00
      • Set Temp_Group_1 = (Units in (Playable map area) matching (Temp_Unit_1 Not equal to (Matching unit)))
      • Unit Group - Pick every unit in Temp_Group_1 and do (Actions)
        • Loop - Actions
          • Set Temp_Loc_2 = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Temp_Loc_1 and Temp_Loc_2) Less than Temp_Real_1
            • Then - Actions
              • Set Temp_Unit_2 = (Picked unit)
              • Set Temp_Real_1 = (Distance between Temp_Loc_1 and Temp_Loc_2)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_Temp_Loc_2)
      • Custom script: call RemoveLocation(udg_Temp_Loc_1)
      • Custom script: call DestroyGroup(udg_Temp_Group_1)
      • Unit - Order Temp_Unit_1 to Right-Click Temp_Unit_2
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
If the spell has somehow limited range, it would be wise to pick units in range, looping throught every unit in game is slower. (Like pick units in 1000 range and choose from them)
Also, I am not 100% sure here, but using (Temp_Unit_1 Not equal to (Matching unit)) is slower than just picking all and then removing Temp_unit_1 from the group.
 
Status
Not open for further replies.
Top