I recieved this crash trying to use a CarpetAddonDeed. Someone posted a version of this that they claim works in 2.0 I compaired the scripts and there is very little difference.
But their script will not compile due to "ref house". The version I have has worked for years with no problem. So I figure fixing it would be better than adding a new script that doesn't work.
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Items.BaseAddon.CheckHouse(Mobile from, Point3D p, Map map, Int32 height, List`1& list) in g:\2.0\Scripts\Items\Addons\BaseAddon.cs:line 175
at Server.Items.BaseAddon.CouldFit(IPoint3D p, Map map, Mobile from, List`1& houses) in g:\2.0\Scripts\Items\Addons\BaseAddon.cs:line 128
at Server.Gumps.CarpetGump.OnResponse(NetState sender, RelayInfo info) in g:\2.0\Scripts\Custom\CarpetAddonDeed.cs:line 145
at Server.Network.PacketHandlers.DisplayGumpResponse(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)
I added the try / catch to BaseAddon.cs and it stopped the crashes.
BaseAddon.cs
CODE |
public static bool CheckHouse( Mobile from, Point3D p, Map map, int height, ref List<BaseHouse> list ) { BaseHouse house = BaseHouse.FindHouseAt( p, map, height );
if ( from == null || house == null || !house.IsOwner( from ) ) return false; try{ if ( !list.Contains( house ) ) list.Add( house ); } catch{return false;}
return true; } |
Then I would just recieve the message "You can only place this in a house that you own!"
Commenting out the lines in CarpetAddonDeed.cs stopped the message.
CarpetAddonDeed.cs
CODE |
Server.Spells.SpellHelper.GetSurfaceTop( ref m_P3D );
List<BaseHouse> houses = null;
AddonFitResult res = addon.CouldFit( m_P3D, m_Map, from, ref houses );
if ( res == AddonFitResult.Valid ) addon.MoveToWorld( new Point3D( m_P3D ), m_Map ); else if ( res == AddonFitResult.Blocked ) from.SendLocalizedMessage( 500269 ); // You cannot build that there. // else if ( res == AddonFitResult.NotInHouse ) // from.SendLocalizedMessage( 500274 ); // You can only place this in a house that you own! else if ( res == AddonFitResult.DoorsNotClosed ) from.SendMessage( "You must close all house doors before placing this." ); |
So I stopped the crash and the message but still I have a non-working Carpet deed. Can you point me in a direction to try and fix this.
If I need to post more script, please tell me. The BaseAddon.cs and BaseAddonDeed.cs are distro.
Thanks for your help.
It is this null list that is causing the crash
CODE |
List<BaseHouse> houses = null;
AddonFitResult res = addon.CouldFit( m_P3D, m_Map, from, ref houses );
|
I would recommend making this fix to the CheckHouse method
CODE |
public static bool CheckHouse( Mobile from, Point3D p, Map map, int height, ref List<BaseHouse> list ) { BaseHouse house = BaseHouse.FindHouseAt( p, map, height );
if ( from == null || house == null || !house.IsOwner( from ) ) return false;
if (list == null) list = new List<BaseHouse>();
if ( !list.Contains( house ) ) list.Add( house );
return true; }
|