• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Couter bash 1.3

A spell I made some time ago now reuploaded to hive. it is MUI and should be leak free now.

the spell;
When unit is attacked there is a X chance to knockback the attacker


  • setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- creates a hashtable --------
      • Hashtable - Create a hashtable
      • Set CB_hash = (Last created hashtable)
      • -------- Settings --------
      • -------- Sets how long the unit will be knocked back --------
      • -------- note, index (array) = level of ability --------
      • Set CB_distance_setup[1] = 150.00
      • Set CB_distance_setup[2] = 200.00
      • Set CB_distance_setup[3] = 300.00
      • -------- Sets the chance to knock back a unit in % --------
      • Set CB_chance_to_knockback[1] = 5
      • Set CB_chance_to_knockback[2] = 10
      • Set CB_chance_to_knockback[3] = 20
      • -------- If the unit are knocked back into trees should they be destroied? --------
      • Set CB_BOOOM = True
      • -------- Effects --------
      • Set CB_effectOnCast = Abilities\Spells\Human\Polymorph\PolyMorphDoneGround.mdl
      • Set CB_effectOnLoop = Abilities\Weapons\AncientProtectorMissile\AncientProtectorMissile.mdl
  • cast
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Random integer number between 1 and 100) Less than or equal to CB_chance_to_knockback[(Level of |cffff0000Counter bash|r for (Triggering unit))]
    • Actions
      • Set CB_defender = (Triggering unit)
      • Set CB_attacker = (Attacking unit)
      • Set CB_attacked_loc = (Position of CB_defender)
      • Set CB_attacking_loc = (Position of CB_attacker)
      • Set CB_angle = (Angle from CB_attacked_loc to CB_attacking_loc)
      • Set CB_distance = (CB_distance_setup[(Level of |cffff0000Counter bash|r for CB_defender)] x 0.03)
      • Set CB_time = 1.00
      • Hashtable - Save CB_angle as 1 of (Key (Attacking unit)) in CB_hash
      • Hashtable - Save CB_distance as 2 of (Key (Attacking unit)) in CB_hash
      • Hashtable - Save CB_time as 3 of (Key (Attacking unit)) in CB_hash
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (CB_group is empty) Equal to True
        • Then - Actions
          • Trigger - Turn on loop <gen>
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CB_BOOOM Equal to True
        • Then - Actions
          • Unit - Turn collision for (Attacking unit) Off
        • Else - Actions
      • Unit Group - Add CB_attacker to CB_group
      • Sound - Play AxeMissile2 <gen> at 100.00% volume, attached to CB_attacker
      • Special Effect - Create a special effect attached to the chest of CB_attacker using CB_effectOnCast
      • Special Effect - Destroy (Last created special effect)
      • Unit - Pause CB_attacker
      • -------- removeing leaks --------
      • Custom script: call RemoveLocation(udg_CB_attacking_loc)
      • Custom script: call RemoveLocation(udg_CB_attacked_loc)
  • loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in CB_group and do (Actions)
        • Loop - Actions
          • Set CB_temp_unit = (Picked unit)
          • -------- loads the time from hashtable --------
          • Set CB_time = (Load 3 of (Key (Picked unit)) from CB_hash)
          • -------- if there is time left the trigger will continue else the unit will be stoped from the knock back --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CB_time Greater than 0.00
            • Then - Actions
              • -------- loads the angle and distance fromhashtable --------
              • Set CB_angle = (Load 1 of (Key (Picked unit)) from CB_hash)
              • Set CB_distance = (Load 2 of (Key (Picked unit)) from CB_hash)
              • -------- moves the unit a small distance every second makes it looks like hes knocked back --------
              • Set CB_temploc = (Position of (Picked unit))
              • Set CB_temploc_2 = (CB_temploc offset by CB_distance towards CB_angle degrees)
              • Unit - Move CB_temp_unit instantly to CB_temploc_2
              • Special Effect - Create a special effect at CB_temploc_2 using CB_effectOnLoop
              • Special Effect - Destroy (Last created special effect)
              • -------- stores the point of the picked unit --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • CB_BOOOM Equal to True
                • Then - Actions
                  • Destructible - Pick every destructible within 100.00 of CB_temploc_2 and do (Actions)
                    • Loop - Actions
                      • Destructible - Kill (Picked destructible)
                • Else - Actions
              • -------- saves the time left --------
              • Hashtable - Save (CB_time - 0.03) as 3 of (Key (Picked unit)) in CB_hash
              • Custom script: call RemoveLocation(udg_CB_temploc_2)
              • Custom script: call RemoveLocation(udg_CB_temploc)
            • Else - Actions
              • Unit Group - Remove CB_temp_unit from CB_group
              • Unit - Unpause CB_temp_unit
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in CB_hash
              • -------- removeing leaks --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • CB_BOOOM Equal to True
                • Then - Actions
                  • Unit - Turn collision for CB_temp_unit On
                • Else - Actions
              • -------- if group is empty the trigger turns off --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (CB_group is empty) Equal to True
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions


