Suddenly my corpse.cs crash on save, it has to do with m_Looters

Error on save:




17/12-22:44 World: Saving...Error:
17/12-22:44 System.NullReferenceException: Object reference not set to an instan
ce of an object.
at Server.BinaryFileWriter.Write(List`1 list, Boolean tidy)
at Server.Items.Corpse.Serialize(GenericWriter writer) in c:\Users\lol\Deskto
p\Tproject\Scripts\Items\Misc\Corpses\Corpse.cs:line 751
at Server.StandardSaveStrategy.SaveItems(SaveMetrics metrics)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C
ontextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
17/12-22:44 Crash: Generating report...done
17/12-22:44 Crash: Sending email...failed




Line 751
Code:
writer.Write( m_Looters );

Whenever i lift an item from a corpse:

Error:


Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Items.Corpse.OnItemLifted(Mobile from, Item item) in c:\Users\lol\Desktop\Tproject\Scripts\Items\Misc\Corpses\Corpse.cs:line 1012
at Server.Item.OnItemLifted(Mobile from, Item item)
at Server.Mobiles.PlayerMobile.Lift(Item item, Int32 amount, Boolean& rejected, LRReason& reject) in c:\Users\lol\Desktop\Tibia project\Scripts\Mobiles\PlayerMobile.cs:line 9025
at Server.Network.PacketHandlers.LiftReq(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)


Line 1020
Code:
  if ( !m_Looters.Contains( from ) )

So i messed up my corpse.cs it seems like the m_Looters its throwing the error i dont remember if i commented out that method somewhere... oh well i hope someone helps me!
 
Last edited:
Hi Sahisahi,

I think I have spotted what could go wrong in your version of Corpse.cs.

In the 'Public Corpse', you have this :
Code:
  public Corpse( Mobile owner, HairInfo hair, FacialHairInfo facialhair, List<Item> equipItems )
       : base(  0x2006 )
     {

  if (owner is PlayerMobile)
  {
this.ItemID =  0x1FD9;
this.GumpID = 1313;
  }
else
{
this.ItemID =  0x2006;
this.Visible = true;
  m_ViewedBy = new List<Mobile>();
       // To supress console warnings, stackable must be true
       Stackable = true;
       Amount = owner.Body; // protocol defines that for itemid 0x2006, amount=body
       Stackable = false;
    //  this.ItemID =  0x1FD9;
       //this.Z +=2;
       this.GumpID = 9;
       Weight = 155;
       //Hue = owner.Hue;
       //Direction = owner.Direction;
       Name = owner.Name;
      // LiftOverride = false;


       m_Owner = owner;

       m_CorpseName = GetCorpseName( owner );

       m_TimeOfDeath = DateTime.Now;

       m_AccessLevel = owner.AccessLevel;
       m_Guild = owner.Guild as Guild;
       m_Kills = owner.Kills;
  SetFlag(CorpseFlag.Criminal, owner.Criminal);

       m_Hair = hair;
       m_FacialHair = facialhair;

  // This corpse does not turn to bones if: the owner is not a player
  SetFlag(CorpseFlag.NoBones, !owner.Player);

       m_Looters = new List<Mobile>();
       m_EquipItems = equipItems;

       m_Aggressors = new List<Mobile>( owner.Aggressors.Count + owner.Aggressed.Count );
       //bool addToAggressors = !( owner is BaseCreature );

  bool isBaseCreature = (owner is BaseCreature);

       TimeSpan lastTime = TimeSpan.MaxValue;

       for ( int i = 0; i < owner.Aggressors.Count; ++i )
       {
         AggressorInfo info = owner.Aggressors[i];

         if ( (DateTime.Now - info.LastCombatTime) < lastTime )
         {
           m_Killer = info.Attacker;
           lastTime = (DateTime.Now - info.LastCombatTime);
         }

  if (!isBaseCreature && !info.CriminalAggression)
  m_Aggressors.Add(info.Attacker);
       }

       for ( int i = 0; i < owner.Aggressed.Count; ++i )
       {
         AggressorInfo info = owner.Aggressed[i];

         if ( (DateTime.Now - info.LastCombatTime) < lastTime )
         {
           m_Killer = info.Defender;
           lastTime = (DateTime.Now - info.LastCombatTime);
         }

  if (!isBaseCreature)
  m_Aggressors.Add(info.Defender);
       }

  if (isBaseCreature)
  {
         BaseCreature bc = (BaseCreature)owner;

         Mobile master = bc.GetMaster();
         if( master != null )
           m_Aggressors.Add( master );

         List<DamageStore> rights = BaseCreature.GetLootingRights( bc.DamageEntries, bc.HitsMax );
         for ( int i = 0; i < rights.Count; ++i )
         {
           DamageStore ds = rights[i];

           if ( ds.m_HasRight )
             m_Aggressors.Add( ds.m_Mobile );
         }
       }

       BeginDecay( m_DefaultDecayTime );

  DevourCorpse();
     }
     }
     public Corpse( Serial serial ) : base( serial )
     {
     }

(...)

I would rather do this :
Code:
  public Corpse( Mobile owner, HairInfo hair, FacialHairInfo facialhair, List<Item> equipItems )
       : base(  0x2006 )
{

  	if (owner is PlayerMobile)
  	{
		ItemID =  0x1FD9;
		GumpID = 1313;
	  }
	else
	 {
		ItemID =  0x2006;
		GumpID = 9;
  		Visible = true;
	}

  		m_ViewedBy = new List<Mobile>();
       // To supress console warnings, stackable must be true
       Stackable = true;
       Amount = owner.Body; // protocol defines that for itemid 0x2006, amount=body
       Stackable = false;
   		//  this.ItemID =  0x1FD9;
       //this.Z +=2;
       Weight = 155;
       //Hue = owner.Hue;
       //Direction = owner.Direction;
       Name = owner.Name;
      // LiftOverride = false;


       m_Owner = owner;

       m_CorpseName = GetCorpseName( owner );

       m_TimeOfDeath = DateTime.Now;

       m_AccessLevel = owner.AccessLevel;
       m_Guild = owner.Guild as Guild;
       m_Kills = owner.Kills;
  	SetFlag(CorpseFlag.Criminal, owner.Criminal);

       m_Hair = hair;
       m_FacialHair = facialhair;

	// This corpse does not turn to bones if: the owner is not a player
  	SetFlag(CorpseFlag.NoBones, !owner.Player);

       m_Looters = new List<Mobile>();
       m_EquipItems = equipItems;

       m_Aggressors = new List<Mobile>( owner.Aggressors.Count + owner.Aggressed.Count );
       //bool addToAggressors = !( owner is BaseCreature );

  	bool isBaseCreature = (owner is BaseCreature);

       TimeSpan lastTime = TimeSpan.MaxValue;

       for ( int i = 0; i < owner.Aggressors.Count; ++i )
       {
         	AggressorInfo info = owner.Aggressors[i];

        	 if ( (DateTime.Now - info.LastCombatTime) < lastTime )
         	{
          	 m_Killer = info.Attacker;
           	lastTime = (DateTime.Now - info.LastCombatTime);
        	 }

		 if (!isBaseCreature && !info.CriminalAggression)
		 	m_Aggressors.Add(info.Attacker);
       }

       for ( int i = 0; i < owner.Aggressed.Count; ++i )
       {
         	AggressorInfo info = owner.Aggressed[i];

        	 if ( (DateTime.Now - info.LastCombatTime) < lastTime )
         	{
         	  m_Killer = info.Defender;
          	 lastTime = (DateTime.Now - info.LastCombatTime);
        	 }

  		if (!isBaseCreature)
  			m_Aggressors.Add(info.Defender);
       }

	if (isBaseCreature)
	{
         	BaseCreature bc = (BaseCreature)owner;

        	 Mobile master = bc.GetMaster();
        	 if( master != null )
         	  m_Aggressors.Add( master );

         	List<DamageStore> rights = BaseCreature.GetLootingRights( bc.DamageEntries, bc.HitsMax );
        	 for ( int i = 0; i < rights.Count; ++i )
        	 {
           		DamageStore ds = rights[i];

          		 if ( ds.m_HasRight )
            			 m_Aggressors.Add( ds.m_Mobile );
        	 }
       }

       BeginDecay( m_DefaultDecayTime );

		DevourCorpse();
     }


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

(...)

As you have added an IF at the beginning of the of the 'Public Corpse', you are skipping a good part of the code in some cases (when owner is PlayerMobile).

It may not be the perfect solution, as I didn't go through all your script, but I think this part wasn't doing what you wanted it to do ^^

Good luck !
 
Last edited:
What a silly mistake by me, thank you so much!!!!!! it got fixed
[doublepost=1545090095][/doublepost]i dont want to abuse but im having another issue now, another crash

System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Items.Corpse.OnSingleClick(Mobile from) in c:\Users\lol\Desktop\Tibia project\Scripts\Items\Misc\Corpses\Corpse.cs:line 1453
at Server.Network.PacketHandlers.LookReq(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)


Line 1453
Code:
if (!string.IsNullOrEmpty(Name) && m_Corpse.Killer != null)

Code:
 private readonly Corpse m_Corpse;
        public override void OnSingleClick(Mobile from)
        {

         if (!string.IsNullOrEmpty(Name) && m_Corpse.Killer != null)
                from.Send(new AsciiMessage(Serial, ItemID, MessageType.Label, hue, 3, "", string.Format("You see a dead human. You recognize {0}( Vol:{1} item{2}) he was killed by {3}", Name, TotalItems, TotalItems != 1 ? "s" : "",m_Corpse.Killer.Name)));
       
           else
                from.Send(new AsciiMessage(Serial, ItemID, MessageType.Label, hue, 3, "", string.Format("You see an unknown corpse. (Vol: {0} item{1})", TotalItems, TotalItems != 1 ? "s" : "")));
        }
 
Oh ! I didn't see you made a double post. Sorry !

I think you can try to modify that line like this :
Code:
if(!string.IsNullOrEmpty(Name) && m_Corpse != null && m_Corpse.Killer!=null)

I can't test it myself right now as I don't have access to the whole code at the moment, but I think it should at least go a bit further than line 1453.

It seems m_Corpse had a null value, which caused your crash.

So, it may be useful to look at why it had a null value.

Hopefully this one works though :)
 
Ayyy thank you! you help me once again. For some reason whenever a player its killed by a basecreature it doesnt say what killed the player.

BUT if i use forensic eval on the corpse it does say the creature that killed the player :O
 
Back