I'm designing a modified set system for my shard, it's an item that you double click and then it equips armor that cannot be removed by the toon by dragging. Double clicking the activator again deletes the armor. Kind of like an armor set that is 'stored' in the activator. Well it works great! except for if the toon has existing armor already equipped, it is supposed to move that armor to the toons backpack, then equip the armor from the set. Instead of doing that it crashes.... Here is the crash Log and the script.

Code:
ServUO Version 0.5, Build 6464.36965
Operating System: Microsoft Windows NT 6.2.9200.0
.NET Framework: 4.0.30319.42000
Time: 9/13/2017 10:31:59 PM
Mobiles: 3347
Items: 114159
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Mobile.AddToBackpack(Item item) in k:\AlfheimRebornServer\Ultima Server2\Server\Mobile.cs:line 10581
   at Server.Items.GreymistActivator.OnDoubleClick(Mobile m)
   at Server.Mobile.Use(Item item) in k:\AlfheimRebornServer\Ultima Server2\Server\Mobile.cs:line 4417
   at Server.Engines.XmlSpawner2.XmlAttach.UseReq(NetState state, PacketReader pvSrc)
   at Server.Network.MessagePump.HandleReceive(NetState ns) in k:\AlfheimRebornServer\Ultima Server2\Server\Network\MessagePump.cs:line 187
   at Server.Network.MessagePump.Slice() in k:\AlfheimRebornServer\Ultima Server2\Server\Network\MessagePump.cs:line 121
   at Server.Core.Main(String[] args) in k:\AlfheimRebornServer\Ultima Server2\Server\Main.cs:line 588

Code:
/*
Current Note.   The armor works, double clicking equips the armor then removes it and deletes it!
Problem, if armor exist, when double clicking the activator the server crashes.



*/
using System;
using System.Collections;
using Server;
using Server.Prompts;
using Server.Mobiles;
using Server.Network;
using Server.Gumps;
using Server.Items;

namespace Server.Items
{
    public class GreymistActivator : Item
    {
        [Constructable]
        public GreymistActivator() : base( 0x2252 )
        {
            Movable = true;
            Weight = 1.0;
            Name = "Greymist Armor Activator";
        }
       
        public override void OnDoubleClick( Mobile m )
        {
            if (m.Race == Race.Human)
            {   
                Item EquipArmor1 = m.FindItemOnLayer(Layer.Pants);
                Item EquipArmor2 = m.FindItemOnLayer(Layer.Gloves);
                Item EquipArmor3 = m.FindItemOnLayer(Layer.InnerTorso);
                Item EquipArmor4 = m.FindItemOnLayer(Layer.Arms);
               
                if (EquipArmor1 != null || EquipArmor2 != null || EquipArmor3 != null || EquipArmor4 != null)
                {
                    if (EquipArmor1 is GreymistLegsAA || EquipArmor2 is GreymistGlovesAA || EquipArmor3 is GreymistChestAA ||
                        EquipArmor4 is GreymistArmsAA)
                    {
                        m.LocalOverheadMessage(MessageType.Emote, 0x59, true, "You remove the armor! ");
                        EquipArmor1.Delete();
                        EquipArmor2.Delete();
                        EquipArmor3.Delete();
                        EquipArmor4.Delete();
                        return;
                    }
                    else
                    {                   
                        m.LocalOverheadMessage(MessageType.Emote, 0x59, true, "You remove existing armor! ");
                        m.AddToBackpack(EquipArmor1);
                        m.AddToBackpack(EquipArmor2);
                        m.AddToBackpack(EquipArmor3);
                        m.AddToBackpack(EquipArmor4);

                    }
                }
               
                else
                {
                    m.EquipItem(new GreymistChestAA());
                    m.EquipItem(new GreymistGlovesAA());
                    m.EquipItem(new GreymistLegsAA());
                    m.EquipItem(new GreymistArmsAA());
                }
            }
            else
                m.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Only Humans Can Equip Me!");
        }
   
   
        public GreymistActivator( Serial serial ) : base( serial )
        {
        }

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

            writer.Write( (int) 0 ); // version
        }

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

            int version = reader.ReadInt();
        }
    }
}
 
Re did the code a little, cleaner and seems to make more sense, but the exact same error. So i didn't come to any good solution with this next attempt..

Code:
/*
Current Note.   The armor works, double clicking equips the armor then removes it and deletes it!
Problem, if armor exist, when double clicking the activator the server crashes.



*/
using System;
using System.Collections;
using Server;
using Server.Prompts;
using Server.Mobiles;
using Server.Network;
using Server.Gumps;
using Server.Items;

