Jump to content

Lua Script adding cool down timer


Recommended Posts

So I haven't found a way to add a cool down timer to a lua script, certain conditions work but it seems to ignore the cooldown time left condition and continues to spam the lua script ability. Below is the lua script for casting growl, how would I go about implementing a 8 second cooldown before it tries to run the script again?

for i=1,50 do
    local spellName, spellSubName = GetSpellBookItemName(i, BOOKTYPE_PET)
    if spellName and spellName == "Growl" then
        CastSpell(i, BOOKTYPE_PET);
    end
end

Link to comment
Share on other sites

You can check for your pet's spell cooldown like so:

local start, duration, enable = GetSpellCooldown(PET_SPELL_INDEX, 'pet') 
return (duration - (GetTime() - start)) * 1000

This returns the spell cooldown in milliseconds. The spell is ready when it returns a value lower than 0. You'll need to replace PET_SPELL_INDEX with i in your case.

Link to comment
Share on other sites

2 hours ago, Zer0 said:

You can check for your pet's spell cooldown like so:

local start, duration, enable = GetSpellCooldown(PET_SPELL_INDEX, 'pet') 
return (duration - (GetTime() - start)) * 1000

This returns the spell cooldown in milliseconds. The spell is ready when it returns a value lower than 0. You'll need to replace PET_SPELL_INDEX with i in your case.

How should I implement this? I tried as Lua condition made the adjustments but crash due to to many characters.

Link to comment
Share on other sites

I've got all this working and even added some more C sharp and Lua scripts to my fightclass but struggling with certain conditions like.

Hostile Unit Near, I am trying to setup disengage to activate when units are within a smaller range of 8. But this condition also seems to trigger from my pet which is always next to the target so it's always just spamming it when it's off cooldown.

Link to comment
Share on other sites

It's c# code to ignore your pet :

ObjectManager.GetWoWUnitHostile().Count(u => u.Position.DistanceTo(ObjectManager.Target.Position) <= 10  && u.IsAttackable && !u.IsMyPet) >= 3

Replace 10 by the radius (distance), and 3 by the number of hostile unit near the target require.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...