Tukaram

Member
I have several quests (not mine) that use an item to combine other items to create a new item, it also deletes the component items. An old fisherman quest looks for 10 worms, 1 empty jar, and 1 fertile dirt. It creates a full jar, and deletes all 12 component items. I used that script as my guide.

I am trying to make an empty jar become a full jar, but I want to use these 3 items: 1 empty jar, 5 FireflyTails, and 5 GlowingOoze. The copied code does compile and the item is made. It checks for 5 of both items, plus one jar. If you are missing anything, you get the warning message. If you have 5 of the items it creates the new item - BUT - the delete does not work right. It deletes 1 item c, 5 of item a, and only deletes 1 of item b. So it leaves you with 4 of item b, instead of deleting them. The integer bit seems to be off. I tried a few things but nothing else seems to even compile, because I obviously do not know what I am doing ha ha.

I guess I could just use 1 jar, 1 ooze, and 5 tails... but I want to figure out what I am doing wrong. There must be a way to have it delete all the items.

Semi-working code:
    public override void OnDoubleClick( Mobile m )

        {
            Item[] a = m.Backpack.FindItemsByType(typeof(FireflyTails));
            // are there at least 5 elements in the returned array?
            if ( a!= null && a.Length >= 5)
            {

                Item b = m.Backpack.FindItemByType(typeof(GlowingOoze));
                if (b != null && a.Length >= 5)
            {
                Item c = m.Backpack.FindItemByType(typeof(GlowingGlassBottleEmpty));
            if ( c != null )
            {
                // delete the first 5 of them
            for(int i=0;i<5;i++)
                 a[i].Delete();
                b.Delete();
                c.Delete();
            
                // and add the full bottle
                m.AddToBackpack(new GlowingGlassBottleFull());
                m.SendMessage("The jar is full, hurry back to xxx for your reward!");
            }
            }                       
            }
            else
            {
                m.SendMessage( "Something went wrong. Are you sure you have everything?" );
            }
        }




The next 2 snippets are attempts to correct it, but I get errors. On the first I simply tried to add the to item b. Then I tried to add a new "for(int i=0;i<5;i++)" to both item a & b. Both give errors (as shown below).

________________________________________________________________________________________________

// delete the first 5 of them

for(int i=0;i<5;i++)

a.Delete();

b.Delete();

c.Delete();
****
Errors:

+ Customs/_Testing/Dragon Lantern Quest/Items/GlowingGlassBottleEmpty.cs:

CS0103: Line 50: The name 'i' does not exist in the current context


_________________________________________________________________________________________________

// delete the first 5 of them

for(int i=0;i<5;i++)

a.Delete();

for (int i = 0; i < 5; i++)

b.Delete();

c.Delete();
****
Errors:

+ Customs/_Testing/Dragon Lantern Quest/Items/GlowingGlassBottleEmpty.cs:

CS0021: Line 51: Cannot apply indexing with [] to an expression of type 'Ite

m'
 
I would suggest to always use Consume() over Delete() for Items.

Also, you only looped over the a array. You need to do the same for b.

C#:
    public override void OnDoubleClick(Mobile m)
    {
        Item[] a = m.Backpack.FindItemsByType(typeof(FireflyTails));
        // are there at least 5 elements in the returned array?
        if (a != null && a.Length >= 5)
        {
            Item b = m.Backpack.FindItemByType(typeof(GlowingOoze));
            if (b != null && a.Length >= 5)
            {
                Item c = m.Backpack.FindItemByType(typeof(GlowingGlassBottleEmpty));
                if (c != null)
                {
                    // delete the first 5 of them
                    for (int i = 0; i < 5; i++)
                    {
                        a[i].Consume();
                        b[i].Consume();
                    }
                    c.Consume();

                    // and add the full bottle
                    m.AddToBackpack(new GlowingGlassBottleFull());
                    m.SendMessage("The jar is full, hurry back to xxx for your reward!");
                }
            }
        }
        else
        {
            m.SendMessage("Something went wrong. Are you sure you have everything?");
        }
    }

Also it should be way simpler if you use ConsumeTotal

C#:
    private static readonly Type[] NeededItems = new Type[] { typeof(FireflyTails), typeof(GlowingOoze), typeof(GlowingGlassBottleEmpty) };
    private static readonly int[] NeededAmounts = new int[] { 5, 5, 1 };           

    public override void OnDoubleClick(Mobile m)
    {
        // are there at least 5 elements in the returned array?
        if (m.Backpack != null && m.Backpack.ConsumeTotal(NeededItems, NeededAmounts) == -1) // -1 us success, other positive numbers say wich item is not enough
        {
            // add the full bottle
            m.AddToBackpack(new GlowingGlassBottleFull());
            m.SendMessage("The jar is full, hurry back to xxx for your reward!");
        }
        else
        {
            m.SendMessage("Something went wrong. Are you sure you have everything?");
        }
    }
 
Wow, quick answer. Thanks, that works great. Sure looks a lot cleaner too. I have not seen the consume. I will start using that instead of delete. I really just edit existing scripts... I do not know much ha ha. :cool:
Post automatically merged:

Just as an aside...
The reward item is the Dragon Lantern Addon. It is included in the ServUO repo. But... should I include a copy of the script when I post the quests? I would think everyone has that addon, but some people may be using a different repo/system. If they are on RunUO, is it included? I can include it but add a note that they need to delete it if they already have one. (I am sure I am overthinking this ha ha)
 
Last edited:

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back