[Trigger] Force Unit to do animation.

Status
Not open for further replies.
Level 2
Joined
May 12, 2020
Messages
10
Hey guys, i'm kinda having a problem with this ability im making called battle charge. So what the ability does is kinda like DotA's Barathrum but this time deals damage equak to my heros's strength and doesn't stun. I nailed the part where he charges to an enemy and damages it but the problem is, how do i get it to play it's walk animation? I already tried using SetUnitAnimationIndex but it doesn't play the animation. I also used Animation - Play unit animation and i've still got nothing. Can anyone pls help? Thx alot in advance!
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Here's a NON-Mui Charge ability I threw together. It uses "BlzPauseUnitEx" which is basically a Stun, resulting in the Pause effect without the unwanted side effects.

"BlzPauseUnitEx" is only available on the newer patches.

If you're on an older patch you can either Stun the Hero with a Dummy or use the old Pause function.
  • Cast Charge
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set VariableSet Charge_Unit = (Triggering unit)
      • Set VariableSet Charge_Target = (Target unit of ability being cast)
      • Set VariableSet Charge_Play_Animation = False
      • Set VariableSet Charge_Animation = 7
      • Set VariableSet Charge_Speed = 15.00
      • Custom script: call BlzPauseUnitEx(udg_Charge_Unit, true)
      • Trigger - Turn on Charge Loop <gen>
  • Charge Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • -------- Play Animation --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Charge_Play_Animation Equal to False
        • Then - Actions
          • Unit - Order Charge_Unit to Stop.
          • Set VariableSet Charge_Play_Animation = True
          • Custom script: call SetUnitAnimationByIndex(udg_Charge_Unit, udg_Charge_Animation)
        • Else - Actions
      • -------- --------
      • -------- Move --------
      • Set VariableSet Charge_Points[0] = (Position of Charge_Unit)
      • Set VariableSet Charge_Points[1] = (Position of Charge_Target)
      • Set VariableSet Charge_Angle = (Angle from Charge_Points[0] to Charge_Points[1])
      • Set VariableSet Charge_Points[2] = (Charge_Points[0] offset by Charge_Speed towards Charge_Angle degrees.)
      • Set VariableSet Charge_X = (X of Charge_Points[2])
      • Set VariableSet Charge_Y = (Y of Charge_Points[2])
      • Custom script: call SetUnitX(udg_Charge_Unit, udg_Charge_X)
      • Custom script: call SetUnitY(udg_Charge_Unit, udg_Charge_Y)
      • Unit - Make Charge_Unit face Charge_Angle
      • -------- --------
      • -------- End --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Charge_Unit is alive) Equal to False
              • (Charge_Target is alive) Equal to False
              • (Charge_Unit is hidden) Equal to True
              • (Charge_Target is hidden) Equal to True
              • (Charge_Unit is Stunned) Equal to True
              • (Distance between Charge_Points[0] and Charge_Points[1]) Less than or equal to 125.00
        • Then - Actions
          • -------- Unpause/Reset Animation --------
          • Custom script: call BlzPauseUnitEx(udg_Charge_Unit, false)
          • Animation - Reset Charge_Unit's animation
          • -------- --------
          • -------- Deal Damage --------
          • Special Effect - Create a special effect attached to the chest of Charge_Target using Abilities\Spells\Human\StormBolt\StormBoltMissile.mdl
          • Special Effect - Destroy (Last created special effect)
          • Unit - Cause Charge_Unit to damage Charge_Target, dealing ((Real((Strength of Charge_Unit (Include bonuses)))) x 2.00) damage of attack type Spells and damage type Normal
          • Unit - Order Charge_Unit to Attack Charge_Target
          • -------- --------
          • -------- Turn Off Loop --------
          • Trigger - Turn off (This trigger)
        • Else - Actions
      • -------- --------
      • -------- Clean Up --------
      • Custom script: call RemoveLocation (udg_Charge_Points[0])
      • Custom script: call RemoveLocation (udg_Charge_Points[1])
      • Custom script: call RemoveLocation (udg_Charge_Points[2])
Notice how I use "call SetUnitAnimationByIndex" AFTER 0.03 seconds has passed. This is because the animation that is forced to play whenever you cast a spell overrides SetUnitAnimationByIndex, that is unless you do it afterwards. If you try to use SetUnitAnimationByIndex inside the Cast Charge trigger you'll see it doesn't work. Ideally, you would use SetUnitAnimationByIndex after a 0.00 second timer, as this will fix the problem too.
 

Attachments

  • Basic Charge Example.w3m
    20.1 KB · Views: 26
Last edited:
Level 2
Joined
May 12, 2020
Messages
10
@WyrmSlayer i used the correct index. I'm using the over lord model and i wanted to do the walk animation so i put in '9' as the index.
@Uncle i'll give yours a shot.

Edit: I can't open it, it says missing data :/
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
You can always recreate exactly what I did. Just make sure to replace:
  • Custom script: call BlzPauseUnitEx(udg_Charge_Unit, true)
With the normal Action for Pausing/Unpausing a unit. The Custom script with true should be replaced with Pause and the one with false should be Unpause.

Or you can just do what I did to get the animation to work (use a short delay).
 
Last edited:
Level 2
Joined
May 12, 2020
Messages
10
You can always recreate exactly what I did. Just make sure to replace:
  • Custom script: call BlzPauseUnitEx(udg_Charge_Unit, true)
With the normal Action for Pausing/Unpausing a unit. The Custom script with true should be replaced with Pause and the one with false should be Unpause.

Or you can just do what I did to get your animation to work (use a short delay).
okays! I'll give it a shot...(i'll have one on the house)

Edit: Thanks alot guys! This really helped me alot. I just created my own and i solved thee problem. Thanks alot to u guys!!
 
Status
Not open for further replies.
Top