ExX

Member
So I made a teleport that only allows you to use it if you don't have a custom account tag. Been working on it for hours since I am so new, and I got it to compile. I was testing out the different parts I put into it. Like only allowing players on it. So I spawned a dog next to it so try and get the dog to enter it and the server crashed when he moved over it.

This is the debug crash report.
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/5/2015 12:18:14 AM
Mobiles: 2115
Items: 97338
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Items.ZeldaTeleporter.OnMoveOver(Mobile m) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Custom\Items\Zelda Teleport.cs:line 25
   at Server.Mobile.Move(Direction d) in c:\Users\Forest\Desktop\trunk\Server\Mobile.cs:line 3268
   at Server.Mobiles.BaseAI.DoMoveImpl(Direction d) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 2259
   at Server.Mobiles.BaseAI.DoMove(Direction d, Boolean badStateOk) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 2217
   at Server.Mobiles.BaseAI.DoMove(Direction d) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 2212
   at Server.Mobiles.BaseAI.WalkRandom(Int32 iChanceToNotMove, Int32 iChanceToDir, Int32 iSteps) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 2090
   at Server.Mobiles.BaseAI.WalkRandomInHome(Int32 iChanceToNotMove, Int32 iChanceToDir, Int32 iSteps) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 2437
   at Server.Mobiles.BaseAI.DoActionWander() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 980
   at Server.Mobiles.AnimalAI.DoActionWander() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\AnimalAI.cs:line 59
   at Server.Mobiles.BaseAI.Think() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 864
   at Server.Mobiles.BaseAI.AITimer.OnTick() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 3095
   at Server.Timer.Slice() in c:\Users\Forest\Desktop\trunk\Server\Timer.cs:line 401
   at Server.Core.Main(String[] args) in c:\Users\Forest\Desktop\trunk\Server\Main.cs:line 638

This is the script I made. (feel free to point out any other flaws I may have messed up. I've learned so much the last month but still very new. lol)

Code:
using System;
using System.Collections.Generic;
using System.Text;
using Server.Mobiles;
using Server.Network;
using Server.Spells;
using Server.Accounting;

namespace Server.Items
{
	public class ZeldaTeleporter : Item
	{

		[Constructable]
		public ZeldaTeleporter() : base(0x1BC3)
		{
			Name = "Newbie Dungeon Teleporter";
			Movable = false;
			Visible = false;
		}

		public override bool OnMoveOver(Mobile m)
		{
			Account acct = (Account)m.Account;
			bool ZeldaQuestStarter = Convert.ToBoolean(acct.GetTag("ZeldaQuestComplete"));
			
			if (m.Player)
			{
				if (m.Holding != null)
				{
					m.SendLocalizedMessage(1071955); // You cannot teleport while dragging an object.
					return true;
				}
				else if (!ZeldaQuestStarter && m.Player)
				{
					m.Location = new Point3D( 6132, 1315, 15  );
					m.Map = Map.Trammel;
					m.PlaySound (510);
					Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10, 10);
					return true;
				}
				else
				{
					m.SendMessage( "You have done all you can do in the Newbie Dungeon. You are no longer allowed to access it on this account." );
					return true;
				}
			}
			return true;
		}

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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
		}

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

			int version = reader.ReadInt();
		}
	}
}
 
You need to move this
Code:
Account acct = (Account)m.Account;
bool ZeldaQuestStarter = Convert.ToBoolean(acct.GetTag("ZeldaQuestComplete"));

inside the if statement for m.Player. You are trying to get the account on a mobile that may not have one. This causes acct.GetTag to throw a null reference.
 
Thank you that fixed that issue completely. Didn't even think of that. I have a last question is anyone knows the answer. The script seems to work fine except it doesnt teleport me to those coords. I have seen that code in other scripts and I even have it working perfect in a gump I made but for some reason it just just the sound and doesnt seem to teleport me anywhere. I am unsure why.
 
Looking at your script you do an effect at the ending location but you do not actually move the player to that location. I am at work right now and cannot post the actual code but that is what you are lacking.
 
