Thread Tools Display Modes
08-31-13, 09:31 AM   #1
palalu
A Defias Bandit
Join Date: Aug 2013
Posts: 2
Question: Cooldown Tracking for Specific Spell

Hi,

I am trying to track cooldown of a specific spell and i am using script below.

Code:
local trigger = CreateFrame("Frame")
local track = CreateFrame("Frame")
trigger:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end) 
trigger:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")

function trigger:UNIT_SPELLCAST_SUCCEEDED(unitID, spell, rank, lineID, spellID)
        if not spellID == 107428 then return end
                if spellID == 107428 then
                   track:SetScript("OnUpdate", function(self)
                   local start, duration, enabled = GetSpellCooldown(107428);
                      if start == 0 then
                          PlaySoundFile("Sound\\Character\\BloodElf\\BloodElfMaleCheer02.wav")
                          track:SetScript('OnUpdate',nil)
                      end
                    end)
       end 
end
I am new to LUA scripting , and I am curious if there's a better way in doing this.

ps:wrong section.. should be on Lua/XML Help sorry

thanks

Last edited by palalu : 08-31-13 at 09:33 AM. Reason: wrong section
  Reply With Quote
08-31-13, 09:59 AM   #2
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Have you considered using the SPELL_UPDATE_COOLDOWN event for this? Haven't used it myself but it seems like it could work better here.

Plus, on a more general note, I suggest putting that spell ID number in a variable so you don't have to repeat it, and you really should keep proper indentation to make everything more readable
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
08-31-13, 02:57 PM   #3
palalu
A Defias Bandit
Join Date: Aug 2013
Posts: 2
Hi, Thanks for your input.. Gonna try things out with that event
  Reply With Quote
08-31-13, 08:46 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Code:
local isOnCooldown

local f = CreateFrame("Frame")
f:RegisterEvent("SPELL_UPDATE_COOLDOWN")
f:SetScript("OnEvent", function(f, event, ...)
	local start, duration = GetSpellCooldown(107428) -- Rising Sun Kick
	if start > 0 and duration > 0 then
		-- Cooldown started or is still in progress.
		isOnCooldown = true
	elseif isOnCooldown then
		-- Cooldown was in progress, but is now ended.
		isOnCooldown = nil
		PlaySoundFile("Sound\\Character\\BloodElf\\BloodElfMaleCheer02.wav")
	end
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Question: Cooldown Tracking for Specific Spell


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off