WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Gem Socket (https://www.wowinterface.com/forums/showthread.php?t=54604)

Marsgames 10-05-16 03:33 AM

Gem Socket
 
Hey, is there a way to know if an item has emty gem sockets ? (ex: when we kill a boss, know if the item looted has sockets, before get it)

Phanx 10-06-16 12:56 AM

You have to use tooltip scanning. Here's the code I use to find the number of sockets a given item has, with some added comments to explain what's going on:

Code:

local GetNumSockets
do
        -- Generate a unique name for the tooltip:
        local tooltipName = "PhanxScanningTooltip" .. random(100000, 10000000)

        -- Create the hidden tooltip object:
        local tooltip = CreateFrame("GameTooltip", tooltipName, UIParent, "GameTooltipTemplate")
        tooltip:SetOwner(UIParent, "ANCHOR_NONE")

        -- Build a list of the tooltip's texture objects:
        local textures = {}
        for i = 1, 10 do
                textures[i] = _G[tooltipName .. "Texture" .. i]
        end

        -- Set up scanning and caching:
        local numSocketsFromLink = setmetatable({}, { __index = function(t, link)
                -- Send the link to the tooltip:
                tooltip:SetHyperlink(link)

                -- Count how many textures are shown:
                local n = 0
                for i = 1, 10 do
                        if textures[i]:IsShown() then
                                n = n + 1
                        end
                end

                -- Cache and return the count for this link:
                t[link] = n
                return n
        end })

        -- Expose the API:
        function GetNumSockets(link)
                return link and numSocketsFromLink[link]
        end
end

Then you can just call GetNumSockets with the item link. It does add a little complexity to maintain a cache, so it'll only ever actually do the scanning once per item link, and if you call it with the same link again, it'll just give you the cached value.

It does not handle cases where the item isn't already in your local item cache, though -- in that case you'll need to wait and call it again once your client receives the item data.

And, though you didn't ask, here's how to count how many gems are currently on the item:

Code:

local _, itemID, enchantID, gem1, gem2, gem3, gem4 = strsplit(":", strmatch(link, "|H(.-)|h"))
local numFilledSockets = (tonumber(gem1) or 0) + (tonumber(gem2) or 0) + (tonumber(gem3) or 0) + (tonumber(gem4) or 0)


Marsgames 10-06-16 02:15 AM

Thank you so much, it does exactly what I wanted

Marsgames 10-09-16 03:14 AM

Sorry to bother you, but do you have a way to know the color of the gem socket ? (blue, red, meta, prismatic...) ?
It would be awesome.

Phanx 10-10-16 03:55 AM

The simplest way is probably to just look at the actual texture being displayed, eg. textures[i]:GetTexture() and match it up to known textures for each gem or socket color.

However, I'm about 90% sure that all sockets on modern items are explicitly prismatic (any color gem activates the socket bonus) and have been that way since WoD launched, and I'm not sure why you'd care whether the gem in a socket was a blue, orange, or any other color, so I don't really see a point in figuring out what color the gem or socket is.


All times are GMT -6. The time now is 08:49 AM.

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