View Single Post
12-10-20, 10:20 AM   #9
VeenixO
A Murloc Raider
Join Date: Dec 2020
Posts: 7
Alright, so tried to do the final piece of the addon which is checking for cooldown.
Here is the code, it seems to not work all the time and I got no clue what's wrong with it.
Do I have to check for cds in the update script?

local SPELL_ID = 24275 -- Hammer of Wrath
local SPELL_NAME = GetSpellInfo(SPELL_ID)
local UPDATE_INTERVAL = 0.1

local frame = CreateFrame("Frame", nil, UIParent)
frame:SetPoint("CENTER", UIParent, "CENTER", 0, -200)
frame:SetSize(64, 64)
frame:Hide()

local texture = frame:CreateTexture()
texture:SetAllPoints(frame)
texture:SetTexture([[Interface\AddOns\PallyProc\Textures\HolyGlow.tga]])

frame:SetScript("OnEvent", function(self, event, spellID)
if event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" then
if spellID == SPELL_ID and HasFullControl() and IsUsableSpell(SPELL_NAME) and GetSpellCooldown(SPELL_NAME)==0 then
frame:Show()
else
frame:Hide()
end
elseif event == "SPELL_ACTIVATION_OVERLAY_GLOW_HIDE" then
if spellID == SPELL_ID then
frame:Hide()
end
end
end)
frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")
frame:RegisterEvent("SPELL_UPDATE_COOLDOWN")

local timer = UPDATE_INTERVAL
frame:SetScript("OnUpdate", function(self, elapsed)
timer = timer + elapsed
if timer < UPDATE_INTERVAL then return end
timer = 0

if IsSpellInRange(SPELL_NAME, "target") == 1 then
frame:SetAlpha(1)
else
frame:SetAlpha(0.5)
end
end)

frame:SetScript("OnHide", function(self)
timer = UPDATE_INTERVAL
end)
  Reply With Quote