function UB_UnitAura(arg1) -- This bit deals with the first running of the code, establishes a table for whatever unit this is if not ubuffs[arg1] then ubuffs[arg1] = {} end local unitBuffs = ubuffs[arg1] -- Decrement all counts -- This bit sets all the previous run's buffs to "Old" for k,v in pairs(unitBuffs) do DEFAULT_CHAT_FRAME:AddMessage(k) DEFAULT_CHAT_FRAME:AddMessage(v) unitBuffs[k] = v - 1 end local i = 1 -- this bit checks the current buffs while true do -- loops over all the buffs local name,rank,count = UnitBuff(arg1, i) if not name then break --this means its run out of buffs and should end end if not unitBuffs[name] then -- this buff wasnt on the unit last cycle -- New buff unitBuffs[name] = 1 -- then its new elseif unitBuffs[name] == 0 then -- if this buff was on the target (but is now "old") --Buff still on from last cycle unitBuffs[name] = 1 -- then "refresh" it end i = i + 1 end -- Clean up any buffs with 0 for k,v in pairs(unitBuffs) do -- go over our table finding "old" buffs that weren't "refreshed" if v == 0 then unitBuffs[k] = nil -- if it wasnt refreshed remove from table, and we know it's faded. -- Buff expired end end end