• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Detecting attack modifiers like searing arrows

Level 6
Joined
Jul 3, 2006
Messages
102
Is there a way to detect when a unit is using auto-cast attack modifiers like searing arrows on a target? On manual cast this is caught by the SPELL_EFFECT event, but not when it is set to auto-cast.
 
No, there is not an out-of-box way. You can kind of determine that doing the following:
  • Detect when unit is 'issued order with no target' to detect when player turns auto-cast on and off (e.g. for searing arrows it is 'flamingarrows' when turned on and 'unflamingarrows' when turned off).
  • Track the auto-cast on/off state yourself in a variable/array.
  • Make a trigger that listens to 'Unit is attacked' event. Check that attacker is the unit with auto-cast. Check your variables to see if auto-cast for the unit is on, if attacker has enough mana to cast the spell and if the spell is off cooldown.
  • Optionally also check if target flags match (e.g. if the auto-cast can only be cast on organic units, then check if the target is not mechanical and not structure).
  • If all above passed, you can assume that the unit will auto-cast the spell.

For even more precise detection, you could still use the 'Unit is attacked' event, do some preliminary checks, but then wait until time set in "Combat - Attack N - Animation Damage Point" has passed when you check for unit's mana.
For example, Priestess of the Moon has 0.3 set in her "Animation Damage Point", meaning when "Unit is attacked" event is fired, an additional 0.3 seconds have to elapse before she actually shoots her arrow. It is possible that during that time some enemy unit could mana drain her and so when she actually shoots her arrow, it would not have an orb effect on it.
 
  • Detect when unit is 'issued order with no target' to detect when player turns auto-cast on and off (e.g. for searing arrows it is 'flamingarrows' when turned on and 'unflamingarrows' when turned off).
  • Track the auto-cast on/off state yourself in a variable/array.
I may be able to do this with just this advice, thanks.

This is actually a skill that does not a have a mana cost, but I have a health cost via triggers which I check before cast and cancel the cast by issuing a stop command. So with a bit of trickery I might be able to do it. Quick a lot of hassle in any case.
 
In that case you could just disable the ability on unit, but keep it visible, like so:
  • Unit - For (Triggering unit), Ability Searing Arrows, Disable ability: True, Hide UI: False
So any time unit does not have enough health to cast the spell, disable the ability. Whenever unit has more health, enable it.

Or you could modify the ability in Object Editor: create a new unit and name it 'Must have at least XY health.'. Find the ability in object editor, open up its 'Techtree - Requirements' field and set the 'Must have at least XY health' unit-type there as requirement. Now your hero won't be able to cast the spell unless the player owns such unit. In UI it will display as:
1766850602041.png

So the idea is to give player the 'Must have at least XY health' unit when caster has enough health to auto-cast the spell and remove the unit when caster does not have enough health.
 
Just for the record, there is a much easier and consistent way I found here and it is based on Poison Arrows and on the fact that when an attack with the modifier deals damage, it also places a debuff that you can detect.
 
From what I understand in that linked thread, their solution detects if unit was damaged by an orb effect. You mentioned that this ability has health cost instead of mana cost, so it is something that should be detected before arrow is being shot.

If you use the linked solution, it will look like this:
1. caster shoots enchanted arrow
2. arrow flies towards target over some time
3. arrow hits target, caster's health is decreased

Second step will have variable length depending on projectile speed and distance between caster and target. It could take a second for the projectile to reach the target. Meaning the health cost would be delayed as well. During that time the caster may shoot another arrow, stacking the health cost to levels where you would normally not allow the ability to be cast.

----
On a side note, that thread is very old - their solution is using dynamically created and destroyed triggers to detect when any unit is damaged, because at that time there was only "<specific unit> is damaged" event. Nowadays we have "any unit is damaged" events, so you can have a single GUI trigger.
 
It fits because this is actually a melee unit, I just had to increase its range a little bit to make poison arrows work. Health check is done on damage, and depending on the result the attack gets the effect or not.

Of course I am using a damage detection system, I just wanted to highlight that it is possible to detect orb effects by the debuff on the damage event.
 
Back
Top