Jump to content
  • [All] ItemsManager.GetItemCountByNameLua is incorrect


    Matenia
    • Version: All Product: WRobot General Type: Bug Status: Confirmed

    Currently this function first uses GetItemInfo("name") to get the itemId then searches in bags for the ID.
    There are several items with different IDs but the same name (for example, Healthstone).

    This function works:

    public static int GetItemCount(string itemName)
        {
            string countLua =
            $@"
            local fullCount = 0;
            for bag=0,4 do
                for slot=1,36 do
                    local name = GetContainerItemLink(bag, slot);
                    if (name and name == ""{itemName}"") then
                        local texture, count = GetContaimerItemInfo(bag, slot);
                        fullCount = fullCount + count;
                    end;
                end;
            end
            return fullCount;";
            return Lua.LuaDoString<int>(countLua);
        }

     



    User Feedback

    Recommended Comments

    Matenia

    Posted

    Can't edit original report, but function is also a bit wrong - this works in vanilla/tbc/wrath:
     

    public static int GetItemCount(string itemName)
        {
            string countLua =
            $@"
            local fullCount = 0;
            for bag=0,4 do
                for slot=1,36 do
                    local itemLink = GetContainerItemLink(bag, slot);
                    if (itemLink) then
                        local itemString = string.match(itemLink, ""item[%-?%d:]+"");
                        if(GetItemInfo(itemString) == ""{itemName}"") then
                            local texture, count = GetContaimerItemInfo(bag, slot);
                            fullCount = fullCount + count;
                        end
                    end;
                end;
            end
            return fullCount;";
            return Lua.LuaDoString<int>(countLua);
        }

     

    Droidz

    Posted

    Hello, you get problem with "GetItemCountByNameLUA"? You get problem only on Lua or with tbc and wotlk also?

    Matenia

    Posted

    I get it with GetItemCountByNameLUA and on vanilla + tbc. But I noticed on TBC.

    Matenia

    Posted

    I forgot string.match is not in vanilla, this works across vanilla-wotlk:

    public static int GetItemCount(string itemName)
        {
            string countLua =
                $@"
            local fullCount = 0;
            for bag=0,4 do
                for slot=1,36 do
                    local itemLink = GetContainerItemLink(bag, slot);
                    if (itemLink) then
                        local _,_, itemId = string.find(itemLink, 'item:(%d+):');
                        if (GetItemInfo(itemId) == ""{itemName}"") then
                            local texture, count = GetContainerItemInfo(bag, slot);
                            fullCount = fullCount + count;
                        end
                    end
                end
            end
            return fullCount;";
            return Lua.LuaDoString<int>(countLua);
        }

     



    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...