Keywords:
knock, back, spell, knock back, counter, bash
Contents

Counter Bash (Map)

Reviews
Approved A basic knockback retaliation spell that could benefit from additional polishing. Suggested changes The knockback speed could diminish over time Instead of pausing the unit, check that the unit is not already in the knockback group...

Moderator

M

Moderator

Reviewed by Maker, Counter bash 1.3, 11th Mar 2012

Approved

A basic knockback retaliation spell that could benefit from additional polishing.

Suggested changes
  • The knockback speed could diminish over time
  • Instead of pausing the unit, check that the unit is not already in the knockback group
    Spells should not really pause units
    You can also try to stun them instead
  • Add the bash chance to the tooltip
  • Disabled version of the icon is missing
  • The research icon should not be the passive version of the icon
  • You could use tree detection system, if BOOM = true it will destroy brisges also for example


Reviewed by Maker, Counter bash 1.2, 3rd Mar 2012

Required changes
  • Disabled icon is missing, passive abilities should have passive version of icons
  • In importing instructions you must mention that the ability used in cast trigger must be configured manually
    For both the condition and the distance
  • You need to flush child hashtable when the spell ends. Hashtable - clear child hashtable of picked unit
Suggested changes
  • Instead of pausing the unit, check that the unit is not already in the knockback group
  • Add the bash chance to the tooltip
  • You could use tree detection system
Reviewed by Maker, Counter bash 1.0, 25th Feb 2012

Required changes
  • Learn tooltip icon is missing
  • In importing instructions you must mention that the ability used in the
    condition in A unit is attacked trigger must be configured manually
  • Set loop initially off
  • Move unit instantly action has a location leak
  • You're setting position of picked unit twice in the looping trigger, set it only once
  • You need to flush child hashtable
  • Units can end up with their collision turned off after the spell is over
  • After moving a unit instantly, the unit can targets nearby enemies. Thus if the bash chance is high, the unit can be caught in a loop. You can push your enemy across the map this way
Suggested changes
  • Mention the hotkey in tooltip, add the chance to the tooltip
  • Change 0.04 to 0.03. 0.04 is not smooth. The knocback could use diminishing speed to make it look better
  • You could use tree detection system
  • Don't load distance and angle if time < 0
  • Abil level >= 1 condition is not needed, the other condition covers that
 
  • -------- THIS ACTION IS NOT NEEDED! --------
  • Hero - Learn skill for Paladin 0002 <gen>: |cffff0000Counter bash|r
Then put it in a different trigger :p

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • CB_BOOOM Equal to True
    • Then - Actions
      • Unit - Turn collision for (Picked unit) Off
    • Else - Actions
