There were some issues at some lines.
For instance the logic for what texture to use is a bit awkward as the texture it should use already is defined in the groupUnit variable. Meaning we only need one check at the begining and draw our custom overlay if it doesn't exist, also apply texture there. The only thing the for loop further down needs to do is make the texture change color accordingly.
I've rewritten it and tried to clean it up a bit. Take a look. Perhaps it fixes some of the issues, perhaps not. I haven't actually tested it myself. Do write what happens though, I am interested.
Also yes I hooked the Minimap UpdateBlips function so when it runs our code run, kind of more synchronized that just randomly updating hoping to update at the right time. Besides the UpdateBlips function runs at lower intervals, so it won't be each frame update either. Good for us!
Code:
local addonName = ...
local padding = 5
local groupSize, groupType, frame
local _, subgroup, class, color
local elapsed = 0
WorldMapFrame:HookScript("OnUpdate", function(self, e)
elapsed = elapsed + e
if elapsed > .5 then -- update frequency
elapsed = 0
groupSize = GetNumGroupMembers()
if groupSize > 0 then
groupType = IsInRaid() and "Raid" or "Party"
for i = 1, groupSize do
frame = _G["WorldMap" .. groupType .. i]
if frame then
if not frame.overlay then
frame.overlay = frame:CreateTexture(nil, "OVERLAY")
frame.overlay:SetDrawLayer("OVERLAY", 7)
frame.overlay:SetPoint("TOPLEFT", frame.icon, -padding, padding)
frame.overlay:SetPoint("BOTTOMRIGHT", frame.icon, padding, -padding)
_, _, subgroup = GetRaidRosterInfo(i)
frame.overlay:SetTexture(groupType == "Raid" and ("Interface\\AddOns\\" .. addonName .. "\\blips\\raid" .. subgroup) or "Interface\\AddOns\\" .. addonName .. "\\blips\\party")
end
if frame.unit and frame:IsShown() then
_, class = UnitClass(frame.unit)
color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
if color then
frame.overlay:SetVertexColor(color.r, color.g, color.b)
else
frame.overlay:SetVertexColor(103/255, 103/255, 103/255)
end
if GetTime() % 1 < .5 then
if UnitAffectingCombat(frame.unit) then
frame.overlay:SetVertexColor(1, 0, 0)
elseif UnitIsDeadOrGhost(frame.unit) then
frame.overlay:SetVertexColor(.2, .2, .2)
elseif UnitIsAFK(frame.unit) then
frame.overlay:SetVertexColor(255/255, 206/255, 206/255)
end
end
end
end
end
end
end
end)