I get this error when I'm trying to add my mobile.

Code:
00:15:55 System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. ---> System.NullReferenceException: Object refer
ence not set to an instance of an object.
   at Server.Items.BaseArmor.OnAdded(Object parent)
   at Server.Mobile.AddItem(Item item) in c:\Users\BackUp-POS\Desktop\ServUO-mas
ter\Server\Mobile.cs:line 6658
   at Server.Mobiles.DrowLord..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo method, O
bject[] args, SignatureStruct& signature, RuntimeType declaringType)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, B
inder binder, Object[] parameters, CultureInfo culture)
   at Server.Commands.Add.Build(Mobile from, ConstructorInfo ctor, Object[] valu
es, String[,] props, PropertyInfo[] realProps, Boolean& sendError)
   at Server.Commands.Add.Build(Mobile from, Point3D start, Point3D end, Constru
ctorInfo ctor, Object[] values, String[,] props, PropertyInfo[] realProps, List`
1 packs, Boolean outline, Boolean mapAvg)

The script in question is just a modified elf brigand script, but, here it is.

Code:
using System;
using Server.Items;

namespace Server.Mobiles 
{ 
       [CorpseName("an elf corpse")]
       public class DrowArcher : BaseCreature
       {
             [Constructable]
             public DrowArcher() : base(AIType.AI_Archer, FightMode.Closest, 10, 1, 0.2, 0.4)// TODO spellweaving AI
             {
                    this.Race = Race.Elf;

                    if (this.Female = Utility.RandomBool())
                    {
                          this.Body = 606;
                          this.Name = NameList.RandomName("Elf Female");
                    }
                    else
                    {
                          this.Body = 605;
                          this.Name = NameList.RandomName("Elf Male");
                    }

                    this.Title = "drow archer";
                    this.Hue = this.Race.RandomSkinHue();

                    this.SetStr(86, 100);
                    this.SetDex(81, 95);
                    this.SetInt(61, 75);

                    this.SetDamage(10, 23);

		    this.SetStr( 96, 115 );
		    this.SetDex( 86, 105 );
		    this.SetInt( 51, 65 );

		    this.SetDamage( 23, 27 );

		    this.SetDamageType( ResistanceType.Physical, 100 );

                    this.SetResistance(ResistanceType.Physical, 10, 15);
                    this.SetResistance(ResistanceType.Fire, 10, 15);
                    this.SetResistance(ResistanceType.Cold, 10, 15);
                    this.SetResistance(ResistanceType.Poison, 10, 15);
                    this.SetResistance(ResistanceType.Energy, 10, 15);

		    this.SetSkill( SkillName.Archery, 60.0, 82.5 );
		    this.SetSkill( SkillName.Poisoning, 60.0, 82.5 );
		    this.SetSkill( SkillName.MagicResist, 57.5, 80.0 );
		    this.SetSkill( SkillName.Swords, 60.0, 82.5 );
		    this.SetSkill( SkillName.Tactics, 60.0, 82.5 );

                    this.Fame = 5000;
                    this.Karma = -5000;

                    this.VirtualArmor = 28;

                    this.AddItem(new Shirt(Utility.RandomNeutralHue()));

                    switch ( Utility.Random( 2 ) )
		    {
		           case 0:
                           {
                                  this.AddItem(new LeafChest(Utility.RandomBlueHue()));
                                  this.AddItem(new LeafArms(Utility.RandomBlueHue()));
                                  this.AddItem(new LeafGorget(Utility.RandomBlueHue()));
                                  this.AddItem(new LeafGloves(Utility.RandomBlueHue()));
                                  switch ( Utility.Random( 2 ) )
			          {
                                         case 0:this.AddItem(new LeafLegs(Utility.RandomBlueHue())); break;
                                         case 1:this.AddItem(new LeafTonlet(Utility.RandomBlueHue())); break;
			          }
			   } break;
                           case 1:
                           {
                                  this.AddItem(new HideChest(Utility.RandomBlueHue()));
                                  this.AddItem(new HidePauldrons(Utility.RandomBlueHue()));
                                  this.AddItem(new HideGorget(Utility.RandomBlueHue()));
                                  this.AddItem(new HideGloves(Utility.RandomBlueHue()));
                                  this.AddItem(new HidePants(Utility.RandomBlueHue()));

			   } break;
                    }

                    switch (Utility.Random( 4 ))
                    {
                           case 1: this.AddItem(new RavenHelm(1175)); break;
                           case 2: this.AddItem(new VultureHelm(1175)); break;
                           case 3: this.AddItem(new WingedHelm(1175)); break;
                    }

                    switch (Utility.Random(4))
                    {
                           case 0:this.AddItem(new Sandals()); break;
                           case 1:this.AddItem(new ElvenBoots()); break;
                           case 2:this.AddItem(new Boots()); break;
                           case 3:this.AddItem(new ThighBoots()); break;
                    }

                    this.HairItemID = this.Race.RandomHair(this.Female);
                    this.HairHue = this.Race.RandomHairHue();

                    switch ( Utility.Random( 2 ) )
		    {
                           case 0:
                           {
                                  this.AddItem( new RepeatingCrossbow() );
                                  this.PackItem( new Bolt( Utility.Random( 50, 120 ) ) );
                           }break;
                           case 1:
                           {
                                  this.AddItem( new ElvenCompositeLongbow() );
                                  this.PackItem( new Arrow( Utility.Random( 50, 120 ) ) );
                           }break;
		    }
             }

	     public override void GenerateLoot()
	     {
		    this.AddLoot( LootPack.Average, 3 );
                    this.PackMagicItems( 1, 2 );
                    this.PackItem( new Bandage( Utility.RandomMinMax( 1, 15 ) ) );
             }

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

             public override OppositionGroup OppositionGroup
	     {
	            get{ return OppositionGroup.ElvesAndDrow; }
	     }

	     public override bool AlwaysMurderer{ get{ return true; } }
	     public override bool ShowFameTitle{ get{ return false; } }
	     public override bool CanRummageCorpses{ get{ return true; } }

             public override void OnDeath(Container c)
             {
                    base.OnDeath(c);

                    if (Utility.RandomDouble() < 0.75)
                        c.DropItem(new SeveredElfEars());
             }

             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();
             }
       }
}

The error calls out a line from Mobile.cs, here is that section and line. (Marked with arrow)

Code:
		public void AddItem(Item item)
		{
			if (item == null || item.Deleted)
			{
				return;
			}

			if (item.Parent == this)
			{
				return;
			}
			else if (item.Parent is Mobile)
			{
				((Mobile)item.Parent).RemoveItem(item);
			}
			else if (item.Parent is Item)
			{
				((Item)item.Parent).RemoveItem(item);
			}
			else
			{
				item.SendRemovePacket();
			}

			item.Parent = this;
			item.Map = m_Map;

			m_Items.Add(item);

			if (!item.IsVirtualItem)
			{
				UpdateTotal(item, TotalType.Gold, item.TotalGold);
				UpdateTotal(item, TotalType.Items, item.TotalItems + 1);
				UpdateTotal(item, TotalType.Weight, item.TotalWeight + item.PileWeight);
			}

			item.Delta(ItemDelta.Update);

-------->>	item.OnAdded(this);
			OnItemAdded(item);

			if (item.PhysicalResistance != 0 || item.FireResistance != 0 || item.ColdResistance != 0 ||
				item.PoisonResistance != 0 || item.EnergyResistance != 0)
			{
				UpdateResistances();
			}
		}
 
Hard to read with the spaces, but kinda looks like your switch statements are incorrect.. the ones creating the equipped items.
 
Yes, the spaces make it hard to read, thankfully, the actual script is nice and uniform!

I'm still trying to get used to the minor differences between ServUO & RunUO scripting.

I know that this is how I would, and have set it up in RunUO scripts.
 

switch (Utility.Random( 4 ))
{
case 1: this.AddItem(new RavenHelm(1175)); break;
case 2: this.AddItem(new VultureHelm(1175)); break;
case 3: this.AddItem(new WingedHelm(1175)); break;
}


I am looking at this switch and I have a few questions. You are looking for 4 cases but only have 3 listed without a default case. Shouldn't there be one or the other. Also on all of the items you are adding I see you are adding an overload (guessing a hue value) but looking at the core scripts for servuo I do not see an int overload.

I have not performed any scripting for Servuo as my server is running on runuo but I dont think the hue overload will work in general. Unless there is something in the BaseArmor script to allow this overload.
 
I am looking at this switch and I have a few questions. You are looking for 4 cases but only have 3 listed without a default case. Shouldn't there be one or the other. Also on all of the items you are adding I see you are adding an overload (guessing a hue value) but looking at the core scripts for servuo I do not see an int overload.

I have not performed any scripting for Servuo as my server is running on runuo but I dont think the hue overload will work in general. Unless there is something in the BaseArmor script to allow this overload.

The 4 cases instead of 3 was a typo, it was corrected after I posted this problem.

Also, I removed the hue value but it had no bearing on the issue as I still have the exact same error.

Thank you for the try though!

I'm still looking at the switch entries but aside from setting them up so they are easier for me to read, they aren't any different than what was in the elfbrigand.cs.
 
Okay, so, I went and commented out the large switch that I was adding all of the armor and it worked fine, so, my new question is...........

How would I go about adding two separate sets of armor to one mobile?
 
If just two sets to choose from randomly, do somthing like..

if(Utility.RandomBool())
{
switch
{
first set cases..
...
}
}

else
{
switch ..
second set of cases..
}
}
 
I think I have determined that it is not the switch that is causing the problem, it has something to do with the armor that I'm adding.

I edited out the switch that was adding the two sets of armor and just added one set of armor, when I tried to spawn I get the same error, when I edit out the armor the mob spawns. I still have the switch for the shoes and the helm and it is moving between the selections easily.
 
Okay, it is working now. All switches are performing as they should be.

For some reason it doesn't like the Utility.RandomBlueHues so I will have to look at other ways to hue the armor which isn't hard to do.

I'm glad to see that I don't have to relearn how to do switches. LOL :p

Thanks to both of you Dian and Keldon for the input.
 
Here is what the final hue and switch dilemma came out as.

Code:
		    int hue = Utility.RandomBlueHue() ;

                    switch ( Utility.Random( 2 ) )
                    {
                           case 0:
                           {
			          LeafChest tunic = new LeafChest();
			          tunic.Hue = hue;
			          AddItem( tunic );

			          LeafArms arms = new LeafArms();
			          arms.Hue = hue;
			          AddItem( arms );

			          LeafGorget gorget = new LeafGorget();
			          gorget.Hue = hue;
			          AddItem( gorget );

			          LeafGloves gloves = new LeafGloves();
			          gloves.Hue = hue;
			          AddItem( gloves );

                                  switch ( Utility.Random( 2 ) )
			          {
                                         case 0:
                                         {
			                        LeafLegs legs = new LeafLegs();
			                        legs.Hue = hue;
			                        AddItem( legs );
			                 }break;
                                         case 1:
                                         {
			                        LeafTonlet legs = new LeafTonlet();
			                        legs.Hue = hue;
			                        AddItem( legs );
			                 }break;
			          }
                           } break;
                           case 1:
                           {
			          HideChest tunic = new HideChest();
			          tunic.Hue = hue;
			          AddItem( tunic );

			          HidePauldrons arms = new HidePauldrons();
			          arms.Hue = hue;
			          AddItem( arms );

			          HideGorget gorget = new HideGorget();
			          gorget.Hue = hue;
			          AddItem( gorget );

			          HideGloves gloves = new HideGloves();
			          gloves.Hue = hue;
			          AddItem( gloves );

			          HidePants legs = new HidePants();
			          legs.Hue = hue;
			          AddItem( legs );
                           } break;
                    }

Bit wordy but it is working so I'm not going to worry about it right now.
 
Code:
RavenHelm helm = new RavenHelm();
helm.Hue = Utility.RandomBlueHue();
this.AddItem(helm);

written in web browser while at work but that should do what you are looking to do.
 
Back