• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[Trigger] Unit notice a target in range

Status
Not open for further replies.
Is there a leak free way to use this event response?
I want an AI controled unit to automaticaly use a certain ability when a target is in range.
With some abilities AI automaticaly cast it when engaging fight like "finger of death" but some other AI never use the ability like "Acid bomb".
So I made a trigger using "unit notice a target in range" to force them to use abilities but I think it leak because I use "add event to trigger".
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,239
Is there a leak free way to use this event response?
Yes there should be. Unless the internal code is bugged and leaks.

So I made a trigger using "unit notice a target in range" to force them to use abilities but I think it leak because I use "add event to trigger".
You will need to switch to pure JASS to do it. Events are destroyed when the trigger they register is also destroyed. The unit specific event is not destroyed when the unit it binds to is destroyed. As such to prevent leaks you need to destroy the trigger every so often and re-register all events and actions. This is how a damage detection system does it.

An alternative would be a staggered polling approach. As long as at least 1 of those AI controlled units exists you periodically check all units near it and run your AI logic. By staggering this check it will scale very will however the AI will start to perform poorly (decision latency) when there are a lot of such units on the map.
 
It's in 2 trigger
  • Enter Battlefield
    • Events
      • Unit - A unit enters Entire Battlefield <gen>
    • Conditions
      • (Unit-type of Triggering Unit) Equal to AcidBombUser
    • Actions
      • Trigger - Add to Acidbomb use ability <gen> the event (Triggering Unit Notices a target in range)
  • Acidbomb use ability
    • Events
    • Conditions
    • Actions
      • Unit - Order (Triggering unit) to Neutral Alchemist - Acid Bomb (Targeted unit)
So yes it create a new event to the trigger for each AcidBombUser entering the map making the trigger bigger and bigger.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,239
So yes it create a new event to the trigger for each AcidBombUser entering the map making the trigger bigger and bigger.
No, the trigger stays the same.
You do however create more and more event objects which can count as a leak if any of the units are removed.
GUI is confusing sadly, this is why most people recommend using JASS.

If you really cannot use a pure JASS solution, then I advise the staggered polling approach I mentioned above.
 
Status
Not open for further replies.
Top