UNIT_SPELLCAST_SUCCEEDED fires when anyone around you casts a spell, so we need to narrowing down what you want your function to react to specifically
, also your cooldown timer will start ticking when you enter the world as it is outside of the function
my coding is a bit rusty, so hopefully this might work:
Code:
local Hearth = CreateFrame("Button", "Hearth", UIParent, "SecureActionButtonTemplate")
Hearth:SetWidth(25)
Hearth:SetHeight(25)
Hearth:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 3, 3)
Hearth:SetFrameStrata("HIGH")
Hearth:SetFrameLevel(1)
Hearth:SetNormalTexture("Interface\\ICONS\\ACHIEVEMENT_GUILDPERK_HASTYHEARTH")
Hearth:SetAttribute("type", "item")
Hearth:SetAttribute("item", "The Innkeeper's Daughter")
Hearth:RegisterForClicks("AnyUp")
if IsUsableItem("The Innkeeper's Daughter")
then Hearth:Show() else Hearth:Hide()
end
local HearthCD = CreateFrame("Cooldown", "HearthCD", Hearth)
HearthCD:SetAllPoints(Hearth)
Hearth:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
local function eventhandler(self, event, unit,spellname)
if (unit == "player") and (spellname == "Hearthstone") then
HearthCD:SetCooldown(GetTime(), 900, 1)
end
end
Hearth:SetScript("OnEvent", eventhandler);