[SOLVED] Miirkat Druid Portraits

Hi

took me a minute to find this addon. It’s old. :grin:

Formatting can be done in multiple ways.

Inline formatting is done by enclosing the text in ` (grave accent) like `yourCode`. Alternatively use [code]yourCode[/code]

Block formatting is done by adding four spaces before each line. Alternatively use

[code]
function()
  return;
end
[/code]

Now to fixing the addon

When BfA was released, some functions got changed so that they might not return the same information as before or in a different order, take different arguments and so on. If you are interested, you can find more about that in Battle for Azeroth Addon Changes.

The addon uses the function UnitBuff() in line 15:

local id = select(11,UnitBuff(self.unit, i))

UnitBuff() dropped its second return parameter so that select() in the line above no longer returns the needed spellId. To get the spellId the first argument of select() needs to be changed to 10.

Though it works for Travel, Bear, Cat, Moonkin and Tree of Life forms, it doesn’t work for Flight forms. They are both still Travel Form.

You would need to add following code after line 19 to show an icon for Flight Form.

local _, _, flightSpeed = GetUnitSpeed(self.unit)
if id == 783 and flightSpeed > 10 then
    id = 40120
end

If the druid has Travel Form and has a high flight speed they should be flying. :sweat_smile:

Regarding your own solution (long read)
AuraUtil.FindAuraByName(self.unit, i)

The function call above will not work because AuraUtil.FindAuraByName() takes three arguments: auraName, unit and filter. The last one is optional. You are missing the first one auraName and i is an index variable which is useless in this case. A correct function call:

AuraUtil.FindAuraByName("Cat Form", "player")

Your second edit goes into the right direction, but still has some issues. I don’t know how much knowledge you have in programming or Lua/WoW API. Every time the UnitFramePortrait is updated, the addon checks if the unit, which frame was updated, is a druid. If so, it will iterate over all auras of the druid and look if any of them corresponds to shape shifting.

This is done through the implementation of the while loop:

while UnitBuff(self.unit, i) do

This reads as while buff of unit at position i is not nil do. This works because i is increasing and at some point UnitBuff() will return nothing (nil) and end the loop. In the loop the addon checks if one of the unit auras is a druid form.

AuraUtil.FindAuraByName(spellName, unitId) doesn’t work with this implementation since it can’t be used to iterate over all unit auras. It rather gives you information of a specific aura by name.

You would need to throw away the while loop and work with if statements. And rather than copying the if statements you would put the druid forms in a table and use a for loop.

local druidForms = {
    [768]="Cat Form",
    [783]="Travel Form",
    [1066]="Aquatic Form",
    [5487]="Bear Form",
    [24858]="Moonkin Form",
    [33891]="Incarnation: Tree of Life",
    [33943]="Flight Form",
    [40120]="Swift Flight Form"
}
for _, druidForm in pairs(druidForms) do
    local spellId = select(10, AuraUtil.FindAuraByName(druidForm, self.unit))
    if spellId then
        SetPortraitToTexture(self.portrait, GetSpellTexture(spellId))
        self.portrait:SetTexCoord(0, 1, 0, 1)
        flag = true
    end
end

Regards

1 Like