namespace Server.Items
{
    public class GreymistActivator : Item
    {
        [Constructable]
        public GreymistActivator() : base( 0x2252 )
        {
            Movable = true;
            Weight = 1.0;
            Name = "Greymist Armor Activator";
        }
       
        public override void OnDoubleClick( Mobile m )
        {
            if (m.Race == Race.Human)
            {   
                Item EquipArmor1 = m.FindItemOnLayer(Layer.Pants);
                Item EquipArmor2 = m.FindItemOnLayer(Layer.Gloves);
                Item EquipArmor3 = m.FindItemOnLayer(Layer.InnerTorso);
                Item EquipArmor4 = m.FindItemOnLayer(Layer.Arms);
               

                if (EquipArmor1 is GreymistLegsAA || EquipArmor2 is GreymistGlovesAA || EquipArmor3 is GreymistChestAA ||
                    EquipArmor4 is GreymistArmsAA)
                {
                    m.LocalOverheadMessage(MessageType.Emote, 0x59, true, "You remove the armor! ");
                    EquipArmor1.Delete();
                    EquipArmor2.Delete();
                    EquipArmor3.Delete();
                    EquipArmor4.Delete();
                    return;
                }
               
                if (EquipArmor1 != null || EquipArmor2 != null ||  EquipArmor3 != null || EquipArmor4 != null)
                {                   
                    m.LocalOverheadMessage(MessageType.Emote, 0x59, true, "You remove existing armor! ");
                    m.AddToBackpack(EquipArmor1);
                    m.AddToBackpack(EquipArmor2);
                    m.AddToBackpack(EquipArmor3);
                    m.AddToBackpack(EquipArmor4);

                }
                else
                {
                    m.EquipItem(new GreymistChestAA());
                    m.EquipItem(new GreymistGlovesAA());
                    m.EquipItem(new GreymistLegsAA());
                    m.EquipItem(new GreymistArmsAA());
                }
            }
            else
                m.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Only Humans Can Equip Me!");
        }
   
   
        public GreymistActivator( Serial serial ) : base( serial )
        {
        }

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

            writer.Write( (int) 0 ); // version
        }

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

            int version = reader.ReadInt();
        }
    }
}
[doublepost=1505343816][/doublepost]So talking to myself helps.. Go Figure. Here is the finished script with no errors. Once I finish this more, I will release it as a resource.

Code:
using System;
using System.Collections;
using Server;
using Server.Prompts;
using Server.Mobiles;
using Server.Network;
using Server.Gumps;
using Server.Items;

namespace Server.Items
{
    public class GreymistActivator : Item
    {
        [Constructable]
        public GreymistActivator() : base( 0x2252 )
        {
            Movable = true;
            Weight = 1.0;
            Name = "Greymist Armor Activator";
        }
       
        public override void OnDoubleClick( Mobile m )
        {
            if (m.Race == Race.Human)
            {   
                Item EquipArmor1 = m.FindItemOnLayer(Layer.Pants);
                Item EquipArmor2 = m.FindItemOnLayer(Layer.Gloves);
                Item EquipArmor3 = m.FindItemOnLayer(Layer.InnerTorso);
                Item EquipArmor4 = m.FindItemOnLayer(Layer.Arms);
               

                if (EquipArmor1 is GreymistLegsAA || EquipArmor2 is GreymistGlovesAA || EquipArmor3 is GreymistChestAA ||
                    EquipArmor4 is GreymistArmsAA)
                {
                    m.LocalOverheadMessage(MessageType.Emote, 0x59, true, "You remove the armor! ");
                    EquipArmor1.Delete();
                    EquipArmor2.Delete();
                    EquipArmor3.Delete();
                    EquipArmor4.Delete();
                    return;
                }
               
                if (EquipArmor1 != null)               
                    m.AddToBackpack(EquipArmor1);
               
                if (EquipArmor2 != null)
                    m.AddToBackpack(EquipArmor2);
               
                if (EquipArmor3 != null)
                    m.AddToBackpack(EquipArmor3);
               
                if (EquipArmor4 != null)
                    m.AddToBackpack(EquipArmor4);

                m.EquipItem(new GreymistChestAA());
                m.EquipItem(new GreymistGlovesAA());
                m.EquipItem(new GreymistLegsAA());
                m.EquipItem(new GreymistArmsAA());

            }
            else
                m.LocalOverheadMessage(MessageType.Emote, 0x59, true, "Only Humans Can Equip Me!");
        }
   
   
        public GreymistActivator( Serial serial ) : base( serial )
        {
        }

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

            writer.Write( (int) 0 ); // version
        }

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

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