Lemke

Member
Hello!Just having a problem,the script is an item,when double click it and you have got the required items in your backpack,this first item self-delete and turn into new item.
With normal items required 8not quantity) script runs without problems,when i try to find quantity server crash when i double click it,here the method:


C#:
public override void OnDoubleClick( Mobile m )

                    {
                    Item a = m.Backpack.FindItemByType( typeof(IronIngot) );/////50<-----
                    if ( a.Amount >= 50 )
                    {   
                    Item b = m.Backpack.FindItemByType( typeof(Log) );//////50<------
                    if ( b.Amount >= 50 )
                    {   
                    Item c = m.Backpack.FindItemByType( typeof(Dagger) );
                    if ( c != null )
                    {           
                    Item d = m.Backpack.FindItemByType( typeof(Pickaxe) );
                    if ( d != null )
                    {           
                    Item e = m.Backpack.FindItemByType( typeof(DoubleAxe) );
                    if ( e != null )
                    {                           
                        m.AddToBackpack( new NewItem() );
                        a.Delete();
                        b.Delete();
                        c.Delete();
                        d.Delete();
                        e.Delete();

                        m.SendMessage( "You get the new test item!" );
                        this.Delete();

                    }
I know the code is wrong,whats the correct path to do that? Thank you so much!!!
 
I am not really good at coding but if you set an amount for a and b possibly you need to say Delete(50); for those two lines and on line 19 if you do not have a scripted item called "NewItem" it will cause a problem. If someone doesnt come on soon that can help you more try attaching a copy of the crash log to make it easier for them to help.
 
Here is the full script:


C#:
using System;
using Server;
using Server.Gumps;
using Server.Network;
using System.Collections;
using Server.Multis;
using Server.Mobiles;


namespace Server.Items
{

    public class ToolBoxWeapEmpty : Item
    {
        [Constructable]
        public ToolBoxWeapEmpty() : this(null)
        {
        }

        [Constructable]
        public ToolBoxWeapEmpty(string name) : base(0x1EB8)
        {
            Name = "Magic ToolBox Empty";
            Hue = 953;

        }

        public ToolBoxWeapEmpty(Serial serial) : base(serial)
        {
        }


        
                public override void OnDoubleClick( Mobile m )

                    {
                    Item a = m.Backpack.FindItemByType( typeof(IronIngot) );
                    if ( a.Amount >= 50 )
                    {   
                    Item b = m.Backpack.FindItemByType( typeof(Log) );
                    if ( b.Amount >= 50 )
                    {   
                    Item c = m.Backpack.FindItemByType( typeof(ZombieBlood) );
                    if ( c.Amount >= 25 )
                    {           
                    Item d = m.Backpack.FindItemByType( typeof(AncientHammerItem) );
                    if ( d != null )
                    {           
                    Item e = m.Backpack.FindItemByType( typeof(PrimitiveAxeItem) );
                    if ( e != null )
                    {                           
                        m.AddToBackpack( new ToolBoxWeapFullyItem() );
                        a.Delete();
                        b.Delete();
                        c.Delete();
                        d.Delete();
                        e.Delete();

                        m.SendMessage( "You fill the bag!" );
                        this.Delete();

                    }
                        else
                    {
                        m.SendMessage( "Are You Forgetting Something?" );
                }
                }
                }
                }
                }
            }


        
        public override void Serialize ( GenericWriter writer)
        {
            base.Serialize ( writer );

            writer.Write ( (int) 0);
        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize ( reader );

            int version = reader.ReadInt();
        }
    }
}

And here the crash log:


C#:
ServUO Version 0.5, Build 6996.26785
Operating System: Microsoft Windows NT 6.2.9200.0
.NET Framework: 4.0.30319.42000
Time: 30/04/2019 8:17:11
Mobiles: 43860
Items: 224739
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Items.ToolBoxWeapEmpty.OnDoubleClick(Mobile m)
   at Server.Mobile.Use(Item item)
   at Server.Engines.XmlSpawner2.XmlAttach.UseReq(NetState state, PacketReader pvSrc)
   at Server.Network.MessagePump.HandleReceive(NetState ns)
   at Server.Network.MessagePump.Slice()
   at Server.Core.Main(String[] args)

Clients:
- Count: 1
 
You never checked if there are even any IronIngots or Logs, so a null check was missing.
Also you deleted the items. Meaning if you had 60000 Ingots on you all would be removed, so use Consume there ;)
Then you can just let it eat 50 of each.

Also just to be aware, this will eat any dagger, any pickaxe and any double axe. Meaning it can be like an artifact too for example.

C#:
public override void OnDoubleClick( Mobile m )
{
    Item a = m.Backpack.FindItemByType( typeof(IronIngot) );/////50<-----
    if ( a != null && a.Amount >= 50 )
    {
        Item b = m.Backpack.FindItemByType( typeof(Log) );//////50<------
        if ( b != null && b.Amount >= 50 )
        {
            Item c = m.Backpack.FindItemByType( typeof(Dagger) );
            if ( c != null )
            {
                Item d = m.Backpack.FindItemByType( typeof(Pickaxe) );
                if ( d != null )
                {
                    Item e = m.Backpack.FindItemByType( typeof(DoubleAxe) );
                    if ( e != null )
                    {
                        m.AddToBackpack( new NewItem() );
                        a.Consume(50);
                        b.Consume(50);
                        c.Delete();
                        d.Delete();
                        e.Delete();

                        m.SendMessage( "You get the new test item!" );
                        Delete();
                    }
                }
            }
        }
    }
}
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back