WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Defining the armor type (https://www.wowinterface.com/forums/showthread.php?t=54116)

Zavian 08-04-16 05:20 AM

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 :o

Lombra 08-04-16 05:30 AM

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.

Zavian 08-04-16 05:52 AM

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 :D

myrroddin 08-04-16 06:54 AM

Quote:

Originally Posted by Zavian (Post 317419)
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 :D

Since Jim White "Cladhaire" retired arguably from WoW, wowprogramming has had less and less functionality, and almost no updates.

Try wowpedia.org instead.

Seerah 08-04-16 12:27 PM

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.

Torhal 08-05-16 11:06 PM

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.


All times are GMT -6. The time now is 05:43 AM.

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