Thread Tools Display Modes
10-05-16, 03:33 AM   #1
Marsgames
An Aku'mai Servant
 
Marsgames's Avatar
Join Date: Jul 2016
Posts: 33
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)
  Reply With Quote
10-06-16, 12:56 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 10-06-16 at 01:04 AM.
  Reply With Quote
10-06-16, 02:15 AM   #3
Marsgames
An Aku'mai Servant
 
Marsgames's Avatar
Join Date: Jul 2016
Posts: 33
Thank you so much, it does exactly what I wanted
  Reply With Quote
10-09-16, 03:14 AM   #4
Marsgames
An Aku'mai Servant
 
Marsgames's Avatar
Join Date: Jul 2016
Posts: 33
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.
  Reply With Quote
10-10-16, 03:55 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Gem Socket

Thread Tools
Display Modes

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