View Single Post
05-12-18, 12:21 AM   #1
Herpopotamus
A Defias Bandit
Join Date: May 2018
Posts: 2
Agony weak aura with nameplate glow

Hello,

I am new to LUA and am taking my first crack at writing a custom weak aura with mixed success.

The goal: cause an enemy nameplate to glow while Agony (cast by the player) has 4 seconds or less remaining

I have managed to make an aura that will cause the nameplates to glow while the player's Agony debuff is on them, however when I add a check for the duration, everything goes haywire. Some of the nameplates don't light up, and the ones that do never stop glowing even after Agony falls off. I feel like I am missing something really basic here.


Some of the code below talks about "orbs." This is because I am using lots of code from an aura that causes the nameplats of the fel orbs in mythic+ dungeons to light up.

Here is the code I have for the custom trigger (checked every frame)
Code:
function()
    local _,type = GetInstanceInfo()
    if (type == 'party' or aura_env.test) and (GetCVar("nameplateShowAll")=="0" or GetCVar("nameplateShowEnemies") == "0" ) then 
        if aura_env.autoEnemyNameplates then SetCVar("nameplateShowEnemies",1) end
        if aura_env.autoAllNameplates then SetCVar("nameplateShowAll",1) end
    end
    local orbsUp = 0
    local markIndex = 1
    for i=1,40 do --for each nameplate
        local unit = "nameplate"..i 
        local hasAgony = false
        --print(unit)
        if UnitExists(unit) then
            for j=1,40 do --for each debuff on a nameplate
                --print("orbs: "..orbsUp)
                local guid = UnitGUID(unit)
                local type, zero, server_id, instance_id, zone_uid, npc_id, spawn_uid = strsplit("-",guid)
                --print(npc_id)
                local name,_,_,_,_,_,etime=UnitDebuff(unit, j, "PLAYER")
                local duration = etime - GetTime()
                --print(name)
                --print(durations)
                if name == nil then --break if we have checked all debuffs
                    break
                end
                if name == "Agony" and duration <= 4 then --turn sentinel on if we find Agony and end the loop
                    hasAgony = true
                    break
                end
            end --end debuff checking loop
            
            --turn on nameplate glow if we found agony, otherwise turn it off
            if hasAgony or aura_env.test then
                orbsUp = orbsUp + 1
                aura_env.glow(unit,true)
            else
                aura_env.glow(unit,false)
            end
            
        end
    end --end nameplate checking loop
    
    aura_env.orbs = orbsUp
    if  aura_env.icon and orbsUp > 0 then
        WeakAuras.regions[aura_env.id].region:SetAlpha(1)
    elseif orbsUp <1 then
        for i,v in pairs(aura_env.nameplates) do
            ActionButton_HideOverlayGlow(v)
        end
        WeakAuras.regions[aura_env.id].region:SetAlpha(0)
    end
    return true
end

Here is the code for the "on init" section of the action tab:
Code:
local enableGlow = true -- glow
local enableIcon = false -- show icon
local enableMarks = false -- assign marks 

local showEnemyNameplates = false  -- Auto Enable Show Enemy Nameplates
local alwaysShowNameplates = false -- Auto Enable Always Show Nameplates
-- Assumes that you usually have them disabled. Will enable them when entering m+ dungeon and disable when exiting. Don't enable this if you usually are running with them enabled because it will still disable them. 

---------------------------------------
local tidyplatesHeight = 8
aura_env.test = false -- change to make all nameplates glow for testing 
aura_env.nameplates = {}
aura_env.glow = function(unit,show)
    --print(unit)
    local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
    if not nameplate then return end
    if enableGlow and show then
        if nameplate.unitFrame and nameplate.unitFrame.HealthBar then
            -- elvui
            ActionButton_ShowOverlayGlow(nameplate.unitFrame.HealthBar)
            nameplate = nameplate.unitFrame.HealthBar
        elseif nameplate.kui then
            -- kui
            ActionButton_ShowOverlayGlow(nameplate.kui.HealthBar)
            nameplate = nameplate.kui.HealthBar
        elseif nameplate.extended then
            -- tidyplates
            nameplate.extended.visual.healthbar:SetHeight(tidyplatesHeight)
            ActionButton_ShowOverlayGlow(nameplate.extended.visual.healthbar)
            nameplate = nameplate.extended.visual.healthbar
        elseif nameplate.TP_Extended then
            -- tidyplates: threat plates
            ActionButton_ShowOverlayGlow(nameplate.TP_Extended.visual.healthbar)
            nameplate = nameplate.TP_Extended.visual.healthbar
        elseif nameplate.ouf then
            -- bdNameplates
            ActionButton_ShowOverlayGlow(nameplate.ouf.Health)
            nameplate = nameplate.ouf.Health
        elseif nameplate.UnitFrame then 
            -- default
            ActionButton_ShowOverlayGlow(nameplate.UnitFrame.healthBar)
            nameplate = nameplate.UnitFrame.healthBar
        else
            ActionButton_ShowOverlayGlow(nameplate)
        end
        aura_env.nameplates[unit] = nameplate
    else
        if nameplate.UnitFrame and nameplate.UnitFrame.HealthBar then
            -- elvui
            ActionButton_HideOverlayGlow(nameplate.UnitFrame.HealthBar)
        elseif nameplate.kui then
            -- kui
            ActionButton_HideOverlayGlow(nameplate.kui.HealthBar)
        elseif nameplate.extended then
            -- tidyplates
            ActionButton_HideOverlayGlow(nameplate.extended.visual.healthbar)
        elseif nameplate.TP_Extended then
            -- tidyplates: threat plates
            ActionButton_HideOverlayGlow(nameplate.TP_Extended.visual.healthbar)
            nameplate = nameplate.TP_Extended.visual.healthbar
        elseif nameplate.ouf then
            -- bdNameplates
            ActionButton_HideOverlayGlow(nameplate.ouf.Health)
        elseif nameplate.UnitFrame then
            -- default
            ActionButton_HideOverlayGlow(nameplate.UnitFrame.healthBar)
        else
            ActionButton_HideOverlayGlow(nameplate)
        end
        --aura_env.nameplates[unit] = nil
        print(unit)
    end 
end

aura_env.orbs = 0
aura_env.icon = enableIcon
aura_env.marks = enableMarks
aura_env.npcID = { -- possible to add more 
    [120651] = true, -- fel explosives
    -- [92168] = true, -- testingdummies
    -- [92166] = true, -- testingdummies
}
aura_env.marksBlocked = false
aura_env.autoEnemyNameplates = showEnemyNameplates
aura_env.autoAllNameplates = alwaysShowNameplates

Here is the code for the "on hide" section of the action tab - I don't think this matters at all since the trigger function always returns true, but here it is for the sake of completion:
Code:
for i,v in pairs(aura_env.nameplates) do
    local unit = v 
    local hasAgony = false
    if UnitExists(unit) then
        for j=1,40 do --for each debuff on a nameplate
            local guid = UnitGUID(unit)
            local type, zero, server_id, instance_id, zone_uid, npc_id, spawn_uid = strsplit("-",guid)
            local name,_,_,_,_,_,etime=UnitDebuff(unit, j, "PLAYER")
            local duration = etime - GetTime()
            
            --if Agony is gone or refreshed, turn off nameplate glow
            if name == "Agony" and duration > 4 or name == nil then
                aura_env.glow(unit,false)
            end
        end --end debuff checking loop
    end
end --end nameplate checking loop
  Reply With Quote