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

[Solved] Detecting Units Not in Range

Status
Not open for further replies.
Level 37
Joined
Jul 22, 2015
Messages
3,485
I have this spell that adds a debuff to enemy units inside the region, and then removes it the moment they leave the region. Removing units who leave the region was an easy thing, heres a snippet of the trigger:
  • -------- --------
  • -------- checking for units inside the radius --------
  • Set VL_Group = (Units within VL_AoE[VL_AbilityLevel[VL_CurrentIndex]] of VL_CasterLoc[VL_CurrentIndex])
  • Unit Group - Pick every unit in VL_Group and do (Actions)
    • Loop - Actions
      • Set VL_PickedUnit = (Picked unit)
      • Set VL_PickedUnitLoc = (Position of VL_PickedUnit)
      • -------- --------
      • -------- keeping track of distance so buff can properly be removed --------
      • Set VL_Distance = (Distance between VL_PickedUnitLoc and VL_CasterLoc[VL_CurrentIndex])
      • ~~~ ~~~
      • ~~~applying debuff to enemy unit block~~~
      • ~~~ ~~~
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • VL_Distance Greater than VL_AoE[VL_AbilityLevel[VL_CurrentIndex]]
          • (VL_PickedUnit has buff VL_Buff) Equal to True
        • Then - Actions
          • Unit - Remove VL_Buff buff from VL_PickedUnit
          • Unit Group - Remove VL_PickedUnit from VL_EnemyGroup[VL_CurrentIndex]
        • Else - Actions
          • -------- continue with spell --------
      • -------- --------
      • -------- removing location leak --------
      • Custom script: call RemoveLocation (udg_VL_PickedUnitLoc)
  • -------- --------
  • -------- removing group leak --------
  • Custom script: call DestroyGroup (udg_VL_Group)

However, the problem with this method is that it won't properly remove the debuff when units instantly teleport away from the region (ex: blink). Is there a better way of detecting units who leave a certain radius, or do I need to add an extra function somewhere? Here's the full set of triggers if anyone needs it.


Things about the spell: Its instant cast and the caster CANNOT move during the channel.
 
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
1) Have two unit groups and two "count" integer variables
2) First group is the initial cast. Assign a count variable to track how many are here
3) Second group is used to scan the area during the loop and count the units with the second count variable. If count changes or one of the unit doesn't have the buff (which, of course means a unit left and a new one took its place), then:
4) Remove all units in the second group from group 1. The ones who are still in group 1 left the radius and you run your stuff here.
 
Level 10
Joined
Apr 4, 2010
Messages
509
I think you have to divde the VL_Distance by 2. If the AoE is 300. It's 150 all around the point. So VL_Distance is 300 away from the point. I'm not too sure though.

  • If - Conditions
  • VL_Distance Greater than (VL_AoE[VL_AbilityLevel[VL_CurrentIndex]] / 2)
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
1) Have two unit groups and two "count" integer variables
2) First group is the initial cast. Assign a count variable to track how many are here
3) Second group is used to scan the area during the loop and count the units with the second count variable. If count changes or one of the unit doesn't have the buff (which, of course means a unit left and a new one took its place), then:
4) Remove all units in the second group from group 1. The ones who are still in group 1 left the radius and you run your stuff here.

Hmm that makes sense, but you know how I am with that saying, Bribe ;D I will try it out when I get home tonight.

I think you have to divde the VL_Distance by 2. If the AoE is 300. It's 150 all around the point. So VL_Distance is 300 away from the point. I'm not too sure though.

  • If - Conditions
  • VL_Distance Greater than (VL_AoE[VL_AbilityLevel[VL_CurrentIndex]] / 2)

Why would I want to divide the radius by 2? I want to remove the buff when they get outside of VL_AoE, not when they're still inside it.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
I see no reason why it would not remove if the unit teleports. Next time the snippet runs it should detect the unit being out of range after the teleport so remove the buff.

Sorry DSG, I forgot to add two pretty important actions... I destroy the group immediately after. Will update it hold on.

EDIT: Bribe's suggestion worked! Thank you all.
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
  • Set VL_Group = (Units within VL_AoE[VL_AbilityLevel[VL_CurrentIndex]] of VL_CasterLoc[VL_CurrentIndex])
  • Unit Group - Pick every unit in VL_Group and do (Actions)
    • Loop - Actions
      • Set VL_Distance = (Distance between VL_PickedUnitLoc and VL_CasterLoc[VL_CurrentIndex])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • VL_Distance Greater than VL_AoE[VL_AbilityLevel[VL_CurrentIndex]]
          • (VL_PickedUnit has buff VL_Buff) Equal to True
Today, I lost faith in mankind... again.

Give me one single reason why this condition would ever be true.
I dare you.

You should make a periodic timer that will check the distance between the caster (or the position of the caster at the Spell Effect moment) and if that is bigger than the AoE radius, then you remove the buff and remove them from the group.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Today, I lost faith in mankind... again.

Give me one single reason why this condition would ever be true.
I dare you.

You should make a periodic timer that will check the distance between the caster (or the position of the caster at the Spell Effect moment) and if that is bigger than the AoE radius, then you remove the buff and remove them from the group.

First off, that method worked if the target just walked out of range. If you read carefully, I said it only didnt work when the target teleported out. Bribes suggestion fixed it. Second, why the fuck do you have to be such an ass about it? I just asked for help and overlooked a simple mistake. I apologize for not being great at triggers like you, but we all start somewhere.

Pre-filtering for all units in range and expecting one to be out of range...

I made the assumption that the group was created and updated on casts. Guess I need to read more carefully in future.

It was a simple mistake. Sorry for wasting your time.
 
Status
Not open for further replies.
Top