WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Aura filtering problems (https://www.wowinterface.com/forums/showthread.php?t=50689)

eiszeit 12-08-14 03:10 AM

Aura filtering problems
 
Good Morning,

I am trying to create an aura filter for my oUF layout and I am a bit struggling because it doesn't really work like I want it - and I have no idea why.

Especially the target is the one who bothers me.

Here's my filter code, which I am adding to my layout per

Lua Code:
  1. self.Buffs.CustomFilter = lib.AurasCustomFilter.target
  2. self.Debuffs.CustomFilter = lib.AurasCustomFilter.target

I've commented inside the code, what I am trying to do ... but yeah, it doesn't work out exactly.

Lua Code:
  1. local whitelist = cfg.debuffList
  2.  
  3. local isPlayer = {
  4.     player  = true,
  5.     pet     = true,
  6.     vehicle = true,
  7. }
  8.  
  9. local dispelList = {
  10.     DRUID   =   {Curse = true, Poison = true},
  11.     MAGE    =   {Curse = true},
  12.     PALADIN =   {Disease = true, Magic = true, Poison = true},
  13.     PRIEST  =   {Disease = true, Magic = true},
  14.     SHAMAN  =   {Curse = true, Disease = true, Poison = true}
  15. }
  16.  
  17. local _, playerClass = UnitClass('player')
  18. local dispel = dispelList[playerClass]
  19.  
  20.     -- FILTER
  21. lib.AurasCustomFilter = {
  22.     target = function(icons, unit, icon, name, _, _, _, dtype, _, _, caster, isStealable, shouldConsolidate, spellID, _, isBossAura, isCastByPlayer)
  23.         local _, instanceType = IsInInstance()
  24.         -- show when on whitelist
  25.         if whitelist[spellID] then
  26.             return true
  27.         -- show when is cast by boss
  28.         elseif isBossAura then
  29.             return true
  30.         -- show when in instance/party and npc (i.e. not boss, because isBossAura doesn't affect normal npc enemies)
  31.         elseif (instanceType == 'party' or instanceType == 'raid') and not UnitPlayerControlled(caster) then
  32.             return true
  33.         -- show when debuff and by me
  34.         elseif icon.isDebuff and isPlayer[caster] then
  35.             return true
  36.         -- show stealable buffs
  37.         elseif isStealable and not icon.isDebuff then
  38.             return true
  39.         -- show when by me and is not debuff
  40.         elseif isPlayer[caster] and not icon.isDebuff then
  41.             return true
  42.         -- hide rest
  43.         else
  44.             return false
  45.         end
  46.     end,
  47.     party = function(icons, unit, icon, name, _, _, _, dtype, _, _, caster, isStealable, shouldConsolidate, spellID, _, isBossAura, isCastByPlayer)
  48.         if isBossAura then
  49.             return true
  50.         elseif (dispel and dispel[dtype]) then
  51.             return true
  52.         else
  53.             return false
  54.         end
  55.     end,
  56.     focus = function(icons, unit, icon, name, _, _, _, dtype, _, _, caster, isStealable, shouldConsolidate, spellID, _, isBossAura, isCastByPlayer)
  57.         if isBossAura then
  58.             return true
  59.         elseif isPlayer[caster] then
  60.             return true
  61.         else
  62.             return false
  63.         end
  64.     end,
  65. }

Hopefully someone can help me with that.

And sorry, if this is the wrong forum, I thought it would fit because it affects my oUF layout. :)

Phanx 12-08-14 03:57 AM

What isn't working? How is what it's doing different than what you expect it to be doing?

Try adding print statements in there so you can see exactly what's happening; I would not recommend doing this while in a group or at a training dummy, however, unless you can read at superhuman speed.

eiszeit 12-08-14 04:05 AM

I coded while raiding, so couldn't spam my chat with print messages last night. That's where I found out, what was wrong.

The problem I have is that somehow in raid, it shows me *all* debuffs and ignores my filters, when I have line 31-32 in my filter. But when I delete them I don't have NPC buffs/debuffs on my target inside normal 5-man dungeons (like the alchemists in UBRS).

Oh, also I added in the OP that I also use this filter on my target buffs, not only debuffs:

Lua Code:
  1. self.Buffs.CustomFilter = lib.AurasCustomFilter.target
  2. self.Debuffs.CustomFilter = lib.AurasCustomFilter.target

Phanx 12-08-14 05:25 AM

Well, all else aside, calling IsInInstance() in your aura filtering function, which is called once per active aura per UNIT_AURA event -- so, potentially thousands of times per second in a raid -- is rather wasteful. Much better to keep track of that outside the function (create a separate frame if you need to) and refer to a variable inside.

As for the problem at hand, the caster unit can be -- and often is -- nil for auras applied by NPCs. Try changing this:

Code:

and not UnitPlayerControlled(caster) then
to this:

Code:

and not (caster and UnitPlayerControlled(caster)) then
Player-applied auras can also have a nil caster, but only if they're applied by players who don't currently have a unit token, so while you're in an instance that shouldn't really be an issue.

eiszeit 12-08-14 06:09 AM

Theoretically I don't need the IsInInstance anymore after that change, right? I mean I had it in my code just because I am sure I am in an instance or group - but if it works also out of a dungeon it's okay. Aslong buffs/debuffs from mobs are shown.

Phanx 12-08-14 08:58 AM

The problem is as I described -- buffs cast by players who are not currently in your group will also have a nil caster. If you don't care about that (mainly an issue in town) then no, you don't need to check that you're in an instance.

Also:

1. You may want to show all debuffs on yourself, even if you can't dispel them.

2. You can combine the first and third of these checks:
Code:

        -- show when debuff and by me
        elseif icon.isDebuff and isPlayer[caster] then
            return true
        -- show stealable buffs
        elseif isStealable and not icon.isDebuff then
            return true
        -- show when by me and is not debuff
        elseif isPlayer[caster] and not icon.isDebuff then
            return true

Since you want to show anything you cast, regardless of whether it's a debuff or not, you don't need to check if it is a debuff, and then again if it's not a debuff. ;)

eiszeit 12-08-14 09:42 AM

Quote:

Originally Posted by Phanx (Post 302039)
The problem is as I described -- buffs cast by players who are not currently in your group will also have a nil caster. If you don't care about that (mainly an issue in town) then no, you don't need to check that you're in an instance.

So, I would also see debuffs/buffs of people inside town, even if they are players?

Quote:

Originally Posted by Phanx (Post 302039)
Also:

1. You may want to show all debuffs on yourself, even if you can't dispel them.

You mean in the party part? Or also in target?

Quote:

Originally Posted by Phanx (Post 302039)
2. You can combine the first and third of these checks:
Code:

        -- show when debuff and by me
        elseif icon.isDebuff and isPlayer[caster] then
            return true
        -- show stealable buffs
        elseif isStealable and not icon.isDebuff then
            return true
        -- show when by me and is not debuff
        elseif isPlayer[caster] and not icon.isDebuff then
            return true

Since you want to show anything you cast, regardless of whether it's a debuff or not, you don't need to check if it is a debuff, and then again if it's not a debuff. ;)

Ah, thanks! Will test this when I am home from work (sadly, in 3 hours ....)

Phanx 12-08-14 02:51 PM

Quote:

Originally Posted by eiszeit (Post 302045)
So, I would also see debuffs/buffs of people inside town, even if they are players?

Yes, if the players have debuffs/buffs whose casters don't currently have valid unit tokens (eg. the buff was not cast by you -- the "player" unit -- or by someone in your group) you will see them. If that is unacceptable, you will still need to check for being in an instance, or use some other method, such as ignoring all debuffs/buffs on player units who are not in your group. Just try it and see.

eiszeit 12-08-14 03:53 PM

Quote:

Originally Posted by Phanx (Post 302071)
Yes, if the players have debuffs/buffs whose casters don't currently have valid unit tokens (eg. the buff was not cast by you -- the "player" unit -- or by someone in your group) you will see them. If that is unacceptable, you will still need to check for being in an instance, or use some other method, such as ignoring all debuffs/buffs on player units who are not in your group. Just try it and see.

I guess I'll leave it like that then ... maybe adding the IsInInstance()-Variant when I have an idea how I do that exactly.

Thanks again, Phanx! :)

Phanx 12-09-14 10:08 PM

Quote:

Originally Posted by eiszeit (Post 302079)
... maybe adding the IsInInstance()-Variant when I have an idea how I do that exactly.

Just do like I said, and move the IsInInstance check out of the filter function. If you don't already have a frame in that file that can listen for events (I have no idea if that's a whole file or just a snippet you posted) just create one.

Code:

lib.AurasCustomFilter = {
    target = function(icons, unit, icon, name, _, _, _, dtype, _, _, caster, isStealable, shouldConsolidate, spellID, _, isBossAura, isCastByPlayer)
        local _, instanceType = IsInInstance()

-->

Code:

local instanceType

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function()
    instanceType, instanceType = IsInInstance()
    -- yes, duplication is intentional, it avoids having to name another variable
    -- the second one overwrites the first one
end)

lib.AurasCustomFilter = {
    target = function(icons, unit, icon, name, _, _, _, dtype, _, _, caster, isStealable, shouldConsolidate, spellID, _, isBossAura, isCastByPlayer)


eiszeit 12-10-14 05:27 AM

That simple. Sometimes I can't see shit around me ... thanks again. I'll test it when I am home from work.


All times are GMT -6. The time now is 07:42 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI