• 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.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

[Trigger] Detecting ranged unit shooting?

Status
Not open for further replies.
Level 30
Joined
Jul 23, 2009
Messages
1,033
I am trying to make an ammunition system for a ranger unit in my map and for that I need a function that deducts an arrow for each auto attack. The problem lies with the way of detecting it because if I choose to detect a unit attacking it will cause you to lose ammo if you start an attack but then cancel it.

Does anyone know how to work around this?

I have a last resort idea that I would prefer not to use.

I have the ranged unit's attack type as instant and intercept the damage with a damage engine reducing it to 0. I then detect the unit taking damage (technically) and deduct an arrow from the unit. Then to get the projectile and actual damage I spawn a dummy unit with 0 attack windup time to attack the target. As I said I would prefer if there is another way.
 
Level 30
Joined
Jul 23, 2009
Messages
1,033
Use a damage detection system.

Thanks for the reply but that will not benefit me in this situation. That means the ranger will be deducted an arrow first when it hits meaning if it shoots an arrow when havin 1 arrow left and then starting another attack before the earlier one lands it gets to shoot an attack without having an arrow. Do you understand the problem?
 
I haven't tried this yet, but I think it should be possible to just use a dummy ability based on POTM fire arrows, enabled by default at 0 mana cost. Then you can detect a cast event on any attack.
To hide the ability, simply put it in a disabled spellbook.

However, this method will not work anymore as soon as you use any other autocast missile ability like frost arrows.


Btw, what's wrong with the "Unit gets attacked" event?
 
Level 19
Joined
Dec 12, 2010
Messages
2,070
im using pure jass, no systems. here are global trigger which register any unit attack. then create trigger for attacker, waiting for damage event happens on target or 10 seconds pass. Trigger's handle stored inside attacker, so every new attack won't create new trigger but retrieve this one, restarting countdown timer. Every next attack increase counter of "shots fired" by 1.
When target damaged by this unit, do the stuff and reduce "shots fired" by 1. Once it reaches 0 - destroy trigger and clear it's memory.

downsides - fast shooting will allows to shoot arrows up to negative arrow counter, cause' shot will be registered only on hit. That could take time. Also evasion will fuckup counter.

Timer needed to compensate slow attack speed and projectile flying time.

In case if you cares about few units only you could make a table with their Attack point (AP) values. Then on attack event check with timer if unit's order isnt changed for AP*(Attack Speed) seconds, and if its still attack - shot just happened.

Anyway, detecting the moment when projectile flew out - is the hardest thing
 
Level 30
Joined
Jul 23, 2009
Messages
1,033
I haven't tried this yet, but I think it should be possible to just use a dummy ability based on POTM fire arrows, enabled by default at 0 mana cost. Then you can detect a cast event on any attack.
To hide the ability, simply put it in a disabled spellbook.

However, this method will not work anymore as soon as you use any other autocast missile ability like frost arrows.


Btw, what's wrong with the "Unit gets attacked" event?

I will try that fire arrow thing. The Unit gets attacked counts when the unit is in range to perform an auto attack and starts winding it up. Therefore if I use this event and the unit cancels the attack before it fires it will run the trigger without the unit actually firing an attack. :thumbs_down:
 
I will try that fire arrow thing. The Unit gets attacked counts when the unit is in range to perform an auto attack and starts winding it up. Therefore if I use this event and the unit cancels the attack before it fires it will run the trigger without the unit actually firing an attack. :thumbs_down:
I see your problem now. But yeah, I think fire arrow will do the trick in this case, as it allows you to attach your ammo decrement to when the missile starts, not just when the attack anim begins.
 
Status
Not open for further replies.
Top