• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Most efficient way to check if a unit is in range?

Status
Not open for further replies.
Level 8
Joined
Oct 3, 2008
Messages
189
Hi everyone,

so I'm making a spell that drops an orb when it hits the target. The caster can walk near the orb to automatically consume for a beneficial effect.

Now I was wondering, how do you best handle this? Right now I'm using the "specific unit comes within range of unit" event, and adding a new event to it whenever a new orb gets created. I'm a bit concerned that there might be a limited amount of events that can be added to a trigger or another problem?

The alternative is using a periodic event to check whether the caster is within range of the orb, but there my worry is that this might be a lot more resource intensive?

Any thoughts?
 
Now I was wondering, how do you best handle this? Right now I'm using the "specific unit comes within range of unit" event, and adding a new event to it whenever a new orb gets created. I'm a bit concerned that there might be a limited amount of events that can be added to a trigger or another problem?
Events can leak if used like that. However one can solve it by creating a unique trigger per orb, or periodically destroying and recreating the trigger. Destroying a trigger also destroys all attached events.
 
i have something like that in my map. The "orb" in my case is a unit with no movement. The unit has a spell based on heal, set to autocast. there's a trigger that destroys the unit after casting the heal. the unit also has an expiration timer that's added at the time it gets created.
 
Events can leak if used like that. However one can solve it by creating a unique trigger per orb, or periodically destroying and recreating the trigger. Destroying a trigger also destroys all attached events.

Having a bunch of triggers around for units that no longer exist would occupy no memory or would the intent be to still destroy the trigger after the unit expires / is picked up?
 
Having a bunch of triggers around for units that no longer exist would occupy no memory or would the intent be to still destroy the trigger after the unit expires / is picked up?
Having a bunch of triggers around for units that no longer exist does occupy memory and handle ID numbers. A typical memory/resource leak.

One could create a trigger per unit and then destroy that trigger when the unit gets removed (you can detect this using the shield ability of the footman, it issues an unshield order when a unit is being removed). Destroying triggers is safe as long as the trigger is not scheduled for execution when it is destroyed.

This requires using JASS directly because of GUI lacking functionality.
 
Out of curiosity, what's wrong with "unit enters region" and "check if a unit has a buff"?
 
Out of curiosity, what's wrong with "unit enters region" and "check if a unit has a buff"?
Quite complex to program and basically results in similar code to a unit enters X of unit approach.

The regions need to be created, events for them created, after the orb is removed both need to be destroyed meaning dynamic trigger destruction/recreation.
 
Status
Not open for further replies.
Back
Top