weakauras

weakauras

my weakauras

local e = aura_env
local hasOffWeapon = C_PaperDollInfo.OffhandHasWeapon()
local count = 0
local missing = 0
local expirationTime = e.config['duration']
local trackedEnchant = e.config['enchant']
e.enchants = {
[6190] = true, -- Embalmer's Oil
[6188] = true, -- Shadowcore Oil
[6201] = true, -- Shaded Weightstone
[6200] = true, -- Shaded Sharpening Stone
[5400] = true, -- Flametongue Weapon
[5401] = true -- Windfury Weapon
}

local e = aura_env

e.enchants = {
[6190] = true, -- Embalmer's Oil
[6188] = true, -- Shadowcore Oil
[6201] = true, -- Shaded Weightstone
[6200] = true, -- Shaded Sharpening Stone
[5400] = true, -- Flametongue Weapon
[5401] = true -- Windfury Weapon
}

function e.missingEnchants()

    local count = 0
    local missing = 0
    local hasOffWeapon = C_PaperDollInfo.OffhandHasWeapon()
    local expirationTime = e.config['duration']

    local hasMainEnchant, mainExpiration, _, mainEnchantID, hasOffEnchant, offExpiration, _, offEnchantID = GetWeaponEnchantInfo()

    if not hasMainEnchant or not e.enchants[offEnchantID] then
        count = count + 1
    elseif (mainExpiration / 60000) < e.config['duration'] then
        count = count + 1
    end

    -- check if an eligible off-hand exists
    if hasOffWeapon then
        if not hasOffEnchant or not e.enchants[offEnchantID] then
            count = count + 1
            missing = missing + 1
        elseif (offExpiration / 60000) < e.config['duration'] then
            count = count + 1
        end

        if mainExpiration and offExpiration then
            expirationTime = (math.min(mainExpiration, offExpiration)) / 60000
        end
    else
        if mainExpiration then
            expirationTime = mainExpiration / 60000
        else
            missing = missing + 1
        end
    end
    return count, expirationTime, missing

end

if not e.clickableFrame then
local r = e.region
e.clickableFrame = CreateFrame("Button", "ConsumeButton", r, "SecureActionButtonTemplate")
end

e.clickableFrame:SetAllPoints()
e.clickableFrame:SetAttribute("type", "macro")
e.clickableFrame:SetAttribute("macrotext", "/use item:171285\n/use 16\n/click StaticPopup1Button1")

“trigger”

function(event, ...)
    local count, _,_ = aura_env.missingEnchants()
    if (count > 0) then
        return true
    else
        return false
    end
end

“icon”

function()
    local _, expirationTime, missing = aura_env.missingEnchants()

    if (aura_env.config['duration'] - expirationTime > 0) and missing == 0 then
        WeakAuras.regions[aura_env.id].region.icon:SetDesaturated(true)
    else
        WeakAuras.regions[aura_env.id].region.icon:SetDesaturated(false)
    end
end

“text”

function()
    local pot = GetItemCount(171285, nil, true)
    local s, d, _ = GetItemCooldown(171285)
    local count
    local cd = ""
    if pot == 0 then
        count = string.format("0")
    else
        count = string.format(pot)
    end
    if s > 0 then
        cd = math.floor(s + d - GetTime())
    end
    return count, cd
end

snippets

general

example “custom activation”

function(trigger) return trigger[1] and (trigger[2] or trigger[3]) end

example “get active buffs on unit”

for i=1,40 do local name, icon, _, _, _, etime = UnitBuff("player",i) if name then print(("%d=%s, %s, %.2f minutes left."):format(i,name,icon,(etime-GetTime())/60)) end end

dynamic groups

example “centered horizontal grid”

function(newPositions, activeRegions)
local limit = 3 -- limit of icons per row
local rows = 3 -- total rows
local spacing = 1 -- spacing between icons
----------------------
local check = true
local xCount = 0
local yCount = 0
local tCount = 0

        local xOffset = 0
        local yOffset = 0
        local total = #activeRegions

        for i, regionData in ipairs(activeRegions) do
            local region = regionData.region

            local regionsLeft = total - tCount
            local rowTotal = 1

            if total <= limit then
                rowTotal = total
            elseif (regionsLeft < limit and xCount < 1) or not check then
                check = false
                rowTotal = regionsLeft
            elseif yCount >= rows-1 then
                rowTotal = regionsLeft
            elseif total > limit then
                rowTotal = limit
            end

            xOffset = 0 - (region.width + spacing) / 2 * (rowTotal-1) + (xCount * (region.width + spacing))
            yOffset = 0 - (region.height + spacing) * yCount -- change '-' to '+' after 0 to grow up instead of down

            xCount = xCount + 1

            if yCount < rows-1 and check then
                tCount = tCount + 1
                if xCount >= limit then
                    xCount = 0
                    yCount = yCount + 1
                end
            end

            newPositions[i] = {xOffset, yOffset}
        end
    end

example “custom grid by kib”

