Jump to content

Bag.GetBagItem()


Recommended Posts

35 minutes ago, Droidz said:

Hello, do you use wow addons? if yes try to disable all

No one addon. In DevelopmentTools if click :"bag items list" - also empty for itemtype "Container"

21,10,17(13-36-23).jpg

21,10,17(13-36-31).jpg

Link to comment
Share on other sites

To add another question onto this, Bag.GetBagItem() only shows 1 instance of the item, even if there are more of them in different bags, anyway to get the containerid/slot for each?

Link to comment
Share on other sites

@Marsbar Hello, i've written a method for this:

    public struct BagInfo
    {
        public int Bag;

        public int Slot;

        public BagInfo(int bag, int slot)
        {
            Bag = bag;
            Slot = slot;
        }

        public override string ToString()
        {
            return "Bag = " + Bag + " ; Slot = " + Slot;
        }
    }

    /// <summary>
    /// Used to get a list of locations of the item as bag and slot position.
    /// </summary>
    /// <param name="itemName">The item name to search.</param>
    /// <returns></returns>
    public static List<BagInfo> GetItemLocations(string itemName)
    {
        var execute =
            "local bs = {}" +
            "for b=0,4 do " +
            "if GetBagName(b) then " +
            "for s=1, GetContainerNumSlots(b) do " +
            "local itemLink = GetContainerItemLink(b, s) " +
            "if itemLink then " +
            "local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(itemLink) \t" +
            "if itemName == '"+itemName+"' ";
        execute +=
                  "then " +
                  "table.insert(bs, b); " +
                  "table.insert(bs, s); " +
                  "\tend\tend\tend end end return unpack(bs);";
        var bs = Lua.LuaDoString<List<int>>(execute);
        var list = new List<BagInfo>();
        for (var i = 0; i < bs.Count; i += 2)
            list.Add(new BagInfo(bs[i], bs[i+1]));
        return list;
    }

Usage:

        GetItemLocations("Mutton Chop").ForEach(i => Logging.Write(i.ToString()));

 

Here are also other similar methods to interact with items:

 

Link to comment
Share on other sites

2 hours ago, Marsbar said:

@reapler Sadly not working for me. Getting a Index was out of range error. I'm doing this for soul shard management, wanting to delete all soul shards exepct for a certain amount.

Not fully tested, but this should work:

    /// <summary>
    /// Used to get the item quantity by name.
    /// </summary>
    /// <param name="itemName">The item name.</param>
    /// <remarks>Replacement for GetItemCount in vanilla.</remarks>
    /// <returns></returns>
    public static int GetItemQuantity(string itemName)
    {
        var execute =
            "local itemCount = 0; " +
            "for b=0,4 do " +
                "if GetBagName(b) then " +
                    "for s=1, GetContainerNumSlots(b) do " +
                        "local itemLink = GetContainerItemLink(b, s) " +
                        "if itemLink then " +
                            "local _, stackCount = GetContainerItemInfo(b, s)\t " +
                            "if string.find(itemLink, \"" + itemName + "\") then " +
                                "itemCount = itemCount + stackCount; " +
                            "end " +
                        "end " +
                    "end " +
                "end " +
            "end; " +
            "return itemCount; ";
        return Lua.LuaDoString<int>(execute);
    }

    /// <summary>
    /// Used to delete all items by name.
    /// </summary>
    /// <param name="itemName">The item to delete.</param>
    /// <param name="leaveAmount">The amount of items which remain in the bag.</param>
    /// <remarks>Bug at links with "-"</remarks>
    public static void DeleteItems(string itemName, int leaveAmount)
    {
        var itemQuantity = GetItemQuantity(itemName) - leaveAmount;
        if (string.IsNullOrWhiteSpace(itemName) || itemQuantity <= 0)
            return;
        var execute = 
            "local itemCount = "+itemQuantity+"; " +
            "local deleted = 0; " +
            "for b=0,4 do " +
                "if GetBagName(b) then " +
                    "for s=1, GetContainerNumSlots(b) do " +
                        "local itemLink = GetContainerItemLink(b, s) " +
                        "if itemLink then " +
                            "local _, stackCount = GetContainerItemInfo(b, s)\t " +
                            "local leftItems = itemCount - deleted; " +
                            "if string.find(itemLink, \""+ itemName + "\") and leftItems > 0 then " +
                                "if stackCount <= 1 then " +
                                    "PickupContainerItem(b, s); " +
                                    "DeleteCursorItem(); " +
                                    "deleted = deleted + 1; " +
                                "else " +
                                    "if (leftItems > stackCount) then " +
                                        "SplitContainerItem(b, s, stackCount); " +
                                        "DeleteCursorItem(); " +
                                        "deleted = deleted + stackCount; " +
                                    "else " +
                                        "SplitContainerItem(b, s, leftItems); " +
                                        "DeleteCursorItem(); " +
                                        "deleted = deleted + leftItems; " +
                                    "end " +
                                "end " +
                            "end " +
                        "end " +
                    "end " +
                "end " +
            "end; ";
        Lua.LuaDoString(execute);
    }

Usage:

        DeleteItems("Soul Shard", 20);

 

Link to comment
Share on other sites

51 minutes ago, kpeno said:

Maybe anyone have idea how convert item entry to wowitem ?:)

Hello, you need to access the objectmanager to get your desired object:

        WoWItem item = ObjectManager.GetObjectWoWItem().FirstOrDefault(i => i.Entry == 1205);//Melon Juice
        Logging.Write(item?.Name ?? "Item not found");

 

Link to comment
Share on other sites

  • 1 year later...

hi all. i have no idea about the codes posted here. I was trying to search how to get my warlock create a spellstone then use it. i tried to base the "create healthstone" but I don't know how to get the itemID for the spellstone. if anyone can help me out that would be really great!

Link to comment
Share on other sites

3 hours ago, jiraiyasm said:

hi all. i have no idea about the codes posted here. I was trying to search how to get my warlock create a spellstone then use it. i tried to base the "create healthstone" but I don't know how to get the itemID for the spellstone. if anyone can help me out that would be really great!

You can use wowhead:
image.png.555caa81fbeabd1dfb812710cbf6acf1.png

Or you can start wrobot and use Tool/Development Tool:
image.png.e4ace6dc9b869dafa74ef03c5bb8007f.png

And then "Bag Items" or "Get all Objects" (if you have the spellstone already) or "Info by name".

P.S. Don't use 41191 from my screenshot. It's most likely not a spellstone you are looking for.

Link to comment
Share on other sites

12 hours ago, Findeh said:

You can use wowhead:
image.png.555caa81fbeabd1dfb812710cbf6acf1.png

Or you can start wrobot and use Tool/Development Tool:
image.png.e4ace6dc9b869dafa74ef03c5bb8007f.png

And then "Bag Items" or "Get all Objects" (if you have the spellstone already) or "Info by name".

P.S. Don't use 41191 from my screenshot. It's most likely not a spellstone you are looking for.

how can I set my warlock to use the master spellstone? Thank you.

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...