Originally Posted by elcius
lua has no problem with very large tables, just make an itemid to setid lookup table.
~ Snip
|
While your method would be ideal, it doesn't really do what the author intended.
I believe they want to have the tooltip show every set that contains a particular itemID not just the first one that returns true.
Lua Code:
local setName = {
[1] = { name = "Mystic's Regalia (Recolor)", items = {14090, 26008, 14094}, },
-- [2......1778]
[1779] = { name = "Imperial Plate", items = {31436, 30002, 12424, 12425, 12422, 12427, 12429}, },
}
-- make lookup table, this will create a list that looks something like this
--[[
local table = {
[14090] = {201,560,888} -- Item id = Table of setName[index] values
}
]]
local itemSet = {}
do
for i,set in pairs(setName) do -- Looks through all the set
for j, id in pairs(set['items']) do -- looks though just the items table within
if not itemSet[id] then itemSet[id] = {} end -- creates a table within itemSet for each id (only once)
tinsert(itemSet[id], i) -- inserts each set index into the table
end
end
end
function addline_gametip()
local itemName,itemLink = GameTooltip:GetItem();
if not itemLink then return end
local itemId = tonumber(itemLink:match('item:(%d+)'));
if itemSet[itemId] then -- if a set is found
for i, setIndex in pairs(itemSet[itemId]) do -- for each index the id has
GameTooltip:AddLine("Transmog Set: " .. setName[setIndex]['name']); -- add a line to the game tooltip
end
end
end
GameTooltip:HookScript("OnTooltipSetItem", addline_gametip);