I think you mean "On".
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,182
fixed a few things.
-collision is now on again after the knockback is over
-learn skill action is in another trigger
-loop is initally off
-loop speed is changed to 0.03
-temploc is only set once in loop trigger
-removed one condition in the cast trigger
-added the learn hotkey in the learn desp
-location leak should be fixed (i think)
-unit is now paused to avoid attacking during the knock back
-animation speed reduce removed

more will be added but its all for now. will edit this post
 
Last edited:
  • Set CB_distance = (CB_distance_setup[(Level of |cffff0000Counter bash|r for CB_defender)] x 0.04)
You meant 0.03 right? :p

Also, this leaks:

  • Set CB_temploc = ((Position of (Picked unit)) offset by CB_distance towards CB_angle degrees)
You need two locations:

  • Set CB_temploc1 = (Position of (Picked unit))
  • Set CB_temploc2 = CB_temploc1 offset by CB_distance towards CB_angle degrees
Also, instead of constantly repeating that (Picked unit) call, you could store the picked unit into a unit
variable and use that variable to increase efficiency.

edit
You can do the same for Key(Picked unit), Key(Attacking unit), (Attacking unit), etc..
You can do it for ANYTHING that is used more than once :p
 
Level 9
Joined
May 25, 2021
Messages
328
I found 2 issues: 1. Units are being knockbacked through doodads & terrain. 2. Range attackers & Building attackers are also able to be knockbacked. And it is inappropriate, don't you think? What if I want my hero only bash counters melee attackers? And what if I want units who were pushed back to be stunned if they hit a doodads?

How should I modify your spell?
 
Last edited:
Level 38
Joined
Feb 27, 2007
Messages
4,951
Range attackers & Building attackers are also able to be knockbacked.
You can add any conditions you want to the "cast" trigger, using the attacked/attacking units and anything else.
I want units who were pushed back to be stunned if they hit a doodads?
The part of the "loop" trigger that kills destructibles can be used to stun the unit being moved. I would dummy cast an invisible, quick storm bolt at the moved unit.
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • CB_BOOOM Equal to True
    • Then - Actions
      • Destructible - Pick every destructible within 100.00 of CB_temploc_2 and do (Actions)
        • Loop - Actions
          • Destructible - Kill (Picked destructible)
    • Else - Actions
Changed to:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • CB_BOOOM Equal to True
    • Then - Actions
      • Set TempBool = False
      • Destructible - Pick every destructible within 100.00 of CB_temploc_2 and do (Actions)
        • Loop - Actions
          • Destructible - Kill (Picked destructible)
          • Set TempBool = True
      • If - Conditions
        • TempBool Equal to True
      • Then - Actions
        • Set TempPoint = (Position of CB_temp_unit)
        • Unit - Create 1 DUMMY CASTER for (Owner of CB_temp_unit) at TempPoint facing Default building facing degrees
        • Unit - Add STORM BOLT ABILITY to (Last created unit)
        • Unit - Add a 1.00 second generic expiration timer to (Last created unit)
        • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt CB_temp_unit
      • Else - Actions
    • Else - Actions
In my opinion, the cast trigger has a shitty event; A Unit is Attacked sucks and can be abused. Instead you want to use a damage detection system that can tell you when a unit did an attack. This one I would recommend can differentiate between a melee attack and a ranged attack, or if damage was caused by an ability or by code ordering the unit to deal damage. You would then need to change the following lines in the cast trigger:
  • Events
    • Game - DamageEvent becomes Less than or equal to 0.00 //runs only for melee attacks
  • Conditions
    • (DamageEventSource is a Building) equal to False //if you want it not to work for structures either
    • (Level of COUNTER BASH ABILITY for DamageEventTarget) greater than 0 //this line isn't in the spell but it should be so that this only triggers for units that have the counter bash ability
  • Actions
    • Set CB_defender = DamageEventTarget //change these two lines
    • Set CB_attacker = DamageEventSource
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
Think about it. You are trying to stop the knockback from occurring at all when the attacked unit is of those types. That would be filtering them out at the trigger conditions level because nothing should happen unless the target isn't a building/flyer.
 
Top