[Spell] Execute ability

Status
Not open for further replies.
Level 4
Joined
Jan 6, 2023
Messages
33
I was scrolling through functions of integers and stuff but havent seen what I am looking for. I want to make an Execute ability that would be possible to use on targets with 35% health remaining.
(Also I'd be glad if someone would be kind to show me how to set triggers to have levels of ability since I don't know how to do it yet. Like 1level: 35%health required to use, 40sec cooldown, doing 10%damage of max enemy health. Level 2: 40%health, 35sec cd, doing 15%damage of max enemy health)
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,860
Your explanation is somewhat vague so I'm going to assume that you want something like Axe's ultimate ability from DotA where it either damages or instantly kills the target unit.

Your trigger needs to use Arithmetic and incorporate the Level of the ability into the calculations:
  • Execute
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Execute
    • Actions
      • Set VariableSet Caster = (Triggering unit)
      • Set VariableSet Target = (Target unit of ability being cast)
      • Set VariableSet Level = (Level of (Ability being cast) for Caster)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Percentage life of Target) Less than or equal to (30.00 + (5.00 x (Real(Level))))
        • Then - Actions
          • -------- Enemy is executable, set damage to a lethal amount: --------
          • Set VariableSet Damage = 1000000000.00
        • Else - Actions
          • -------- Enemy has too much life %, set non-lethal damage: --------
          • Set VariableSet Damage = ((Max life of Target) x (0.05 + (0.05 x (Real(Level)))))
      • -------- --------
      • Unit - Cause Caster to damage Target, dealing Damage damage of attack type Spells and damage type Normal
If the enemy has <= 35% / 40% / 45% life then Damage will be set to a huge amount which should be lethal.

Else, if the enemy has > 35% / 40% / 45% life then Damage will be set to an amount based on the target's max life: 10% / 15% / 20% as damage.

With this Arithmetic setup the ability will scale infinitely and can have as many levels as you'd like. Note that Damage is a Real variable and because of this it can only do calculations with other Reals so you'll need to convert the Level variable to a Real when multiplying them.



Alternatively, you can create variable Arrays for these values where the [index] of the Array represents Ability Level.
This will allow for ability scaling that doesn't follow a strict pattern:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Set VariableSet Execute_KillPercentage[1] = 35.00
    • Set VariableSet Execute_KillPercentage[2] = 45.00
    • Set VariableSet Execute_KillPercentage[3] = 60.00
    • Set VariableSet Execute_DamagePercentage[1] = 10.00
    • Set VariableSet Execute_DamagePercentage[2] = 15.00
    • Set VariableSet Execute_DamagePercentage[3] = 30.00
These variables get initialized at the start of the game. Now you can reference them in your Execute trigger:
  • (Percentage life of Target) Less than or equal to Execute_KillPercentage[Level]
  • Set VariableSet Damage = ((Max life of Target) x Execute_DamagePercentage[Level])
 

Attachments

  • Execute.w3m
    17.2 KB · Views: 5
Last edited:
Level 20
Joined
Feb 23, 2014
Messages
1,265
Your explanation is somewhat vague so I'm going to assume that you want something like Axe's ultimate ability from DotA where it either damages or instantly kills the target unit.
Well, to me it sounds more like the Execute ability in WoW, i.e. an ability can only be used on / target units below a certain health percentage.

This is going to be tricky - as far as I know, there's no easy way to have custom targetting (i.e. the game showing you an error message and blocking you from using the ability, like it does for instance when you try to target a unit with full life with a simple healing ability).

The closest you can get, I think, is trying to cancel the ability if it's used on an invalid target, i.e. the game will let you "click" the target with the ability, but you'll use triggers to stop the caster from actually using it. Technically that could work, but... It's messy:

1. You won't be blocked from clicking on the target and you won't get the standard error sound & message.
2. There might be some visible effects, e.g. the caster might move to the target or play the spell cast animation.

You could technically play the sound yourself and have some custom error message, but it might be difficult to simulate the default effects to such a degree that there will be no noticeable difference. And as for the "blocked from clicking" part... well, perhaps you could do some janky workaround with the Game - Force UI Key or something to make it appear as if the player was blocked from clicking on the target, but it might be impossible to detect clicking on the unit with the targeting cursor of a specific ability and by extension triggering your workaround at the right moment.