function(newPositions, activeRegions)
local powerBarHeight = 24
local powerBarWidth = 312
local space = 3
local group = {}
local comboSpace = -1
local comboPoints = {}
local group1AuraSize, group2AuraSize, group3AuraSize

    for i = 1, #activeRegions do
        if activeRegions[i].data.config.group then
            group[activeRegions[i].data.config.group] = group[activeRegions[i].data.config.group] or {}
            table.insert(group[activeRegions[i].data.config.group], i)
        elseif activeRegions[i].data.triggers[1].trigger.powertype == 4 then
            table.insert(comboPoints, i)
        else
            newPositions[i] = {0, 0}
        end
    end

    if #comboPoints > 0 then
        local barWidth = (powerBarWidth - (#comboPoints - 1) * comboSpace) / #comboPoints
        for i, auraIndex in ipairs(comboPoints) do
            activeRegions[auraIndex].region:SetWidth(barWidth)
            activeRegions[auraIndex].region.bar.totalWidth = barWidth
            newPositions[auraIndex] = {
                (i - 1) * (barWidth + comboSpace) + barWidth / 2 - powerBarWidth / 2,
                0
            }
        end
    end

    if group[1] then
        group1AuraSize = (powerBarWidth - (#group[1] - 1) * space) / #group[1]
        for i, auraIndex in ipairs(group[1]) do
            activeRegions[auraIndex].region:SetSize(group1AuraSize, group1AuraSize)
            newPositions[auraIndex] = {
                (i - 1) * (group1AuraSize + space) + group1AuraSize / 2 - powerBarWidth / 2,
                (-1) * (powerBarHeight + group1AuraSize / 2 + space)
            }
        end
    end

    group1AuraSize = group1AuraSize or 0

    if group[2] then
        group2AuraSize = (powerBarWidth - (#group[2] - 1) * space) / #group[2]
        for i, auraIndex in ipairs(group[2]) do
            activeRegions[auraIndex].region:SetSize(group2AuraSize, group2AuraSize)
            newPositions[auraIndex] = {
                (i - 1) * (group2AuraSize + space) + group2AuraSize / 2 - powerBarWidth / 2,
                (-1) * (powerBarHeight + group1AuraSize + group2AuraSize / 2 + 2 * space)
            }
        end
    end

    group2AuraSize = group2AuraSize or 0

    if group[3] then
        local auraPerRow = (#group[3] % 2 == 0 and #group[3] or #group[3] - 1) / 2
        if auraPerRow > 0 then
            group3AuraSize = ((powerBarHeight + group1AuraSize + group2AuraSize + 2 * space) - (auraPerRow - 1) * space) / auraPerRow
        end
        for i, auraIndex in ipairs(group[3]) do
            if i <= auraPerRow then
                activeRegions[auraIndex].region:SetSize(group3AuraSize, group3AuraSize)
                newPositions[auraIndex] = {
                    -1 * (powerBarWidth / 2 + group3AuraSize / 2 + space),
                    -1 * ((i - 1) * (group3AuraSize + space) + group3AuraSize / 2)
                }
            elseif i <= auraPerRow * 2 then
                activeRegions[auraIndex].region:SetSize(group3AuraSize, group3AuraSize)
                newPositions[auraIndex] = {
                    powerBarWidth / 2 + group3AuraSize / 2 + space,
                    -1 * ((i - auraPerRow - 1) * (group3AuraSize + space) + group3AuraSize / 2)
                }
            else
                newPositions[auraIndex] = {0, 0, false}
            end
        end
    end
end

custom text

example “blade dance”

function() return string.format('%d', aura_env.count) end

complex weakauras

example “advanced mythic keystone”

“Open Vault (Init)”

local r = aura_env.region if not r.MPlusButton then r.MPlusButton = CreateFrame("BUTTON", nil, r) end r.MPlusButton:SetAllPoints() r.MPlusButton:RegisterForClicks("AnyUp") r.MPlusButton:SetScript("OnClick", function() WeeklyRewardsFrame:Show() end ) r.MPlusButton:SetScript("OnEnter", function() WeakAuras.ScanEvents("BETTER_MYTHIC_PLUS_VAULT_ENTER", true) end ) r.MPlusButton:SetScript("OnLeave", function() WeakAuras.ScanEvents("BETTER_MYTHIC_PLUS_VAULT_LEAVE", true) end ) LoadAddOn("Blizzard_WeeklyRewards")

“R.IO Trigger”

Checks if RaiderIO exists on event BETTER_MYTHIC_PLUS

function(e, nilc) if (IsAddOnLoaded("RaiderIO")) then return e == "BETTER_MYTHIC_PLUS" and nilc else return end end

example ""

READY_CHECK, UNIT_INVENTORY_CHANGED, BAG_UPDATE_DELAYED

triggers and variables

Action Usable

Checks whether a specified spell is able to be used.

note

This directly correlates with the way it is displayed on the action bar; if the spell would be grayed out (its proc conditions are not met, or there is not enough mana/rage/etc. to cast it) or is on cooldown, then this trigger will not be active.

Action Usable triggers provide Duration Info, Icon Info, and Name Info, but do not show stacks.

Trigger Options:

  • Spell: The name of the spell to be checked. It is only possible to specify a spell that is currently in your spellbook. If this option is not enabled, the trigger will always be active.
  • Require Valid Target: If this option is enabled, the trigger will only be active if the current target is a valid target for the spell. Note that some spells, like AoE spells, cannot have a “valid” target.

Related