Full Version : Help Please Got a crash
xmlspawner >>Scripting Support >>Help Please Got a crash
<< Prev | Next >>
Erica- 11-18-2007
hi ArteGordon have any idea how i can fix this crash heres the crash log on debug.

CODE
RunUO Version 2.0, Build 2870.8034 Operating System: Microsoft Windows NT 5.1.2600 Service Pack 2 .NET Framework: 2.0.50727.1378 Time: 11/18/2007 9:31:03 AM Mobiles: 2495
Items: 110043
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Items.Glasses.CanEquip(Mobile m) in c:\Program Files\RunUO SVN 264 Mondain's Legacy\Scripts\Mondain's Legacy\Items\Armor\Glasses.cs:line 37
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)

And heres the Glasses Script.

CODE
using System; using Server; namespace Server.Items { public class Glasses : BaseArmor
{
public override int AosStrReq{ get{ return 45; } }
public override int OldStrReq{ get{ return 40; } }
public override int ArmorBase{ get{ return 30; } }
public override ArmorMaterialType MaterialType{ get{ return ArmorMaterialType.Leather; } }
private AosWeaponAttributes m_AosWeaponAttributes;
[CommandProperty( AccessLevel.GameMaster )]
public AosWeaponAttributes WeaponAttributes
{
get{ return m_AosWeaponAttributes; }
}
[Constructable]
public Glasses() : base( 0x2FB8 )
{
Weight = 2.0;
m_AosWeaponAttributes = new AosWeaponAttributes( this );
}
public Glasses( Serial serial ) : base( serial )
{
}
public override bool CanEquip( Mobile m )
{
if ( !m.NetState.SupportsExpansion( Expansion.ML ) )
{
m.SendLocalizedMessage( 1072791 ); // You must upgrade to Mondain's Legacy in order to use that item.
return false;
}
return true;
}
public override void AppendChildNameProperties( ObjectPropertyList list )
{
base.AppendChildNameProperties( list );
int prop;
list.Add( 1075085 ); // Requirement: Mondain's Legacy
if ( (prop = m_AosWeaponAttributes.HitColdArea) != 0 )
list.Add( 1060416, prop.ToString() ); // hit cold area ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitDispel) != 0 )
list.Add( 1060417, prop.ToString() ); // hit dispel ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitEnergyArea) != 0 )
list.Add( 1060418, prop.ToString() ); // hit energy area ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitFireArea) != 0 )
list.Add( 1060419, prop.ToString() ); // hit fire area ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitFireball) != 0 )
list.Add( 1060420, prop.ToString() ); // hit fireball ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitHarm) != 0 )
list.Add( 1060421, prop.ToString() ); // hit harm ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitLeechHits) != 0 )
list.Add( 1060422, prop.ToString() ); // hit life leech ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitLightning) != 0 )
list.Add( 1060423, prop.ToString() ); // hit lightning ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitLowerAttack) != 0 )
list.Add( 1060424, prop.ToString() ); // hit lower attack ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitLowerDefend) != 0 )
list.Add( 1060425, prop.ToString() ); // hit lower defense ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitMagicArrow) != 0 )
list.Add( 1060426, prop.ToString() ); // hit magic arrow ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitLeechMana) != 0 )
list.Add( 1060427, prop.ToString() ); // hit mana leech ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitPhysicalArea) != 0 )
list.Add( 1060428, prop.ToString() ); // hit physical area ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitPoisonArea) != 0 )
list.Add( 1060429, prop.ToString() ); // hit poison area ~1_val~%
if ( (prop = m_AosWeaponAttributes.HitLeechStam) != 0 )
list.Add( 1060430, prop.ToString() ); // hit stamina leech ~1_val~%
}
private static void SetSaveFlag( ref SaveFlag flags, SaveFlag toSet, bool setIf )
{
if ( setIf )
flags |= toSet;
}
private static bool GetSaveFlag( SaveFlag flags, SaveFlag toGet )
{
return ( (flags & toGet) != 0 );
}
private enum SaveFlag
{
None = 0x00000000,
WeaponAttributes = 0x00000001,
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
SaveFlag flags = SaveFlag.None;
SetSaveFlag( ref flags, SaveFlag.WeaponAttributes, !m_AosWeaponAttributes.IsEmpty );
writer.Write( (int) flags );
if ( GetSaveFlag( flags, SaveFlag.WeaponAttributes ) )
m_AosWeaponAttributes.Serialize( writer );
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize( reader );
int version = reader.ReadInt();
SaveFlag flags = (SaveFlag) reader.ReadInt();
if ( GetSaveFlag( flags, SaveFlag.WeaponAttributes ) )
m_AosWeaponAttributes = new AosWeaponAttributes( this, reader );
else
m_AosWeaponAttributes = new AosWeaponAttributes( this );
}
}
}

the crash happens when you pull a player off line and put glasses on him.
ArteGordon- 11-20-2007
the problem is here

QUOTE
public override bool CanEquip( Mobile m ) { if ( !m.NetState.SupportsExpansion( Expansion.ML ) ) { m.SendLocalizedMessage( 1072791 ); // You must upgrade to Mondain's Legacy in order to use that item.
return false;
}
return true;
}

if the player is offline, then m.NetState is null. You need to add another check, like this

QUOTE
public override bool CanEquip( Mobile m ) { if ( m == null || m.NetState == null ) { return false;
}
else
if ( !m.NetState.SupportsExpansion( Expansion.ML ) )
{
m.SendLocalizedMessage( 1072791 ); // You must upgrade to Mondain's Legacy in order to use that item.
return false;
}
return true;
}

which will block equipping chars that are offline. If you change the return value to true, then you will enable equipping offline chars.