Like, maybe some smarter people than me will know ways to do this, but as far as I know - there's no good way to solve these issues, which means that if you attempt to cancel the ability, you won't catch it at the correct moment, so it might be difficult if not impossible to cancel the visible effects mentioned above. Again, perhaps there is a way to do this, but I've spent a solid amount of time and couldn't do it.

---

Overall, most likely you'll a) be forced to use some elaborate workarounds and / or b) not achieve the desired result of blocking the player from using the ability in a way that's indistinguishable from the way Warcraft 3 does it. Thus, your ability will probably look and feel rather weird and awkward to the player (e.g. you'll be able to click on a target only to see the caster move, play the spell cast animation and have nothing happen).

My recommendation would be to slightly tweak how the ability works, i.e. have it deal a small amount of damage regardless of the target's health and then add the extra damage on top of that if the target has the required health percentage (using methods show by @Uncle).

It's not exactly what you asked for, but it's pretty close thematically and it would be an easy way to circumvent all of the targetting issues.
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
MasterBlaster is correct that making a cast cancel seamless is a big ask. You can get 90% of the way to being perfect but that last 10% is always going to be a problem. Vexorian's old library SimError still does most of what you can do for you. You cannot force a UI key to re-enter spellcast immediately when canceling the order because the game needs a frame to redraw the UI. How long a frame takes to redraw (and thus how long you have to wait before re-issuing the UI Key Force) is dependent on game framerate so is not standardized (per player or even over time) or generally knowable in-game.

An alternative solution would be much easier to implement but does change how the ability works: make the ability non-targeted instead of unit-targeted. It can then function as "execute the last unit this unit damaged with an attack" and can be enabled/disabled on the UI at will (based on target % health, proximity to the target, duration since you last attacked, etc.). This disabling can keep it visible on the UI so it would just appear to be greyed out and un-clickable/pressable unless the conditions to activate it were satisfied already, as well as showing the remaining cooldown at all times. Forcing a keycast to re-enter targeting after a failed cast is also not necessary; if the ability is not disabled by proximity to the target it would be possible to activate this non-targeted ability erroneously, which would have to be stopped... but you would just go back the main unit UI like you should after a failed non-targeted cancel.
 
Level 7
Joined
Jan 11, 2022
Messages
108
Actually meant they WoW type execute ability but ten realised it can be hard to cancel as both od you explained above.

Your explanation is somewhat vague so I'm going to assume that you want something like Axe's ultimate ability from DotA where it either damages or instantly kills the target unit.

Your trigger needs to use Arithmetic and incorporate the Level of the ability into the calculations:
  • Execute
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Execute
    • Actions
      • Set VariableSet Caster = (Triggering unit)
      • Set VariableSet Target = (Target unit of ability being cast)
      • Set VariableSet Level = (Level of (Ability being cast) for Caster)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Percentage life of Target) Less than or equal to (30.00 + (5.00 x (Real(Level))))
        • Then - Actions
          • -------- Enemy is executable, set damage to a lethal amount: --------
          • Set VariableSet Damage = 1000000000.00
        • Else - Actions
          • -------- Enemy has too much life %, set non-lethal damage: --------
          • Set VariableSet Damage = ((Max life of Target) x (0.05 + (0.05 x (Real(Level)))))
      • -------- --------
      • Unit - Cause Caster to damage Target, dealing Damage damage of attack type Spells and damage type Normal
If the enemy has <= 35% / 40% / 45% life then Damage will be set to a huge amount which should be lethal.

Else, if the enemy has > 35% / 40% / 45% life then Damage will be set to an amount based on the target's max life: 10% / 15% / 20% as damage.

With this Arithmetic setup the ability will scale infinitely and can have as many levels as you'd like. Note that Damage is a Real variable and because of this it can only do calculations with other Reals so you'll need to convert the Level variable to a Real when multiplying them.

Alternatively, you can create variable Arrays for these values where the [index] of the Array represents Ability Level.
This will allow for ability scaling that doesn't follow a strict pattern:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Actions
    • Set VariableSet Execute_KillPercentage[1] = 35.00
    • Set VariableSet Execute_KillPercentage[2] = 45.00
    • Set VariableSet Execute_KillPercentage[3] = 60.00
    • Set VariableSet Execute_DamagePercentage[1] = 10.00
    • Set VariableSet Execute_DamagePercentage[2] = 15.00
    • Set VariableSet Execute_DamagePercentage[3] = 30.00
