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

Kill Nearest Unit

Status
Not open for further replies.
Level 33
Joined
Mar 27, 2008
Messages
8,035
Okay, I got my CasterUnit casting a spell
This spell will kill enemy unit that is the most nearest to the CasterUnit
Say:

CasterUnit's distance to Enemy A is 350.00
CasterUnit's distance to Enemy B is 150.00
CasterUnit's distance to Enemy C is 600.00

So, I want this spell to only kill Enemy B (which is the most nearest)
I tried using For Loop Integer action and Unit Group - Pick Every Unit... action but still fail

Can someone show me the proper action ?
 
Level 5
Joined
Apr 22, 2011
Messages
152
temp_position, temp_position_2 - are points.
distance, min_range - are reals (so they don't leak)

  • Actions
    • Set temp_position = (Position of (Triggering unit))
    • Set min_range = 1000.00
    • Unit Group - Pick every unit in (Units within 1000.00 of temp_position) and do (Actions)
      • Loop - Actions
        • Set temp_position_2 = (Position of (Picked unit))
        • Set distance = (Distance between temp_position and temp_position_2)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • distance Less than min_range
            • <HERE YOU MUST CHECK if Picked unit is of certain type or belongs to a certain player, or else you would kill yourself with this trigger>
          • Then - Actions
            • Set min_range = distance
            • Set unit_target = (Picked unit)
          • Else - Actions
        • Custom script: call RemoveLocation(udg_temp_position_2)
    • Unit - Kill unit_target
    • Custom script: call RemoveLocation(udg_temp_position)
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Yes, I did that earlier in the trigger, (Matching unit) is alive Equal to True :)
I filtered it earlier in the trigger, hehe

Also, it doesn't "bug", it's normal dude
Because, the "dead" unit is dead (because got killed for the nearest unit) and when the caster doesn't change his spot to a new place (new alive unit doesn't gets registered as the "most nearest" location to the caster), that's what happen
We keep picking up the dead units over and over again
We try to "kill" a unit that has already dead
 
Status
Not open for further replies.
Top