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

Unit in Range

Status
Not open for further replies.
Is there a way to make this event
  • Unit - A unit comes within 256.00 of Gryphon Rider 0000 <gen>
Usable with non-preplaced units? Say, for instance, that I have a summoned unit that knocks back enemy units that come within a distance of 200. Can I somehow make that specific event use a variable instead, and if so, how would I accomplish that?

Ideally I'd like to avoid using periodic timers to detect every 0.05 seconds or so if an enemy is within range in the event that I have *plenty* of those summoned units on the map.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
It is possible. You have to use in some trigger (e.g. map ini trigger) the following action:
  • Trigger - Add to *Your trigger* the event (Unit - A unit comes within 256.00 of (Triggering unit))
(triggering unit) is just an example here, it can be preplaced unit, function call or variable.

Do note that you can add events into trigger, but you cannot remove them - even if the unit in question no longer exists, there is still event for that unit. The longer the list of events for said trigger, the less efficient it is.

Another thing to note: With multiple "unit comes within range" events in one trigger, you have no idea to determine to which unit the (triggering unit) came to.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Event:
--- A unit enters entire map area (aka a unit enters the game)
Condition:
--- Unit type of entering unit equal to <YourUnitType>
Action:
--- Add to <YourTrigger> the event (Unit - A unit comes within 256.00 of (Entering unit))
(Same action as Nichilus described.)

However as Nichilus mentioned the problem about which unit is the one that you got in range of or the leak about the events that cannot be removed, I suggest you to use a JASS script to make dynamic triggers.
I will make it for you and will edit this post or make a new one when it is finished... (I guess I will have to start the editor anyway.)
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Ok here is what I have got.
I used the Unit Indexer because of the event of when a unit is created.
Saves work :D

It creates a dynamic event for every unit of a certain unit type for units that come in range of a certain distance.
Just take a look inside.
You should be able to rename all variables (as they should be changed in JASS as well automatically) and you can see the three variables in the configuration to set your range, unit type and trigger that has to run.
 

Attachments

  • DynamicEvent.w3x
    17.9 KB · Views: 30
Level 10
Joined
Apr 4, 2010
Messages
509
Periodic Triggers is the only way. I just tested with the "Unit Enterers Within Range" and it doesn't work.
EDIT: IT's not leakless btw, I made it quickly, It doesn't lag though. You can add the variables yourself and make it leakless.

Ok here is what I have got.
I used the Unit Indexer because of the event of when a unit is created.
Saves work :D

It creates a dynamic event for every unit of a certain unit type for units that come in range of a certain distance.
Just take a look inside.
You should be able to rename all variables (as they should be changed in JASS as well automatically) and you can see the three variables in the configuration to set your range, unit type and trigger that has to run.
Just looked at your test map, looks way too complex.
 

Attachments

  • Knockback.w3x
    17.6 KB · Views: 134
Last edited by a moderator:
Level 24
Joined
Aug 1, 2013
Messages
4,657
You are not supposed to look at it.
You are just supposed to copy and paste it into your map and set the unit type to the unit type of the summoned unit that needed that event.
And if that is too complicated... I cannot help you.

About your knockback map.
Never use an interval number lower than 0.03 There is no reason why you should even want it.
Also when checking if the group is empty... this only has to be done when a unit is removed (when he died).
It should also work, but I still recommend using the UnitInRange event.
 
Status
Not open for further replies.
Top