ServUO Version
Publish 57
Ultima Expansion
Endless Journey
Is there an easy way to have items dropping in the players pack to stack on other items of the same type?

I'm currently fixing some bugs in a script and I have it working but the dropped items aren't stacking which is rather annoying..
 
I didn't know that was a thing! Testing it out now!

Hmm nope, seems like it doesn't like it.. here's what I'm using:
C#:
                    Container pack = from.Backpack;
                    pack.DropItemStacked(new Bottle(count));
C#:
error CS1061: 'Container' does not contain a definition for 'DropItemStacked' and no accessible extension method 'DropItemStacked' accepting a first argument of type 'Container' could be found (are you missing a using directive or an assembly reference?)

I think it might be because I'm calling that in the OnDragDrop, but not sure..
 
Last edited:
I didn't know that was a thing! Testing it out now!

Hmm nope, seems like it doesn't like it.. here's what I'm using:
C#:
                    Container pack = from.Backpack;
                    pack.DropItemStacked(new Bottle(count));
C#:
error CS1061: 'Container' does not contain a definition for 'DropItemStacked' and no accessible extension method 'DropItemStacked' accepting a first argument of type 'Container' could be found (are you missing a using directive or an assembly reference?)

I think it might be because I'm calling that in the OnDragDrop, but not sure..

If you want to use the Vita-Nex extension method, it is DropItemStack, otherwise @Bittiez solution should work, so long as the item is actually set as stackable.

This extension method requires `using Server;`
 
Vita Nex has an extension too.. omg lol.. I'll test yours here in a sec, the only way I could get it to work right now was by writing a new drop method to Container.cs, the item I am dropping things onto isn't actually a container it's an item then it returns the items it "consumes" to the players inventory if that makes sense.

C#:
        public static void DropItemStackedIntoPack(Item item, Mobile from)
        {
            Container pack = from.Backpack;
            List<Item> list = pack.Items;

            ItemFlags.SetTaken(item, true);

            for (int i = 0; i < list.Count; ++i)
            {
                Item packItem = list[i];

                if (packItem.StackWith(null, item, false))
                {
                    item.Delete();
                    return;
                }
            }

            pack.DropItem(item);
        }

Voxpire, your code worked without any other code modifications. I'll likely go that route! Thank you!
 
Last edited:
I didn't know that was a thing! Testing it out now!

Hmm nope, seems like it doesn't like it.. here's what I'm using:
C#:
                    Container pack = from.Backpack;
                    pack.DropItemStacked(new Bottle(count));
C#:
error CS1061: 'Container' does not contain a definition for 'DropItemStacked' and no accessible extension method 'DropItemStacked' accepting a first argument of type 'Container' could be found (are you missing a using directive or an assembly reference?)

I think it might be because I'm calling that in the OnDragDrop, but not sure..
DropItemStacked defined in BaseContainer, not in its parent "Container". The code should looks like:
C#:
                    BaseContainer pack = from.Backpack;

                    pack.DropItemStacked(new Bottle(count));
                    // or just:
                    // from.Backpack?.DropItemStacked(new Bottle(count));
 
Back