Jump to content

Recommended Posts

    public static void DeleteItems(string itemName, int leaveAmount = 0)
    {
        var itemQuantity = ItemsManager.GetItemCountByNameLUA(itemName) - leaveAmount;

        if (string.IsNullOrWhiteSpace(itemName) || itemQuantity <= 0)
        {
            return;
        }

        string luaToDelete = $@"
            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 itemString = string.match(itemLink, ""item[%-?%d:]+"");
                            local _, stackCount = GetContainerItemInfo(b, s);
                            local leftItems = itemCount - deleted; 
                            if ((GetItemInfo(itemString) == ""{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(luaToDelete);
    }

Directly out of  Matenias  Framework, and with DeleteItems("Soulshard", 5) usable.

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