sahisahi

Member
Hello i got a weird crash today, from a armor script OnEquip method, players used that armor for like a month and nothing happened, today it crashed teh server:

This is the crashlog

Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Items.PlateOfHonorLegs.OnEquip(Mobile from) in c:\Users\x\Scripts\ML Peerless System\PlateofHonor\Legs.cs:line 46
at Server.Mobile.EquipItem(Item item)
at Server.Network.PacketHandlers.EquipReq(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)

Line 46
Code:
  TimeSpan ts = DateTime.UtcNow - acct.Created;

how can that line crash? :O


Code:
using System;
using Server;
using Server.Network;
using Server.Accounting;
using Server.Items;
using Server.Engines.XmlSpawner2;

namespace Server.Items
{
    [FlipableAttribute( 0x1415, 0x1416 )]
    public class PlateOfHonorChest : BaseArmor
    {
        public override int LabelNumber{ get{ return 1074303; } }
    //    public override int BasePhysicalResistance{ get{ return 8; } }
        private int BoundToSoul = 0;// Start binding value as zero.
  
        private bool m_Blessed;

        public override int InitMinHits{ get{ return 50; } }
        public override int InitMaxHits{ get{ return 65; } }

        public override int AosStrReq{ get{ return 95; } }
        public override int OldStrReq{ get{ return 60; } }

    //    public override int OldDexBonus{ get{ return -8; } }

        public override int ArmorBase{ get{ return 34; } }
public override ArmorMaterialType MaterialType{ get{ return ArmorMaterialType.Leather; } }

        [Constructable]
        public PlateOfHonorChest() : base( 0x1415 )
        {
            Weight = 1.0;
        //Movable = false;
        Hue = 1348;
            LootType = LootType.Blessed;
            Name = "Novice chest";
            XmlAttach.AttachTo(this, new TemporaryQuestObject("temporarypeto", 604800));
        }
     
                   public override bool OnEquip( Mobile from )
              {
             /////////edit for if ACCOUNT is more than 7 days old///////////////////
            Account acct = from.Account as Account;

            TimeSpan ts = DateTime.UtcNow - acct.Created;
         
                  if(BoundToSoul == 0 /*&& ts.TotalDays < 7 && acct != null )   //Check to see if bound to a serial.
                  {
                      BoundToSoul = from.Serial; //Bind to a serial on first time equiped.

                    this.Name = from.Name.ToString() + " Novice Chest [Bounded]";//Change item name and add who it is bound to.
                    //    Movable = true;
                    this.LootType = LootType.Regular;

                      //from.Emote( "* " + from.Name + " feels weird *" );
   

               base.OnEquip( from );
 
               return true; //Allow it to bind to the first player to equip it after creation.
                     //Will show in [props as ParentEntity and RootParentEntitty as [m] Serial, "Player Name"
 

              }
                   else if(BoundToSoul == from.Serial) //Check to see if sword is bound to who is equiping it. y si no supera los 400 en skills
              {

                  //from.Emote( "* " + from.Name + " feels weird *" );
   

               base.OnEquip( from );
 
               return true; //Allow player who had bound to sword to equip it.
 

              }
              else
              {
               
                from.SendAsciiMessage(1156,"You are not novice" );
   
            return false; //Disallow any one else from equiping the sword.
        }
    }

       public override void OnSingleClick( Mobile from )
{

PrivateOverheadMessage( MessageType.Label, 2591, true, "[Temporay]", from.NetState );
    base.OnSingleClick( from );
}
 
        public PlateOfHonorChest( Serial serial ) : base( serial )
        {
        }
     
        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );

            writer.Write( (int) 0 ); // version
                 writer.Write( (int) BoundToSoul );//Serialize who it is bound to.
        }

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

            int version = reader.ReadInt();
                 BoundToSoul = reader.ReadInt();//Read on startup who it is bound to.
        }
    }
}
 
Last edited:
Would crash if that armor was equipped to an NPC - because NPC's don't have an Account.

'acct' is therefore null.
 

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back