[Spell] Need some advice with Counter attack.

Status
Not open for further replies.
Level 7
Joined
Apr 26, 2015
Messages
125
Hey there, I'm working on a counter attack ability where when the Hero is a Attacked, he has a chance to counter.
So far I got it set up alright, I think...however when the Hero is attacked I want him to play his Attack Slam animation....
It works some times, but if I move the hero as he counters, or if he's busy attacking, or using an item it doesn't always play his animation :/
Is there away I can make it so he's forced to play his animation?

Here's how I set up my trigger in the image :p I'm still learning when it comes to custom spells XD

Well, i'm off for a little walk, I hope everyone is doing well during the great toilet paper shortage of 2020!
 

Attachments

  • Counter.png
    Counter.png
    65.4 KB · Views: 44
Level 12
Joined
Jan 30, 2020
Messages
875
Hello there,

Have you tried ordering the unit to stop before playing the animation ?
Probably better to order to stop after the 0.5s wait as applying immediate orders without delay can bug a lot.

Hope this helps.
 

Uncle

Warcraft Moderator
Level 69
Joined
Aug 10, 2018
Messages
7,240
You can save yourself a lot of hassle if you incorporate some variables into your setup. Also, the method you're attempting to use is rather flawed. But if you really want it to work that way then you could Pause the Hero before playing those animations and then Unpause after the 0.50 second wait. An alternative to pause would be Stunning the hero, although there will be a delay before the stun happens that you will have to account for.

Otherwise, here's a Counter Attack ability I threw together just now that I think works great:
First we declare our variables. This is where we set the Counter Chance and Counter Damage per level.
Variable Types:
Counter_Chance = Integer (Array)
Counter_Dmg = Real (Array)
  • Anthon Counter Attack Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- The number in the [ ] represents the level of the ability --------
      • -------- --------
      • -------- Counter Chance --------
      • Set VariableSet Counter_Chance[1] = 1
      • Set VariableSet Counter_Chance[2] = 2
      • Set VariableSet Counter_Chance[3] = 3
      • Set VariableSet Counter_Chance[4] = 4
      • Set VariableSet Counter_Chance[5] = 5
      • Set VariableSet Counter_Chance[6] = 6
      • Set VariableSet Counter_Chance[7] = 7
      • Set VariableSet Counter_Chance[8] = 8
      • Set VariableSet Counter_Chance[9] = 9
      • Set VariableSet Counter_Chance[10] = 10
      • -------- --------
      • -------- Counter Damage --------
      • Set VariableSet Counter_Dmg[1] = 20.00
      • Set VariableSet Counter_Dmg[2] = 30.00
      • Set VariableSet Counter_Dmg[3] = 50.00
      • Set VariableSet Counter_Dmg[4] = 70.00
      • Set VariableSet Counter_Dmg[5] = 100.00
      • Set VariableSet Counter_Dmg[6] = 250.00
      • Set VariableSet Counter_Dmg[7] = 350.00
      • Set VariableSet Counter_Dmg[8] = 500.00
      • Set VariableSet Counter_Dmg[9] = 800.00
      • Set VariableSet Counter_Dmg[10] = 1000.00
We only need 1 Counter Attack trigger. This trigger can then reference the variables we created in our Counter Attack Setup trigger.
Variable Types:
Level = Integer
  • Anthon Counter Attack
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Level of Counter Attack for (Attacked unit)) Greater than or equal to 1
      • ((Attacking unit) is A melee attacker) Equal to True
    • Actions
      • -------- Get The Level Of Counter Attack --------
      • Set VariableSet Level = (Level of Counter Attack for (Attacked unit))
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 0 and 10) Less than or equal to Counter_Chance[Level]
        • Then - Actions
          • -------- Deal Damage --------
          • Unit - Cause (Attacked unit) to damage (Attacking unit), dealing Counter_Dmg[Level] damage of attack type Chaos and damage type Normal
          • -------- --------
          • -------- Counter Special Effect --------
          • Set VariableSet Point = (Position of (Attacked unit))
          • Special Effect - Create a special effect at Point using units\human\HeroPaladin\HeroPaladin.mdl
          • Special Effect - Set Yaw of (Last created special effect) to: ((((Facing of (Attacking unit)) + 180.00) x Pi) / 180.00)
          • Special Effect - Set Color of (Last created special effect) to color of (Owner of (Attacked unit))
          • Special Effect - Set Alpha of (Last created special effect) to 127
          • Special Effect - Play Special Effect: (Last created special effect), Animation: Attack
          • -------- --------
          • -------- Destroy The Special Effect After 1.00 Second --------
          • Trigger - Run Arthon Counter Destroy Sfx <gen> (ignoring conditions)
          • -------- --------
          • -------- Clean Up Leaks --------
          • Custom script: call RemoveLocation (udg_Point)
        • Else - Actions
This trigger is a bit confusing I know. We're using a trick called Shadowing Globals that turns a global variable into a local variable. This gets around the issue of using Waits and global variables that you'd normally run into. Note that we run this trigger from the Anthon Counter Attack trigger. This is actually pretty neat because by doing it this way the Wait 1.00 second isn't actually applied inside the Anthon Counter Attack trigger, meaning that it won't delay our other Actions.
local udg_
Things You Should Know When Using Triggers / GUI
  • Arthon Counter Destroy Sfx
    • Events
    • Conditions
    • Actions
      • Custom script: local effect udg_Counter_Sfx = GetLastCreatedEffectBJ()
      • Wait 1.00 seconds
      • Special Effect - Set Height of Counter_Sfx to: 5000.00
      • Special Effect - Destroy Counter_Sfx
      • Custom script: set udg_Counter_Sfx = null
 

Attachments

  • Counter Example.w3m
    20.2 KB · Views: 21
Last edited:
Status
Not open for further replies.
Top