View Single Post
05-15-18, 07:06 AM   #3
d87
A Chromatic Dragonspawn
 
d87's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 163
Lua Code:
  1. -- Construct your saarch pattern based on the existing global string:
  2. local S_ITEM_LEVEL   = "^" .. gsub(ITEM_LEVEL, "%%d", "(%%d+)")
  3. local strmatch = string.match
  4.  
  5. -- Create the tooltip:
  6. local scantip = CreateFrame("GameTooltip", "MyScanningTooltip", nil, "GameTooltipTemplate")
  7. scantip:SetOwner(UIParent, "ANCHOR_NONE")
  8.  
  9. local function GetItemLevelFromTooltip(itemLink)
  10.     -- Pass the item link to the tooltip:
  11.     scantip:SetHyperlink(itemLink)
  12.  
  13.     -- Scan the tooltip:
  14.     for i = 2, scantip:NumLines() do -- Line 1 is always the name so you can skip it.
  15.         local text = _G["MyScanningTooltipTextLeft"..i]:GetText()
  16.         if text and text ~= "" then
  17.         local itemLevel = strmatch(text, S_ITEM_LEVEL)
  18.             if itemLevel then
  19.                 return itemLevel
  20.             end
  21.         end
  22.     end
  23. end
  Reply With Quote