WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Item Socket Count (https://www.wowinterface.com/forums/showthread.php?t=24762)

dirtygurl 06-14-09 06:35 PM

Item Socket Count
 
How do you get the number of sockets in an item? I can get the filled socket count easy. Is there anything special I need to do to be able to do this?

dirtygurl 06-16-09 09:10 PM

Okay, answering my own question. I found a post here that helped me find which functions I needed to extract data.

Since "Interface\\ItemSocketingFrame\\UI-EmptySocket-Red" is the texture output from the temporary tooltip; you can essentially get the color of the sockets as well.

The only problem I had was doing a raw filter seemed to produce the extra socket from the Eternal Belt Buckle. So the gem was currently equipped for the raw id but the original gem was empty. I wasn't sure how to clear the cache of that but I assume there is a way.
Code:

-- hooks
GameTooltip:HookScript("OnTooltipSetItem", GameTooltip_OnTooltipSetItem)

-- func
function GameTooltip_GetSocketInfo(link, raw)
  local total = 0
  local gem1, gem2, gem3, gem4 = link:match("item:%d+:%d+:(%d+):(%d+):(%d+):(%d+)")
  local filled = (gem1 ~= "0" and 1 or 0) + (gem2 ~= "0" and 1 or 0) + (gem3 ~= "0" and 1 or 0) + (gem4 ~= "0" and 1 or 0)
  local TmpTooltip = CreateFrame("GameTooltip", "TmpTooltip", nil, "GameTooltipTemplate")
  TmpTooltip:SetOwner(UIParent, "ANCHOR_NONE")
  if raw then
    local id = link:match("item:(%d+)")
    local _, rawlink = GetItemInfo(id)
    TmpTooltip:SetHyperlink(rawlink)
  else
    TmpTooltip:SetHyperlink(link)
  end
  for i = 1, 10 do
    local TmpTooltipTextureId = "TmpTooltipTexture"..i
    if _G[TmpTooltipTextureId] then
      local TmpTooltipTexture = _G[TmpTooltipTextureId]:GetTexture()
      if TmpTooltipTexture and string.find(TmpTooltipTexture, "EmptySocket") then
        total = total + 1
      end
    end
  return total, filled
end

function GameTooltip_OnTooltipSetItem()
  local _, iLink = GameTooltip:GetItem()
  if iLink then
    local total, filled = GameTooltip_GetSocketInfo(iLink, false)
    local total1, filled2 = GameTooltip_GetSocketInfo(iLink, true) -- raw
[...]
  end
end



All times are GMT -6. The time now is 09:58 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI