Jump to content

Recommended Posts

Is there a way in c# (plugin code for example) to get the stats from an item (vanilla 1.12)?  For example, I loot an item, I want to compare that item's stats, such as strength, intelligence, etc. and compare it against my equipped item.

Also, I have code to get the item when the character loots, I just need the code to get the stats.

I'm very comfortable with c#, not so comfortable with LUA.

TIA!

Link to comment
https://wrobot.eu/forums/topic/15223-get-an-items-stats-strength-int-agi-etc/
Share on other sites

I'm not entirely sure it will work for vanilla, since I've used it on TBC/Wotlk, but even then, there's no easy way to do this. The only way I know to read item stats is to create a LUA Frame, set its hyperlink to the item link you want to check, and read its regions.

You can check the LUASetup() method to get an idea how this works here https://github.com/Wholesome-wRobot/Wholesome-Inventory-Manager/blob/master/Helper/Toolbox.cs

After you've ran this setup, all you need is to call is ParseItemInfo(itemLink) in LUA to get your item stats. You'll have to adapt the code to whatever you want to do, obviously.

Although untested due to my current lack of a vanilla World of Warcraft installation, the following code snippet should serve as a helpful starting point for constructing the necessary functions to manage item states.

 

public class ToolTipReader
    {
        private static string TooltipName { get; set; }

        static ToolTipReader()
        {
            TooltipName = Others.GetRandomString(12);
        }

        public static void CreateTooltip()
        {
            Lua.LuaDoString($@"
                if not {TooltipName} then
                    {TooltipName} = CreateFrame('GameTooltip', '{TooltipName}', nil, 'GameTooltipTemplate'); 
                    {TooltipName}:SetOwner(UIParent, 'ANCHOR_NONE');
                end
            ");
        }

        public static void DestroyTooltip()
        {
            Lua.LuaDoString($"{TooltipName} = nil;");
        }

        public static string[] ItemStates(string itemLink)
        {
            return Lua.LuaDoString<string[]>($@"
                local StatsTable = {{}}
                {TooltipName}:ClearLines()
                {TooltipName}:SetHyperlink('{itemLink}')
                for i = 1, {TooltipName}:NumLines() do
                    local text = _G['ItemPurseTextLeft'..i]:GetText()
                    table.insert(StateTable, text)
                end
                return unpack(StatsTable);
            ");
        }
    }

 

  • 2 weeks later...

Just wanted to pop in and say for Vanilla it's really worth finding some of the older wiki entries regarding Tooltip handling in general. Tooltip handling in vanilla is very different from later expansions and honestly such a mess.

I don't think you can just destroy tooltips. For example, as far as I know, you can not get ToolTips to be garbage collected by just setting them back to 'nil'.
They will continue to exist and you're just dumping your memory full of new tooltips eventually. You absolutely need to reuse the tooltip and clear all lines as well as assigning a new owner.

As far as I remember, in Vanilla you even need to manually delete some sub texts on the tooltip because it's such a rudimentary (buggy) implementation in 1.12. The old wiki entries should have more info.

 

A code snippet from my own TBC+ code:

List<int> containerSlot = Bag.GetItemContainerBagIdAndSlot(bagItem.Entry);
                if (!containerSlot.IsNullOrEmpty())
                {
                
                    Lua.LuaDoString($@"
                    {TooltipName}:Hide();
                    {TooltipName}:SetOwner(UIParent, 'ANCHOR_NONE');
                    {TooltipName}:ClearLines();
                    {TooltipName}:SetBagItem({containerSlot[0]}, {containerSlot[1]});
                ");
                    ParsedItem parsedBagItem = ItemParser.ParseCurrentTooltip(TooltipName);
                                    
...                                    

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...