ExX

Member
I have this custom region I am implementing as part of a quest. However whenever I enter the region the server crashes. This is the region code. It's pretty straight forward. It checks to see if they are a playermobile and if they do not have a custom account tag. (later that account tag makes the region uncursed). What's even more stumping is this same code snippet I have working perfectly on another quest for a teleporter. So I am a tad confused why it crashes when I enter. It also freaked out on compile about a custom npc I had spawned in that area.

Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Server;
using Server.Mobiles;
using Server.Spells;
using Server.Items;
using Server.Network;
using System.Xml;
using Server.Accounting;

namespace Server.Regions
{
	public class CursedGraveyard : BaseRegion
	{
		public CursedGraveyard( XmlElement xml, Map map, Region parent ) : base( xml, map, parent )
		{
		}

		public void CreateRemains(Mobile m)
		{
			Ztimer tm = new Ztimer(this, m);
			tm.Start();
		}

		public override bool AllowHousing( Mobile from, Point3D p )
		{
			return false;
		}

		public override void OnDeath( Mobile m )
		{
			Account acct = (Account)m.Account;
			bool BGYQuestStarter = Convert.ToBoolean(acct.GetTag("BGYQuestComplete"));
			
			if (m is PlayerMobile && (!BGYQuestStarter) )
				CreateRemains(m);
		}

		public override void OnEnter( Mobile m )
		{
			Account acct = (Account)m.Account;
			bool BGYQuestStarter = Convert.ToBoolean(acct.GetTag("BGYQuestComplete"));
			
			if (m is PlayerMobile && (!BGYQuestStarter) )
				m.SendMessage("You feel as though you are being watched.");
		}

		public override void OnExit( Mobile m )
		{
		}

		public override bool OnDecay( Item item )
		{
			return base.OnDecay( item);
		}

		private class Ztimer : Timer
		{
			Mobile plr;
			CursedGraveyard m_Region;
			private static TimeSpan m_Delay = TimeSpan.FromMinutes( 1 );

			public void Initialize()
			{
			}

			public Ztimer(CursedGraveyard rgn, Mobile m) : base(m_Delay )
			{
				Priority = TimerPriority.OneMinute;
				plr= m;
				m_Region = rgn;
			}

			protected override void OnTick()
			{
				if ((m_Region!=null) && (plr !=null) && !plr.Deleted && (plr.Corpse!=null) && !plr.Corpse.Deleted)
				{
					Corpse crp = (Corpse) plr.Corpse;
					if ((crp.Owner==plr) && m_Region.Contains(crp.Location) && (m_Region.Map==crp.Map))
					{
						WalkingRemains zomb = new WalkingRemains(crp);
					}
				}
			}
		}
	}
}
[code]
 
Without a crashlog, only thing i can tell you is acct.GetTag("BGYQuestComplete") might not be set, which could be returning "", Convert.ToBoolean only accepts "True" or "False", so you could be having a crash because of this... but we really need a crash log to be sure.
 
Just one thing, OnEnter and OnDeath in region are not only triggered by playermobiles, so you can expect a crash when you are checking a null account.
 
Sorry is the crash log. and Jack, I thought of that but doesnt "if (m is PlayerMobile" prevent crashing from npcs entering and leaving?

Code:
Server Crash Report
===================

JustUO Version 2.0, Build 5.0
Operating System: Microsoft Windows NT 6.2.9200.0
.NET Framework: 4.0.30319.34014
Time: 6/30/2015 12:47:12 AM
Mobiles: 2096
Items: 99350
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Regions.CursedGraveyard.OnEnter(Mobile m) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Custom\Quests\Britain Graveyard Quest\CursedGraveyard.cs:line 44
   at Server.Region.OnRegionChange(Mobile m, Region oldRegion, Region newRegion) in c:\Users\Forest\Desktop\trunk\Server\Region.cs:line 976
   at Server.Mobile.UpdateRegion() in c:\Users\Forest\Desktop\trunk\Server\Mobile.cs:line 7587
   at Server.Mobile.MoveToWorld(Point3D newLocation, Map map) in c:\Users\Forest\Desktop\trunk\Server\Mobile.cs:line 9704
   at Server.Mobiles.Spawner.Spawn(Int32 index) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Services\Spawner\Spawner.cs:line 614
   at Server.Mobiles.Spawner.Spawn() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Services\Spawner\Spawner.cs:line 568
   at Server.Mobiles.Spawner.Respawn() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Services\Spawner\Spawner.cs:line 562
   at Server.Mobiles.SpawnerGump.OnResponse(NetState state, RelayInfo info) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Services\Spawner\SpawnerGump.cs:line 112
   at Server.Network.PacketHandlers.DisplayGumpResponse(NetState state, PacketReader pvSrc) in c:\Users\Forest\Desktop\trunk\Server\Network\PacketHandlers.cs:line 1384
   at Server.Network.MessagePump.HandleReceive(NetState ns) in c:\Users\Forest\Desktop\trunk\Server\Network\MessagePump.cs:line 313
   at Server.Network.MessagePump.Slice() in c:\Users\Forest\Desktop\trunk\Server\Network\MessagePump.cs:line 131
   at Server.Core.Main(String[] args) in c:\Users\Forest\Desktop\trunk\Server\Main.cs:line 639

Clients:
- Count: 1
+ 127.0.0.1: (account = fcondon) (mobile = 0x1 'Exale')
 
On further inspection I think you are right Jeff. This code works on some gumps but I can see it causing issues with npcs on entering. How would I remedy this?
 
You are not checking if the mobile is a player before checking the account. You are only checking it after checking the account & tags.

Code:
       public override void OnDeath( Mobile m )
       {
            Account acct = (Account)m.Account;
           bool BGYQuestStarter = Convert.ToBoolean(acct.GetTag("BGYQuestComplete"));

What if m doesn't have an account? You haven't checked that they do.

You could just put at the very beginning of the code block

Code:
if( !(m is PlayerMobile) )
    return;
 
Last edited:
This was also an issue with the barrier into the The Abyss for SA (again, not sure if anyone addressed that yet). Whenever a player crossed the barrier with a pet, crash city.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back