View Single Post
08-14-15, 07:45 AM   #5
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by elcius View Post
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:
  1. local setName =  {
  2. [1] = {  name = "Mystic's Regalia (Recolor)", items = {14090, 26008, 14094}, },
  3. -- [2......1778]
  4. [1779] = {  name = "Imperial Plate", items = {31436, 30002, 12424, 12425, 12422, 12427, 12429}, },
  5. }
  6.  
  7. -- make lookup table, this will create a list that looks something like this
  8. --[[
  9. local table = {
  10.     [14090] = {201,560,888} -- Item id = Table of setName[index] values
  11. }
  12. ]]
  13. local itemSet = {}
  14. do
  15.     for i,set in pairs(setName) do -- Looks through all the set
  16.         for j, id in pairs(set['items']) do -- looks though just the items table within
  17.             if not itemSet[id] then itemSet[id] = {} end -- creates a table within itemSet for each id (only once)
  18.             tinsert(itemSet[id], i) -- inserts each set index into the table
  19.         end
  20.     end
  21. end
  22.  
  23. function addline_gametip()
  24.     local itemName,itemLink = GameTooltip:GetItem();
  25.     if not itemLink then return end
  26.    
  27.     local itemId = tonumber(itemLink:match('item:(%d+)'));
  28.     if itemSet[itemId] then -- if a set is found
  29.         for i, setIndex in pairs(itemSet[itemId]) do -- for each index the id has
  30.             GameTooltip:AddLine("Transmog Set: " .. setName[setIndex]['name']); -- add a line to the game tooltip
  31.         end
  32.     end
  33.  end
  34.  
  35.  
  36. GameTooltip:HookScript("OnTooltipSetItem", addline_gametip);

Last edited by suicidalkatt : 08-14-15 at 07:50 AM. Reason: spellcheck
  Reply With Quote