Thread Tools Display Modes
08-04-16, 05:20 AM   #1
Zavian
A Deviate Faerie Dragon
 
Zavian's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 10
Defining the armor type

Hello everyone, I come here because I have a pretty annoying problem with the implementation of a function for my addon. I'm trying to determine the armor type that the user has dropped to understand if the user wants it or not (determined by an external variable). The goal is, with this function, to return either "plate", "mail", "leather" or "cloth" depending on the armor type the user dropped to, after, fetch from the variables the user specifications.
Code:
function ArmorType(item)
	local _, _, _, _, _, class, subclass, _, equipSlot, _, _ = GetItemInfo(item)
	local cloth =	select(2, GetAuctionItemSubClasses(2))
	local leather =	select(3, GetAuctionItemSubClasses(2))
	local mail =	select(4, GetAuctionItemSubClasses(2))
	local plate =	select(5, GetAuctionItemSubClasses(2))
	local returner = ""
	if class ~= ARMOR then return nil end
	if subclass ~= MISCELLANEOUS then
		if subclass == plate then
			returner = "plate"
		elseif subclass == mail then
			returner = "mail"
		elseif subclass == leather then
			returner = "leather"
		elseif subclass == cloth then
			returner = "cloth"
		else returner = nil end
	else
		equipSlot = equipSlot:gsub("INVTYPE_", "")
		returner = equipSlot == "TRINKET" and "trinkets" or
			equipSlot == "NECK" and "necks" or
			equipSlot == "FINGER" and "rings" or nil
	end
	return returner
end
As you might imagine the part of the fingers, necks and trinkets do work since those are non-localized strings contained in the equipSlot variable, but the armor types are not working since the subclass is a localized string of the armor type. I tried to look around in the GlobalStrings.lua for something recalling these classes but with no luck and in the code you see I tried to work with the GetAuctionItemSubClasses which unfortunately it returns a number instead of a localized text (which I believe used to do before the pre-patch). Am I missing something obvious?

Sorry if my writings are convoluted or if I butchered some english, but as you may understand it's not my main language. Feel free to ask for better expanations
__________________
Developer of PileSeller

Last edited by Zavian : 08-04-16 at 05:23 AM.
  Reply With Quote
08-04-16, 05:30 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Try using those numbers with GetItemClassInfo. Also, I think you get those same numbers directly from GetItemInfo in the last return arguments.

Edit: GetItemSubClassInfo, even, I guess.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
08-04-16, 05:52 AM   #3
Zavian
A Deviate Faerie Dragon
 
Zavian's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 10
Thank you for the fast answer, it's exactly what I've been looking for. Strangely enough on wowprogramming these functions (and the last parameters of GetItemInfo) are not documented, but anyhow thank you
__________________
Developer of PileSeller
  Reply With Quote
08-04-16, 06:54 AM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Zavian View Post
Thank you for the fast answer, it's exactly what I've been looking for. Strangely enough on wowprogramming these functions (and the last parameters of GetItemInfo) are not documented, but anyhow thank you
Since Jim White "Cladhaire" retired arguably from WoW, wowprogramming has had less and less functionality, and almost no updates.

Try wowpedia.org instead.
  Reply With Quote
08-04-16, 12:27 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Remember, wowprogramming is updatable by anyone, just like wowpedia.

Also, change this
Lua Code:
  1. local cloth =   select(2, GetAuctionItemSubClasses(2))
  2.     local leather = select(3, GetAuctionItemSubClasses(2))
  3.     local mail =    select(4, GetAuctionItemSubClasses(2))
  4.     local plate =   select(5, GetAuctionItemSubClasses(2))
to this
Lua Code:
  1. local _, cloth, leather, mail, plate = GetAuctionItemSubClasses(2)
and move it out of that function - those names will never change during your gameplay session.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-05-16, 11:06 PM   #6
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Here's code for determining all of the item classes and their associated subclasses:

Code:
do
	COMPILED_ITEM_CLASSES = {}
	local classIndex = 0
	local className = _G.GetItemClassInfo(classIndex)

	while className and className ~= "" do
		COMPILED_ITEM_CLASSES[classIndex] = {
			name = className,
			subClasses = {},
		}

		local subClassIndex = 0
		local subClassName = _G.GetItemSubClassInfo(classIndex, subClassIndex)

		while subClassName and subClassName ~= "" do
			COMPILED_ITEM_CLASSES[classIndex].subClasses[subClassIndex] = subClassName

			subClassIndex = subClassIndex + 1
			subClassName = _G.GetItemSubClassInfo(classIndex, subClassIndex)
		end

		classIndex = classIndex + 1
		className = _G.GetItemClassInfo(classIndex)
	end
end
You can then look at the table (it's globally declared) to see what's what. The starting index of 0 rather than 1 is intentional - they're actually used by Blizzard.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.

Last edited by Torhal : 08-05-16 at 11:14 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Defining the armor type

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