Jump to content
This site uses cookies! Learn More

This site uses cookies!

By continuing to use this site, you agree to allow us to store cookies on your computer. :)

  • [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 =
            [email protected]"
            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);
        }

     


    Attached Files:


    User Feedback

    Recommended Comments

    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 =
            [email protected]"
            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);
        }

     

    Share this comment


    Link to comment
    Share on other sites

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

    Share this comment


    Link to comment
    Share on other sites

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

    public static int GetItemCount(string itemName)
        {
            string countLua =
                [email protected]"
            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);
        }

     

    Share this comment


    Link to comment
    Share on other sites


    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

×