• 🏆 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!

[General] Set ability remaining cooldown to certain value?

Status
Not open for further replies.
Level 7
Joined
Oct 3, 2008
Messages
183
Hi everyone,

was wondering if there is a way to set the remaining cooldown of an ability for a unit to a certain value. Specific usecase:

Custom ability being cast, say it has 10 second cooldown, if the target is invalid (determined in a trigger) I want to be able to set the remaining cooldown of the ability to a small value, say 0.5, rather than fully reset it to prevent players from being able to just mash the ability.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
Native functions were recently added to support adjusting ability cooldowns. If they work correctly or can do what you are after I am not sure.

If you are using a legacy version of Warcraft III then you might be able to work around the issue by detecting the target before the ability goes onto cooldown and if so interrupting it. For example when the player orders the unit cast the ability you could already validate the target and abort the order before the unit has chances to execute it. Intercepting abilities when they "begin casting" can also allow for them to be interrupted before the ability goes onto cooldown.
 
Level 7
Joined
Oct 3, 2008
Messages
183
Hmm, this seemed to work, probably cause "starts the effect of ability" triggers before the cooldown applies, just annoyed that Blizzard indexing is so inconsistent about starting at 0 or 1. I haven't tried your solution yet, Ender, but I imagine it'd work as well I just always had been putting the level at 1 instead of zero. (Probably why the new natives weren't working properly for me either.)

Code:
call BlzSetAbilityRealLevelField(BlzGetUnitAbility(GetTriggerUnit(), 'A00L'), ABILITY_RLF_COOLDOWN, 0, 0.5)

Which works for my use case, I'll have to see if I can now get one of the natives to work for editing the cooldown of an ability already ticking down.
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,559
For adjusting an ability already ticking down I believe you would do it like this:

Set variable Amount = 5.00
Set variable newCd = Cooldown remaining for ability - Amount
If newCd < 0.00 then set newCd = 0.00 (probably unnecessary as I'm sure this is automatically handled for you)
Start unit cooldown for ability as newCd seconds

With these natives you should have all the tools needed to manipulate cooldowns however you'd like. They all work as well (shocker, I know).
 
Status
Not open for further replies.
Top