These variables get initialized at the start of the game. Now you can reference them in your Execute trigger:
  • (Percentage life of Target) Less than or equal to Execute_KillPercentage[Level]
  • Set VariableSet Damage = ((Max life of Target) x Execute_DamagePercentage[Level])
I have a silly request, but would that be a problem if you attach a map that works on legacy versions? I can't open these new ones. I'd be delighted if you could so I can see that trigger in action, working etc
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,860
I can't save the map on anything other than my current version. All of the triggers I used in the map are posted here as well, and the functions used in those triggers are all categorized by name, so as long as you use the "Search For Text" feature and look carefully when scrolling through the available functions you should be able to find everything you need. Arithmetic is the function that allows you to make calculations like (35.00 + (5.00 * Level of ability)). The first time you click Arithmetic you'll see two numbers that you can add/subtract/divide/multiply, and if you click one of the numbers you can apply Arithmetic again to get another pair of parenthesis (x + x). From there it's just basic math.

I would use the Array method if you're struggling with the Arithmetic since it's a bit more straightforward and easier to read/use. If you're unsure of how to use Arrays, there's a million tutorials on Hive about them. Same goes for anything else you see in there.

Also, the cancelling of the ability is actually pretty simple, the hard part is making it feel like a standard Warcraft 3 cancel mechanic with error text/error sound. That's not really necessary though and I don't think players will care.

This interrupts the order process. Replace "devour" with the Order String of your Execute ability:
  • Events
    • Unit - A unit is issued an Order targeting an object
  • Conditions
    • (Issued order) Equal to (Order(devour))
    • (Level of Execute for (Ordered unit) Greater than 0)
  • Actions
    • Set Caster = (Ordered unit)
    • Set Target = (Target unit of issued order)
    • Set Level = (Level of Execute for Caster)
    • -------- --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Percentage life of Target) Greater than (30.00 + (5.00 x (Real(Level))))
      • Then - Actions
        • Unit - Pause Caster
        • Unit - Order Caster to Stop
        • Unit - Unpause Caster
      • Else - Actions
This interrupts the casting process:
  • Events
    • Unit - A unit Begins casting an ability
  • Conditions
    • (Ability being cast) Equal to Execute
  • Actions
    • Set Caster = (Casting unit)
    • Set Target = (Target unit of ability being cast)
    • Set Level = (Level of Execute for Caster)
    • -------- --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Percentage life of Target) Greater than (30.00 + (5.00 x (Real(Level))))
      • Then - Actions
        • Unit - Order Caster to Stop
      • Else - Actions
When the unit is issued the order to cast the spell or begins casting the spell we will check the life of the target. If it's too high then we tell the caster to Stop. The Pause/Unpause stuff is there to fix an issue that happens when trying to interrupt an Order with another Order, although it may not be necessary in this case.

You can find the Order String in the Ability Editor under the Use/Turn On field. In my example I used the string "devour" which goes with the Devour ability. If say Execute was based on Storm Bolt then you would use the Order String "thunderbolt".

Once you have those two triggers added you can go back to the Execute trigger that I made in my previous post and simplify it:
  • Execute
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Execute
    • Actions
      • Set Caster = (Casting unit)
      • Set Target = (Target unit of ability being cast)
      • Set Level = (Level of Execute for Caster)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Percentage life of Target) Less than or equal to (30.00 + (5.00 x (Real(Level))))
        • Then - Actions
          • -------- Enemy is executable, deal damage: --------
          • Set Damage = ((Max life of Target) x (0.05 + (0.05 x (Real(Level)))))
          • Unit - Cause Caster to damage Target, dealing Damage damage of attack type Spells and damage type Normal
        • Else - Actions
There may be very rare instances where Execute fails to damage the unit despite successfully casting. This would happen if the target unit managed to restore enough life in-between the "Begins casting" and "Starts the effect" phases, which is a fairly small window of time. It's not really anything to worry about though, slap an "intended feature" sticker on it and call it a day. Alternatively, you could delete the If Then Else in the Execute trigger and instead ALWAYS deal the damage.
 
Last edited:
Status
Not open for further replies.
Top