1. #1

    Help with Custom Addon

    I am working on transferring some simple functions I use in wow into a custom add-on using LUA. Im trying to make a custom button that shows my hearthstone. When I click the button it casts my hearthstone, but where the issue is, is that I'm trying to have an overlay that shows the cooldown of my hearthstone. The button works fine, but the cooldown starts on entering world, and not on the cooldown of the item. Any help would help tremendously.

    Here is the code that I am using for the button, and what I've come up with for the cool down using what I've found online:
    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:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
    Hearth:SetNormalTexture("Interface\\ICONS\\ACHIEVEMENT_GUILDPERK_HASTYHEARTH")
    Hearth:SetAttribute("type", "item")
    Hearth:SetAttribute("item", "The Innkeeper's Daughter")
    Hearth:RegisterForClicks("AnyUp")
    Hearth:SetScript("OnEvent", function()
    if IsUsableItem("The Innkeeper's Daughter")
    then Hearth:Show() else Hearth:Hide()
    end
    end)
    local HearthCD = CreateFrame("Cooldown", "HearthCD", Hearth)
    local start, duration, enabled = GetSpellCooldown("The Innkeeper's Daughter")
    HearthCD:SetAllPoints(Hearth)
    HearthCD:SetCooldown(GetTime(), "900", 1)

  2. #2
    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);
    Last edited by mmocba105e19de; 2013-10-26 at 09:27 PM. Reason: Fixed a few typo'ed variable names to avoid confusion :)

  3. #3
    Deleted
    I'm not sure if UNIT_SPELLCAST_SUCCEEDED actually works for the Hearthstone - generally, if you're interested in cooldown specific information, registering for an actual cooldown event such as BAG_UPDATE_COOLDOWN is the best way to go.

    Code:
    HearthCD:SetScript("OnEvent",function(self)
        local start,duration,enable=GetItemCooldown(64488)
        if enable then
            self:SetCooldown(start,duration)
        end
    end)
    HearthCD:RegisterEvent("BAG_UPDATE_COOLDOWN")

  4. #4
    Worked perfectly for my hearthstone and jaina's locket thank you so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •