• 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.

[Snippet] Making a unit attack instantly

Status
Not open for further replies.
Level 9
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:

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:
Level 12
Joined
Mar 13, 2012
Messages
1,121
Interesting.
You can get rid of this restriction by setting a unit's prop window to 360, or removing its movement
If the normal rules apply setting prop window to 360 will not solve it, as prop window only is at which facing angle to a target a unit starts to move (after it was decided that moving is required to cast the spell/attack/move to the target)

With removing its movement you mean setting base movement speed to 0 probably.
 
Te best stun snippet is one that forces the unit to channel indefinitely, and then can be un-issued afterward, with triggers. No dummy unit involved.

http://www.hiveworkshop.com/forums/jass-resources-412/snippet-suspendunit-266681/
The problem is that it issues a "defend" order, so if you use any custom defend abilities in your map (which is very common, since defend is a nice way to generate "toggle" abilities that don't interrupt unit movement), this way to stun the unit might mess up your toggle state.

The good thing about regular stuns is that they can be issued from the outside.
 
The problem is that it issues a "defend" order, so if you use any custom defend abilities in your map (which is very common, since defend is a nice way to generate "toggle" abilities that don't interrupt unit movement), this way to stun the unit might mess up your toggle state.

The good thing about regular stuns is that they can be issued from the outside.

He and I both clarified in the thread that it does not interfere with the defend ability. Had you tested the map instead of making assumptions, you would have seen the Footman did have a defend ability, but it wasn't affected by it. It works because the issue order native affects only the most-recently added ability.

Since this can also target invulnerable, magic immune and ethereal, this is the most reliable method to disable a unit.
 
Level 9
Joined
Jul 30, 2012
Messages
156
Interesting.
You can get rid of this restriction by setting a unit's prop window to 360, or removing its movement

If the normal rules apply setting prop window to 360 will not solve it, as prop window only is at which facing angle to a target a unit starts to move (after it was decided that moving is required to cast the spell/attack/move to the target)

With removing its movement you mean setting base movement speed to 0 probably.

Yes, it seems that I was wrong, prop window doesn't really help with that problem. I didn't really test it, it just came to my mind by the time I was writing, and I thought that it could help, but it doesn't.

So the only solution is to disable the unit's movement, either by setting base MS to 0, or removing 'Amov' in game. Alternatively, you can use my [post=2778019]AbilitySilence[/post] library, and call SetUnitAbilitySilenced(Attacker, 'Amov', true), to disable a unit's movement temporarily.

Btw, this concept isn't new. I've been using a stun snippet for years already (I think this one was made by anitarf or Jesus4lyf back on my TheHelper days?) that is using a 100% bash ability that uses a similar trick to make the stun execute before the next line of code.

Could you please point me to this snippet? I've always been looking for something like that and I never found it. A quick search in TheHelper didn't show me that. What did they use to make the attack instant? Is it the same trick I found?
Mass Teleport is fine, war stomp is bad for the terrain deformation.

Mass Teleport is definitely not good. At first, it's not even a stun, it just calls CUnit::SilenceEx on the target unit (check the [thread=274351]guide about Silence[/thread]). This has many implications, it interrupts the unit's order queue (a stun is supposed to keep the unit's orders after the stun ends), and you can't issue any new orders, because all abilities are disabled. It also has the problem of unit aggro: enemies of the stunned unit will never attack it, unless it's the only enemy nearby. And because it's a channeling spell, it requires 1 dummy for every target.
 
He and I both clarified in the thread that it does not interfere with the defend ability. Had you tested the map instead of making assumptions, you would have seen the Footman did have a defend ability, but it wasn't affected by it. It works because the issue order native affects only the most-recently added ability.
I haven't read the thread until the end back when it was posted. But it still triggers a spellcast event on the unit, right?

Since this can also target invulnerable, magic immune and ethereal, this is the most reliable method to disable a unit.
Invulnerable makes it interesting. Magic immune and ethereal is not a problem with other stun methods either.
Then again, the stun snippet I'm using seems to have no problem with invulnerability either. Dunno why.

It doesnt have terrain deformation on my maps.
It's still a huge resource eater, even with the terrain deformation zeroed.
Could you please point me to this snippet? I've always been looking for something like that and I never found it. A quick search in TheHelper didn't show me that. What did they use to make the attack instant? Is it the same trick I found?
I haven't found it on helper either...
I'll check out the map script when I get home and post it here. I think he used a Pause/Unpause trick for it and not a searing arrow ability.
 
Status
Not open for further replies.
Top