- Joined
- Jul 30, 2012
- Messages
- 156
So, I was looking for a way to cast attack-modifier spells from a dummy unit, without requiring 1 dummy for every target. For that I would need to make a unit that can attack instantly. Although I didn't succeed with that, I found something interesting.
The trick is to order the unit to cast an arrow ability and then remove that ability on the SPELL_CHANNEL event:
Then, you just need to call IssueTargetOrderById(Attacker, ORDER_ID, Target) and your unit will make an instant attack. After that, you can re-add the arrow ability if you plan to use it again.
By "instant" I mean that the attack will be finished before the next line of code. If it's a ranged unit, it will instantly fire the projectile. If it's a melee attacker, the damage will be dealt immediately.
The instant attack does not have any cooldown by itself. You can make a unit attack multiple times from a single function in your code. However the instant attack does not work if the unit's regular attack is already on cooldown.
Unfortunately this attack will not carry any attack modifiers present on the unit, except for lifesteal. So it does not work for my needs, but it might be useful for somebody else.
Also remember that the attacker must be facing the target, else it will not be instant. (Units that can't move don't have this restriction.)
The trick is to order the unit to cast an arrow ability and then remove that ability on the SPELL_CHANNEL event:
JASS:
constant integer ARROW_ID = 'AHfa'
constant integer ORDER_ID = 852173 //OrderId("flamingarrowstarg")
function OnSpellChannel takes nothing returns boolean
if GetSpellAbilityId() == ARROW_ID then
call UnitRemoveAbility(GetTriggerUnit(), ARROW_ID)
endif
return false
endfunction
function OnInit takes nothing returns nothing
trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CHANNEL)
call TriggerAddCondition(t, Condition(function OnSpellChannel))
set t = null
endfunction
Then, you just need to call IssueTargetOrderById(Attacker, ORDER_ID, Target) and your unit will make an instant attack. After that, you can re-add the arrow ability if you plan to use it again.
By "instant" I mean that the attack will be finished before the next line of code. If it's a ranged unit, it will instantly fire the projectile. If it's a melee attacker, the damage will be dealt immediately.
The instant attack does not have any cooldown by itself. You can make a unit attack multiple times from a single function in your code. However the instant attack does not work if the unit's regular attack is already on cooldown.
Unfortunately this attack will not carry any attack modifiers present on the unit, except for lifesteal. So it does not work for my needs, but it might be useful for somebody else.
Also remember that the attacker must be facing the target, else it will not be instant. (Units that can't move don't have this restriction.)
Last edited: