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

[General] How to give a unit spell Cooldowns?

Status
Not open for further replies.
Level 7
Joined
Jul 1, 2008
Messages
1,024
Hi, so I know there is a function which resets all the abilities on a unit but I am looking to do the opposite. I want to give a newly created unit cooldowns on all its abilities, so that when its spawned, it can't use its abilities straight away.

Is there a way I can do this please?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,901
There's no function to put an ability on cooldown. I think all we can do right now is reset cooldowns and set their cooldown durations.

That being said, one possible solution would be to disable the unit's abilities when it enters the map and then re-enable them with a timer.

  • Untitled Trigger 001
    • Events
      • Unit - A unit enters (Entire map)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Footman
    • Actions
      • Unit - For (Triggering unit), Ability Defend, Disable ability: True, Hide UI: False
      • Wait 5.00 seconds
      • Unit - For (Triggering unit), Ability Defend, Disable ability: False, Hide UI: False
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,901
I feel like forcing the unit to cast it's spells would be a nightmare to deal with depending on how the map works. For starters, if you trigger any of your spells then they would need to be coded so that they aren't going to cause problems. Second, you have to consider the targeting type for the ability. There's Instant, Target Unit, Target Point, and Channeling that all need to be considered. On top of that, if the ability targets a unit then you would need to consider the targeting filter, does it target Allies, Enemies, Air, Ground, etc...?

Plus what Pyro said about the animation backswing/castpoint. However, once we can manipulate this with triggers you could temporarily set these values to 0 before casting the spell and then reset them back to their default values afterwards.

I suppose if you really want the cooldowns to be displayed then this is the best option available, but otherwise just disabling the ability and then re-enabling it would probably be a lot easier to do. Although, if he wants the abilities to be disabled for different durations (like based on their cooldowns) then it would get slightly more complex but still very doable.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Hi, so I know there is a function which resets all the abilities on a unit but I am looking to do the opposite. I want to give a newly created unit cooldowns on all its abilities, so that when its spawned, it can't use its abilities straight away.

Is there a way I can do this please?
For what scenario you need this? Depending on the situation alternative solutions like using shop items instead of abilities might work.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
For what scenario you need this?
It's in the part you quoted:
I want to give a newly created unit cooldowns on all its abilities, so that when its spawned, it can't use its abilities straight away.
Here's an interesting option:
  • Use this method to create passive-but-with-cooldown versions of all of the units' active skills. In theory if set up properly they should all go on cooldown the instant a unit spawns (only one can be cast at once but the check period if set to 0.01 will be the only delay between them all casting in succession). They will consume mana on cast which might need to be given back to the unit.
  • Create a hashtable that allows you to associate the real version spells with the fake passive versions. Save the real spell's id under a key of the fake spell. Using ability IDs (integers, under the hood) this way will require a small amount of custom script fuckery to set variables equal to each other.
  • Track when any of these passive-but-with-cooldown abilities are cast with a trigger.
  • The first time a unit casts such a spell, do nothing, but save that it has cast it somewhere. In a hashtable would be by far the easiest way since you can use unit ID/handle ID and ability ID as keys. Same caveat about integers/custom script fuckery.
  • You may need to read the 'mana cost' integer field of the cast spell to allow you to replenish it.
  • The second time a unit casts one of these passive spells (which you'll know because you saved that it had already cast once), the cooldown has finished and the spell can be replaced with the real version. Flush the info in the hashtable about whether or not the unit has cast already, since that info is no longer needed.
  • Don't forget to UnitMakeAbilityPermanent() on the newly added abilities so they persist properly.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
It's in the part you quoted:

No, that does not explain the reason, it only explains what OP is trying to do technically. But if we know the actual problem, there might be alternative solutions as I suggested.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
They want cooldowns to be active when creating a unit. What more is there to understand? The reason is so that spells start on cooldown because that's how they want it to be.
It is true that the "passive cooldown" solution you mentioned can clearly solve the issue, but depending on the situation there might be alternatives that require less work.
1- If abilities are non-hero abilities, you can give dummy berserk abilities to unit and order unit to cast them. (Original abilities need to be replaced with a timer, and yes you can issue multiple berserk orders in consecutive lines of code).
2- Another solution is to sell dummy items instead of using actual abilities. On some maps players have an important unit whole game, and there are some abilities that can only be used after X seconds elapsed in the game, or X seconds after some event happens.
3- You can use tech-tree requirements, like using a dummy upgrade with name "100 seconds need to be passed". But of course this method has the disadvantage that it does not show remaining cooldown.
 
Status
Not open for further replies.
Top