You guys copying arena macros into addons need to do some reading on good Lua coding practices. Everything any of you posts is full of leaked globals, unnecessary variables that don't even save space in the original macro versions, glaring general inefficiencies, horrible readability with inconsistent or no indentation, etc.
Anyway, you probably just need to force an update after someone leaves a vehicle:
Code:
local careUnits = {
-- Likely, there are fewer units you do care about
-- than units you don't, so this is easier to maintain.
-- We need the frame references for forced updates later.
["party1"] = PartyMemberFrame1,
["party2"] = PartyMemberFrame2,
["party3"] = PartyMemberFrame3,
["party4"] = PartyMemberFrame4,
}
local CLASS_ICON_TCOORDS = CLASS_ICON_TCOORDS
local function UpdateClassPortrait(self)
local unit, portrait = self.unit, self.portrait
-- This saves a few table lookups.
if not careUnits[unit] or not portrait then
-- We do not care about this unit,
-- or this frame does not have a portrait.
return
end
local _, class = UnitClass(unit)
local coords = CLASS_ICON_TCOORDS[class]
if coords then
portrait:SetTexture("Interface\\TargetingFrame\\UI-Classes-Circles")
portrait:SetTexCoord(unpack(coords))
end
end
hooksecurefunc("UnitFramePortrait_Update", UpdateClassPortrait)
-- Force an update when a unit leaves a vehicle.
local f = CreateFrame("Frame")
f:RegisterEvent("UNIT_EXITED_VEHICLE")
f:SetScript("OnEvent", function(self, event, unit)
local frame = careUnits[unit]
if frame then
UpdateClassPortrait(frame)
end
end)