[Help] Nameplate Aura Whitelist

I’ve been trying to get this script working to clear the nameplate auras and whitelist my own, but I’ve been having a few problems. The script shows auras by name, and some abilities share the same name (Disable slow/root, Rake bleed/stun). If there’s anyone on the forums who can help, please let me know if there’s a way to add additional whitelisted auras by spell ID. I’ve spent ages trying to get this to work.

local whitelist = {
	["Aura 1"] = "player";
	["Aura 2"] = "pet";
	["Aura 3"] = "all";
}
local function newShouldShowBuff(_,name,caster)
    return name and caster and (whitelist[name] == caster or whitelist[name] == "all")
end
local function Mixin(baseFrame)
  baseFrame.UnitFrame.BuffFrame.ShouldShowBuff = newShouldShowBuff
end
local f = CreateFrame("Frame")
f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
f:SetScript("OnEvent", function(_,_,unitId)
  Mixin(C_NamePlate.GetNamePlateForUnit(unitId))
end)
for _,baseFrame in pairs(C_NamePlate.GetNamePlates()) do
  Mixin(baseFrame)
end

The final code so far, in full, so anyone interested doesn’t have to piece it together:

local whitelist = {
--	[116095] = "player", -- Disable WW Monk Slow
--	[113746] = "player", -- Mystic Touch
	[116706] = "all", -- Disable WW Monk Root
	[137639] = "player", -- Storm, Earth, and Fire buff spell for player
--	[nnnn] = "all", -- Other spell from anyone
}

local function newShouldShowBuff(self, name, caster, nameplateShowPersonal, nameplateShowAll, duration)
--	if not caster then return end
	local filter = "INCLUDE_NAME_PLATE_ONLY"
	if UnitIsUnit(self.unit, "player") then
		filter = "HELPFUL|".. filter
	else
		filter = "HARMFUL|".. filter
	end
	for i=1, BUFF_MAX_DISPLAY do 
		local spellName, _, _, _, spellDuration, _, spellCaster, _, _, spellId = UnitAura(self.unit, i, filter);
		if not spellName then break end
		if name == spellName and caster == spellCaster and duration == spellDuration then -- fingers crossed we're testing for the same aura
			if (caster and whitelist[spellId] == spellCaster) or whitelist[spellId] == "all" then
				return true
			end
			break
		end
	end
	return false
end
local function Mixin(baseFrame)
	baseFrame.UnitFrame.BuffFrame.ShouldShowBuff = newShouldShowBuff
end
local f = CreateFrame("Frame")
f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
f:SetScript("OnEvent", function(_,_,unitId)
	Mixin(C_NamePlate.GetNamePlateForUnit(unitId))
end)
for _,baseFrame in pairs(C_NamePlate.GetNamePlates()) do
	Mixin(baseFrame)
end

The original post for those with too much time on their hands :wink:

Untested but maybe something like:

local whitelist = {
	[12345] = "player",
	[6789] = "pet",
}
function NameplateBuffContainerMixin:ShouldShowBuff(name, caster, nameplateShowPersonal, nameplateShowAll, duration)
	for i= 1, BUFF_MAX_DISPLAY do 
		local spellName, _, _, _, _, _, _, _, _, spellId = UnitBuff(self.unit, i)
		if not spellName then return end
		if spellName == name and (whitelist[spellId] == caster or whitelist[spellId] == "all") then
			return true
		end
	end
end

Nope, doesn’t do anything but clear the auras.

self.unit will be nameplate1, nameplate2 etc.
You can check UnitIsUnit(self.unit, “player”) or UnitIsUnit(self.unit, “pet”) to see if it belongs to those units in the table.

When I change it to “player” it just shows the target marker icons on nameplates. I don’t know Lua, I’m just trying to get this one script to work.

The spell ids in the table were bogus just for example.

Using the original code, if you replace them with real ones for your character, it should work.

I did replace the spell ID with 116095 which is the ID for the Disable slow. Nothing shows up. The script I posted originally is tested and working by spell name. The only thing I want to do is add to that script so that I can also use spell ID to whitelist the auras.

If they are being cast on a target/enemy then you need to use UnitDebuff instead of UnitBuff.

I think you’re on the right track here, but even when it shows Disable by spell ID, it still shows other debuffs with the same name. I think it may be checking the ID and displaying the resulting name instead of only that ID. I appreciate your help, by the way.

Something like:

local whitelist = {
	[116095] = "player", -- Disable Monk
	[113746] = "player", --Mystic Touch
}
local function newShouldShowBuff(self, name, caster)
	for i= 1, BUFF_MAX_DISPLAY do 
		local spellName, _, _, _, _, _, castUnit, _, _, spellId = UnitDebuff(self.unit, i)
		if not spellName then break end
		if name == spellName and caster == castUnit and (whitelist[spellId] == caster or whitelist[spellId] == "all") then
			return true
		end
	end
	return false
end

I’m not sure how accurate that is.

It no longer displays any auras. I’m not sure why.

local whitelist = {
	[116095] = "player", -- Disable: Monk
	[113746] = "player", -- Mystic Touch: Monk
}
local function newShouldShowBuff(self, name, caster, nameplateShowPersonal, nameplateShowAll, duration)
	for i= 1, BUFF_MAX_DISPLAY do 
		local spellName, _, _, _, _, _, _, _, _, spellId = UnitDebuff(self.unit, i)
		if not spellName then break end
		if name == spellName and (whitelist[spellId] == caster or whitelist[spellId] == "all") then
			return true
		end
	end
	return false
end
local function Mixin(baseFrame)
	baseFrame.UnitFrame.BuffFrame.ShouldShowBuff = newShouldShowBuff
end
local f = CreateFrame("Frame")
f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
f:SetScript("OnEvent", function(_,_,unitId)
	Mixin(C_NamePlate.GetNamePlateForUnit(unitId))
end)
for _,baseFrame in pairs(C_NamePlate.GetNamePlates()) do
	Mixin(baseFrame)
end

It still shows auras of the same name. The Disable slow, Disable root, and Mystic Touch are shown.

I don’t Monk so I’m not sure of the difference, I thought they were the same id but if already snared (slowed) when cast, they are then rooted… so to speak.
You can print(spellName, spellId) and check what IDs UnitDebuff is returning and check with WoWHead to see what they should be if you don’t already have them.

The slow is 116095 and the root is 116706. The Rake stun and bleed behave the same way (same name, different ID’s).

Maybe I’m doing it wrong but I get the same debuffs as my target frame. If I comment out the Mystic Touch entry in the table then it doesn’t show on the target nameplate.

Edit: They appear to be interactive. If I comment out 116706 I get both and if I comment 116095 out nothing on the first application and both on the second.

No, I just isolated the script and ran it without other AddOns, and the filter works, but it still shows auras with identical names as the whitelisted spell ID’s. I’m pretty sure what it’s doing is searching through the debuffs for the spell ID, pulling the name, and displaying debuffs of that name.

Because the debuff is active twice it will always find an entry in the table even if only one spellid because the debuff list is being process from start to finish for each nameplate buff being tested. It would work it there were only ever one debuff of the same name but different ids in effect.

Back to the drawing board.

An alternative solution would be to whitelist spells by name and then blacklist specific ID’s. A strict whitelist would be a more ideal solution, but if it can’t be done, maybe that is an option.

I’m not sure how far this will go ie. not sure if spells with the same name and differend ids also have a different duration but…

local function newShouldShowBuff(self, name, caster, nameplateShowPersonal, nameplateShowAll, duration)
	for i= 1, BUFF_MAX_DISPLAY do 
		local spellName, _, _, _, spellDuration, _, _, _, _, spellId = UnitAura(self.unit, i, "HARMFUL|INCLUDE_NAME_PLATE_ONLY");
		if not spellName then break end
		if name == spellName and spellDuration == duration and (whitelist[spellId] == caster or whitelist[spellId] == "all") then
			return true
		end
	end
	return false
end