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

[Ability Cooldown Remaining] function not working?

Status
Not open for further replies.
Level 7
Joined
Jun 1, 2009
Messages
104
Hi!
My goal is to auto-cast a spell under certain conditions. To reduce lags in the case of multiple units I want to check the condition if the spell is ready or not.
But when I try to use the
  • Ability Cooldown Remaining
condition, the whole thing stops working, until I disable that function.
What I'm doing wrong?
Is there any other resource-saving method to check the ability cooldown?
Ofc. I can simply start a timer for every casting unit, but I hope to avoid this.

My triggers:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Unit-type of (Attacking unit)) Equal to |cff00ffffWizzard|r
    • Then - Actions
      • Set VariableSet AI_TempUnit[0] = (Attacking unit)
      • Set VariableSet AI_TempUnit[1] = (Attacked unit)
      • Trigger - Run AI Wizzard <gen> (checking conditions)
      • Skip remaining actions
    • Else - Actions
  • AI Wizzard
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability Cooldown Remaining of AI_TempUnit[0] for ability Spell Absorption ..) Less than or equal to 0.00
        • Then - Actions
          • Set VariableSet AI_TempPoint = (Position of AI_TempUnit[1])
          • Unit - Order AI_TempUnit[0] to Undead Destroyer - Devour Magic AI_TempPoint
          • Custom script: call RemoveLocation(udg_AI_TempPoint)
        • Else - Actions
      • Set VariableSet AI_TempUnit[0] = No unit
      • Set VariableSet AI_TempUnit[1] = No unit

Without
  • (Ability Cooldown Remaining of AI_TempUnit[0] for ability Spell Absorption ..) Less than or equal to 0.00
everything is fine...
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,539
That condition should work unless it was broken very recently. Test to see if it works with a value like 10.00 instead of 0.00 to confirm that you can even get it to work in the first place. Also, double check the ability that it's referencing.

Aside from that, if you're concerned about performance the most important thing to do here would be to avoid a massive amount of If Then Else statements whenever a unit is attacked. Instead, store the AI triggers inside of a Hashtable, saving them to the unit's Unit-Type id.

Setting up the hashtable:
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Hashtable - Create a Hashtable
    • Set Variable AI_Hashtable = (Last created hashtable)
    • ///
    • Set Variable AI_Type = Wizard
    • Set Variable AI_Trigger = AI Wizard
    • Custom script: set udg_AI_Id = udg_AI_Type
    • Hashtable - Save AI_Trigger as 0 of AI_Id in AI_Hashtable
    • ///
    • /// continue adding each AI unit-type to the hashtable
    • Set Variable AI_Type = ...
    • Set Variable AI_Trigger = ...
    • Custom script: set udg_AI_Id = udg_AI_Type
    • Hashtable - Save AI_Trigger as 0 of AI_Id in AI_Hashtable
Then making it run whenever a unit is attacked:
  • Events
    • Unit - A unit is attacked
  • Conditions
    • Level of AI Classification for (Attacking unit) Greater than 0
  • Actions
    • Set Variable AI_TempUnit[0] = (Attacking unit)
    • Set Variable AI_TempUnit[1] = (Attacked unit)
    • Custom script: set udg_AI_Id = GetUnitTypeId(udg_AI_TempUnit[0])
    • Trigger - Run (Load 0 of AI_Id from AI_Hashtable) (ignoring conditions)
AI Classification would be some hidden passive ability (based on Storm Hammers for example) that you'd give to each AI unit in the Object Editor. It acts as a way to filter units that are intended to have AI.

Now whenever an AI unit attacks a unit the variables will get set and the appropriate trigger will run.

Note that when you Run a trigger (ignoring conditions) it simply skips the Conditions block but not any Conditions found in your If Then Else statements. So if your Conditions block is empty than this is the better option. Also, you can save other unit-type specific data to this Hashtable which may come in handy depending on your needs.

Variables:
AI_Type = Unit-type
AI_Trigger = Trigger
AI_Id = Integer
AI_Hashtable = Hashtable
 
Last edited:
Level 7
Joined
Jun 1, 2009
Messages
104
Thanks for the info! That's quite handy! Wish I knew set udg_AI_Id = GetUnitTypeId(udg_AI_Type) custom script trick before. Yet I'm not ready to implement this hashtable thing right now; even thinking about rewriting the whole thing makes me feel bad. But at least if lags will show up I know where to go from massive if\then\else blocks.

As for the CD detection. Can't make Ability Cooldown Remaining work as intended yet :(
But I've used a Unit custom value as a timer: set the custom value to cooldown seconds value, and then each second making it -1:

  • AI Loop CD Decay
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Player number of (Owner of (Matching unit))) Less than 9) and ((Level of AI Autocasts ON [Dummy Spell] - Global for (Matching unit)) Greater than 0)) and ((Custom value of (Matching unit)) Greater than 0))) and do (Actions)
        • Loop - Actions
          • Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 1)
When it drops to zero the trigger conditions allows to cast it again.
Think I can do the similar thing with the dummy ability levels - if I ever need these units' custom values for another purposes.
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
When it drops to zero the trigger conditions allows to cast it again.
Think I can do the similar thing with the dummy ability levels - if I ever need these units' custom values for another purposes.
Be aware that this will only allow you to track one cooldown per unit. If there are multiple spells with a cooldown you'll have to come up with another solution.

Instead of checking the cooldown remaining, why don't you print the cooldown remaining (it's a real, so convert real to string) every time the trigger runs. Then you can see if the cooldown reading function is what's broken or something else is fucked up.
 
Status
Not open for further replies.
Top