Friday, April 13, 2012

ItemString Socket Count

[:1]How would I get the original socket count from an ItemString? I can get the filled socket count; just not too sure how to get the original count because the ItemString is in a format of 0 fills for each gem. "item:0:0:gem1:gem2:gem3:gem4" In short I'm trying to figure out a way to check for Eternal Belt Buckle and Blacksmithing sockets.|||Okay, once again answering my own questions. 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

No comments:

Post a Comment