Thread: Item level
View Single Post
08-16-18, 06:53 AM   #4
runamonk
A Theradrim Guardian
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 61
What Ammako said. I've found the same issue in a couple of the addons I wrote. I ended up having to write a routine that parses the tooltip for the item and pulls the item level from there. I think this is what most people are doing, at least until the correct item level is returned by GetDetailedItemLevelInfo().

Lua Code:
  1. local function GetItemLevel(bagID, slotID, slot)
  2.     local link = GetContainerItemLink(bagID, slotID)
  3.     if link then
  4.         local tip, leftside = CreateFrame('GameTooltip', 'mnkBackpackScanTooltip'), {}
  5.         for i = 1, 5 do
  6.             local L, R = tip:CreateFontString(), tip:CreateFontString()
  7.             L:SetFontObject(GameFontNormal)
  8.             R:SetFontObject(GameFontNormal)
  9.             tip:AddFontStrings(L, R)
  10.             leftside[i] = L
  11.         end
  12.         tip:ClearLines()
  13.         tip.leftside = leftside
  14.         tip:SetOwner(UIParent, 'ANCHOR_NONE')
  15.         --print(link, ' ', slot.itemLevel)
  16.         -- Weird issue with the tooltip not refilling/painting with the details of a bank item. This
  17.         -- resolves that issue and it makes no sense why.
  18.         if bagID < 0 then
  19.             tip:ClearLines()
  20.             tip:SetHyperlink(link)
  21.         end
  22.         tip:ClearLines()
  23.         tip:SetBagItem(bagID, slotID)
  24.         tip:Show()
  25.         for l = 1, #tip.leftside do
  26.             local t = tip.leftside[l]:GetText()
  27.             if t and t:find('Item Level') then
  28.                 local _, i = string.find(t, 'Item Level%s%d')
  29.                 -- check for boosted levels ie Chromeie scenarios.
  30.                 local _, x = string.find(t, " (", 1, true)
  31.                 --print(t, ' ', x)
  32.                 if x then
  33.                     return string.sub(t, i, x-2) or nil
  34.                 end
  35.                 return string.sub(t, i) or nil
  36.             end
  37.         end
  38.         return nil
  39.     else
  40.         return nil
  41.     end
  42. end
  Reply With Quote