Learning addon development

There doesn’t seem to be any event that explicitly fires when a specific cooldown ends.

I tried using GetSpellCooldown() but it returns 0, 0 when casting the spell, you’d have to use a timer or keep polling it to get the actual cooldown.

I went with hooking CooldownFrame_Set()

local casts = {}
local spells = {
	[101545] = true, -- Flying Serpent Kick
	[101643] = true, -- Transcendence
}

local function CreateFancyTexture(spellID)
	local f = CreateFrame("Frame")
	f:SetSize(60, 60)
	f:SetPoint("CENTER")
	local tex = f:CreateTexture()
	tex:SetAllPoints(f)
	tex:SetTexture(GetSpellTexture(spellID))
	return tex
end

hooksecurefunc("CooldownFrame_Set", function(self)
	local btn = self:GetParent()
	if btn.action then
		local actionType, id = GetActionInfo(btn.action)
		if actionType == "spell" and spells[id] then
			if not self.HookedScript then
				self:HookScript("OnCooldownDone", function()
					if casts[id] then
						casts[id] = false
						self.fancyTexture = self.fancyTexture or CreateFancyTexture(id)
						self.fancyTexture:Show()
						C_Timer.After(2, function() self.fancyTexture:Hide() end)
					end
				end)
				self.HookedScript = true
			end
		end
	end
end)

-- ignore OnCooldownDone script when fired from the GCD by tracking for actual spell casts
local function OnEvent(self, event, unit, _, spellID)
	if unit == "player" and spells[spellID] then
		casts[spellID] = true
	end
end

local f = CreateFrame("Frame")
f:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
f:SetScript("OnEvent", OnEvent)

For any tutorials/resources I suggest these:

  • https://github.com/WeakAuras/WeakAuras2/wiki/Lua-Dev-Environment
  • https://www.mmo-champion.com/threads/817817-Creating-Your-Own-WoW-Addon
  • API docs: https://wow.gamepedia.com/World_of_Warcraft_API
  • Addons discord: https://discord.gg/J9VUQ5g
  • https://www.wowinterface.com/forums/index.php