Since all the code is doing is matching items to set names, the lookup table doesn't need to be so complicated to use. Here's my example. There can be more optimizations depending on how you want the tooltip to look.
Lua Code:
local TransmogSets={
{
name="Mystic's Regalia (Recolor)",
items={14090, 26008, 14094},
},
{
name="Imperial Plate",
items={31436, 30002, 12424, 12425, 12422, 12427, 12429},
},
-- And so on ...
};
-- Lookup Table
local ItemSetNames={}; do
for _,set in ipairs(TransmogSets) do-- Scan through all sets
for _,itemid in ipairs(set.items) do-- Scan through items
-- Add set name to list in lookup table
if not ItemSetNames[itemid] then ItemSetNames[itemid]={}; end
table.insert(ItemSetNames[itemid],set.name);
end
end
-- Sorts set names
for _,list in pairs(ItemSetNames) do table.sort(list); end
end
-- Tooltip Hook
GameTooltip:HookScript("OnTooltipSetItem",function(self)
local _,link=self:GetItem();
if not link then return; end-- Exit if we have no item
local id=tonumber(link:match("|Hitem:(%d+)")) or 0;-- Force nil to zero if we have an invalid link (no items exist at index zero)
if ItemSetNames[id] then
for i,name in ipairs(ItemSetNames[id]) do
-- Only show our label on the first line
self:AddDoubleLine(i<=1 and "Transmog Set:" or " ",name);
end
end
end);
-- Chat Hook
ChatFrame_AddMessageEventFilter("CHAT_MSG_LOOT",function(self,event,msg,...)
local id=tonumber(msg:match("|Hitem:(%d+)")) or 0;-- Force nil to zero if we have an invalid link (no items exist at index zero)
if ItemSetNames[id] then return false,msg.." (|cff9400d3Transmog Sets: "..table.concat(ItemSetNames[id],", ").."|r).",...; end
end);
Edit: Replaced
string.join() section with more efficient
table.concat() call.