Thread Tools Display Modes
06-14-09, 06:35 PM   #1
dirtygurl
A Murloc Raider
 
dirtygurl's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 4
Question 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?
  Reply With Quote
06-16-09, 09:10 PM   #2
dirtygurl
A Murloc Raider
 
dirtygurl's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 4
Exclamation

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
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Item Socket Count


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off