View Single Post
02-22-23, 08:57 AM   #5
phatzz
A Defias Bandit
Join Date: Feb 2023
Posts: 3
Originally Posted by Fizzlemizz View Post
Return 7 from UnitDebuff would be unitID eg. "player", not the name.

Instead of calling the select and UnitDebuff functions twice each iteration you could use:

Code:
local spellName, _, _, _, _, _, unitID = UnitDebuff(unit, j)
if spellName == spellname and unitID == "player" then
	DebuffCount = DebuffCount + 1
end
Thank you both for the tips!
I was able to get it working before i read your latest reply, using this code - but i see your solution is more elegant.
I will now just remove the prints and incorporate this into my own little learning addon.
thanks again!

You were both helpful in identifying the faults in my code.
The first error was inded wrong index from google to the current WoW API.
The 2nd was the use of UnitName("player") that will return the actual name instead of "player".

Code:
local DebuffCount = 0
local spellname = "Stellar Flare"
local playerName = "player"
for i = 1, 20 do
  local unit = "nameplate" .. i
  if UnitExists(unit) then
    print("Found unit: " .. unit)
    for j = 1, 40 do
      local debuffName, _, _, _, _, _, _, _, _, _, _ = UnitDebuff(unit, j)
      if debuffName and debuffName == spellname and select(7, UnitDebuff(unit, j)) == playerName then
        print("Debuff found: " .. debuffName .. " on " .. unit)
        DebuffCount = DebuffCount + 1
      end
    end
  end
end
print("Total debuffs found: " .. DebuffCount)
return DebuffCount
  Reply With Quote