Looking at your script you do an effect at the ending location but you do not actually move the player to that location. I am at work right now and cannot post the actual code but that is what you are lacking.
Code:
 else if (!ZeldaQuestStarter && m.Player)
{
    m.Location = new Point3D( 6132, 1315, 15 );
    m.Map = Map.Trammel;

Unless I'm missing something (and its late, so i may be), he's moving the player with this code.
 
I tested it some more this morning. With the tag and without the tag. With the tag the script does as it is supposed to and tells you that you can no longer enter the dungeon. Without the tag it does the effect and sound effect AND teleports you to the dungeon but back out again right away. I only noticed this when there was a delay in the action otherwise it happens so fast. When it teleports you back out it puts you right where the teleporter is so I didn't notice right away.. It's odd. I know I am new to the language but like I said I have that exact code working in another gump I made. Normal moongates work fine going to the dungeon so I know it's not something with the dungeon. I dont understand why the script is sending you in and out right away.
 
@Exale
As a temporary work-around until you figured out the script issue, you could use Xmlspawners (and XmlQuest) to do this for you as well. It'd actually be as simple as having a spawner that has the TRIGONCARRIED set to ZeldaQuestStarter and one entry set to do the teleport:
Code:
SETONTRIGMOB/x/6203/y/775/z/4/Map/Felucca //Enter in your own coords obviously and change the Map destination accordingly.

I had a similar issue with a quest item that teleported a player, they bounced, just like you mentioned. I changed it so that it summoned a gate instead of doing the teleport and that worked out better anyway.
 
  • Like
Reactions: ExX
Thats a good idea too, thanks tass. Still would love to know what the issue is here. Hate being so stumped lol
 
With this code you will have more then just 1 issue.
first of all before you can check any Account data, you need to be sure it is a player and not a creature :

Code:
     if (m is PlayerMobile)
     {
     }

as Next Step i would recommning to cast your Mobile to PlayerMobile in order to access freely to more data :

Code:
     PlayerMobile pm = m as PlayerMobile;

As Final Step you can add your handling code.
 
You should just cast with the "as" operator and check for null, do not do an "is" + "as", its redundant and bad practice;

Either do this:
Code:
if(m is PlayerMobile)
{
    PlayerMobile pm = (PlayerMobile)m;
    // logic for when its a player here...
}

Or do this:

Code:
PlayerMobile pm = m as PlayerMobile;
if(pm != null)
{    
    // logic for when its a player here...
}

Its extremely bad practice to do an "as" without a null check afterward. And since you are going to do the null check, there is no reason to do the "is" check.[/code]
 
Ok I think I understand what you two are trying to say and made some changes. it didn't effect my issue at all but it's nice to understand some good practices with the language. This is the new OnMoveOver code.

Code:
public override bool OnMoveOver(Mobile m)
		{			
			if(m is PlayerMobile)
			{
				PlayerMobile pm = (PlayerMobile)m;
				Account acct = (Account)m.Account;
				bool ZeldaQuestStarter = Convert.ToBoolean(acct.GetTag("ZeldaQuestComplete"));
				
				if (m.Holding != null)
				{
					m.SendLocalizedMessage(1071955); // You cannot teleport while dragging an object.
					return true;
				}
				else if (!ZeldaQuestStarter)
				{
					m.Location = new Point3D( 6132, 1315, 15  );
					//m.Map = Map.Trammel;
					m.PlaySound (510);
					//Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10, 10);
					return true;
				}
				else
				{
					m.SendMessage( "You have done all you can in the Newbie Dungeon. You are no longer allowed to access it on this account." );
					return true;
				}
			}
			return true;
		}

Still just teleports me in and out right away which boggles my mind as to why.
 
Just a quick update for anyone having the same issue in the future. Thanks to Keldon for PMing me. The proper code to port someone to a new location is not:

m.Location=new Point3D(6132, 1315, 15);
m.Map = Map.Trammel;

but instead, this:

m.MoveToWorld(new Point3D(6132, 1315, 15), Map.Trammel);
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back