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

[Trigger] Having trouble with a knockback skill

Status
Not open for further replies.
Level 3
Joined
Nov 12, 2011
Messages
46
So I am trying to help Hera_ with her map by at least doing the coding for my own hero's skill first then work on the others. but i ran in to a problem with my second skill.

The skill is suppose to knockback the targeted unit. With the code im using it seems to only work the first time and then afterwards it moves the target unit to the center of the map, so can any of you help me?

  • Savage kick start
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Savage Kick [W]
    • Actions
      • Set KnockBackTarget = (Target unit of ability being cast)
      • Set KnockBackSpeed = 50
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Savage Kick [W] for (Triggering unit)) Equal to 1
        • Then - Actions
          • Set KnockBackDistance = 150
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Savage Kick [W] for (Triggering unit)) Equal to 2
            • Then - Actions
              • Set KnockBackDistance = 200
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Savage Kick [W] for (Triggering unit)) Equal to 3
                • Then - Actions
                  • Set KnockBackDistance = 250
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Savage Kick [W] for (Triggering unit)) Equal to 4
                    • Then - Actions
                      • Set KnockBackDistance = 300
                    • Else - Actions
      • Set Temp_Loc1 = (Position of (Triggering unit))
      • Set Temp_Loc2 = (Position of KnockBackTarget)
      • Set KnockBackAngle = (Integer((Angle from Temp_Loc1 to Temp_Loc2)))
      • Custom script: call RemoveLocation(udg_Temp_Loc1)
      • Custom script: call RemoveLocation(udg_Temp_Loc2)
      • Trigger - Turn on Savage Kick <gen>
  • Savage Kick
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Loc1 = (Position of KnockBackTarget)
      • Set Temp_Loc2 = (Temp_Loc1 offset by (Real(KnockBackSpeed)) towards (Real(KnockBackAngle)) degrees)
      • Unit - Move KnockBackTarget instantly to Temp_Loc2
      • Custom script: call RemoveLocation(udg_Temp_Loc1)
      • Custom script: call RemoveLocation(udg_Temp_Loc2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • KnockBackDistance Less than or equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Set KnockBackDistance = (KnockBackDistance - KnockBackSpeed)
Here is my revised code. It works pretty well in testing too.
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
1) Do not use waits for stuff like this.
While you say "0.01 seconds", it will in fact be something like 0.20 - 0.50 seconds. Not good if you want to make it look realistic.
It doesn't work because "Target unit of ability being cast" is forgotten after a wait.

2) Never use "Do Nothing". No exceptions.

3) You should remove the location leak (call RemoveLocation(udg_MoveTo)).
Also, read up on memory leaks.


For an actual knockback, you need 2 triggers: the initialization (determine which unit will get knocked back, how fast, the distance, angle and so on), and a periodic trigger that runs every 0.03 seconds that will move the unit.

If there is no need to make this spell MUI, then it isn't all that hard.
If you need an MPI-spell, it's slightly harder, and if it's MUI, then you might wanna grab a knockback-system from the hive :).
MPI / MUI explanation (if needed)


Here's how it looks for a normal spell (not MPI/MUI):
First Trigger: (setup)
  • Start Knockback
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Knockback
    • Actions
      • Set KnockbackTarget = (Target unit of ability being cast)
      • Set KnockbackSpeed = 30.00
      • Set KnockbackDistance = 500.00
      • Set TempLoc1 = (Position of (Triggering unit))
      • Set TempLoc2 = (Position of KnockbackTarget)
      • Set KnockbackAngle = (Angle from TempLoc1 to TempLoc2)
      • Custom script: call RemoveLocation(udg_TempLoc1)
      • Custom script: call RemoveLocation(udg_TempLoc2)
      • Trigger - Turn on Knockback Loop <gen>
Second trigger: (periodical, initially disabled)
  • Knockback Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set TempLoc1 = (Position of KnockbackTarget)
      • Set TempLoc2 = (TempLoc1 offset by KnockbackSpeed towards KnockbackAngle degrees)
      • Unit - Move KnockbackTarget instantly to TempLoc2
      • Custom script: call RemoveLocation(udg_TempLoc1)
      • Custom script: call RemoveLocation(udg_TempLoc2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • KnockbackDistance Less than or equal to 0.00
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Set KnockbackDistance = (KnockbackDistance - KnockbackSpeed)
To make the above triggers MPI, basically you should make all Knockback-variables into arrays (not the Temp-variables).
Add an additional variable: KnockbackEnabled. Set it to true when a player uses this ability (and to false when that ability ends).
Use the array's index as the player number (when Player 4 casts the ability, use KnockbackTarget[4]).

In the periodical trigger, loop from 1 to (number of players).
Check if KnockbackEnabled[LoopInt] equals to true.
The other actions remain about the same.
 
Level 3
Joined
Nov 12, 2011
Messages
46
Thanks for the help Maker and ap0calypse. Though ap0calypse you explanation is very long x.x

also im trying to limit the knock back distance to a certain number which is why im using one trigger. havent figured out how to do it with two triggers just yet.
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
Though ap0calypse you explanation is very long x.x

also im trying to limit the knock back distance to a certain number which is why im using one trigger. havent figured out how to do it with two triggers just yet.
I wouldn't call that a 'long' explanation :p.

You can try and copy the triggers from my previous post first, edit them to see how exactly they work, and then you can go and create the system you want (or at least try - nothing will happen if you don't at least try).
 
Level 3
Joined
Nov 12, 2011
Messages
46
I know, im using what you have explained to me. Though what i meant by long is that you explained a hell of a lot in a short area. it confused me for a bit. ill post the revised code of my skill in about 4 or 5 minutes and would like for you to take a look at it again.
 
Status
Not open for further replies.
Top