1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Server crashing when creatures goes over custom teleport.

Discussion in 'Script Support' started by Exale, Jun 4, 2015.

  1. Exale
    Offline

    Exale Active Member

    Joined:
    Mar 2, 2014
    Messages:
    180
    Likes Received:
    15
    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 (C#):
    1.  
    2. Server Crash Report
    3. ===================
    4.  
    5. JustUO Version 2.0, Build 5.0
    6. Operating System: Microsoft Windows NT 6.2.9200.0
    7. .NET Framework: 4.0.30319.34014
    8. Time: 6/5/2015 12:18:14 AM
    9. Mobiles: 2115
    10. Items: 97338
    11. Exception:
    12. System.NullReferenceException: Object reference not set to an instance of an object.
    13.    at Server.Items.ZeldaTeleporter.OnMoveOver(Mobile m) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Custom\Items\Zelda Teleport.cs:line 25
    14.    at Server.Mobile.Move(Direction d) in c:\Users\Forest\Desktop\trunk\Server\Mobile.cs:line 3268
    15.    at Server.Mobiles.BaseAI.DoMoveImpl(Direction d) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 2259
    16.    at Server.Mobiles.BaseAI.DoMove(Direction d, Boolean badStateOk) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 2217
    17.    at Server.Mobiles.BaseAI.DoMove(Direction d) in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 2212
    18.    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
    19.    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
    20.    at Server.Mobiles.BaseAI.DoActionWander() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 980
    21.    at Server.Mobiles.AnimalAI.DoActionWander() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\AnimalAI.cs:line 59
    22.    at Server.Mobiles.BaseAI.Think() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 864
    23.    at Server.Mobiles.BaseAI.AITimer.OnTick() in c:\Users\Forest\Desktop\Ultima Online\Scripts\Mobiles\AI\BaseAI.cs:line 3095
    24.    at Server.Timer.Slice() in c:\Users\Forest\Desktop\trunk\Server\Timer.cs:line 401
    25.    at Server.Core.Main(String[] args) in c:\Users\Forest\Desktop\trunk\Server\Main.cs:line 638
    26.  
    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 (C#):
    1.  
    2. using System;
    3. using System.Collections.Generic;
    4. using System.Text;
    5. using Server.Mobiles;
    6. using Server.Network;
    7. using Server.Spells;
    8. using Server.Accounting;
    9.  
    10. namespace Server.Items
    11. {
    12.     public class ZeldaTeleporter : Item
    13.     {
    14.  
    15.         [Constructable]
    16.         public ZeldaTeleporter() : base(0x1BC3)
    17.         {
    18.             Name = "Newbie Dungeon Teleporter";
    19.             Movable = false;
    20.             Visible = false;
    21.         }
    22.  
    23.         public override bool OnMoveOver(Mobile m)
    24.         {
    25.             Account acct = (Account)m.Account;
    26.             bool ZeldaQuestStarter = Convert.ToBoolean(acct.GetTag("ZeldaQuestComplete"));
    27.            
    28.             if (m.Player)
    29.             {
    30.                 if (m.Holding != null)
    31.                 {
    32.                     m.SendLocalizedMessage(1071955); // You cannot teleport while dragging an object.
    33.                     return true;
    34.                 }
    35.                 else if (!ZeldaQuestStarter && m.Player)
    36.                 {
    37.                     m.Location = new Point3D( 6132, 1315, 15  );
    38.                     m.Map = Map.Trammel;
    39.                     m.PlaySound (510);
    40.                     Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10, 10);
    41.                     return true;
    42.                 }
    43.                 else
    44.                 {
    45.                     m.SendMessage( "You have done all you can do in the Newbie Dungeon. You are no longer allowed to access it on this account." );
    46.                     return true;
    47.                 }
    48.             }
    49.             return true;
    50.         }
    51.  
    52.         public ZeldaTeleporter( Serial serial ) : base( serial )
    53.         {
    54.         }
    55.  
    56.         public override void Serialize( GenericWriter writer )
    57.         {
    58.             base.Serialize( writer );
    59.  
    60.             writer.Write( (int) 0 ); // version
    61.         }
    62.  
    63.         public override void Deserialize( GenericReader reader )
    64.         {
    65.             base.Deserialize( reader );
    66.  
    67.             int version = reader.ReadInt();
    68.         }
    69.     }
    70. }
    71.  
     
  2. The_Real_Jeff
    Offline

    The_Real_Jeff Active Member

    Joined:
    May 9, 2015
    Messages:
    108
    Likes Received:
    30
    You need to move this
    Code (C#):
    1. Account acct = (Account)m.Account;
    2. 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.
     
    • Winner Winner x 2
    • Agree Agree x 1
  3. Exale
    Offline

    Exale Active Member

    Joined:
    Mar 2, 2014
    Messages:
    180
    Likes Received:
    15
    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.
     
  4. The_Real_Jeff
    Offline

    The_Real_Jeff Active Member

    Joined:
    May 9, 2015
    Messages:
    108
    Likes Received:
    30
    Did you have ZeldaQuestComplete in your tags?
     
  5. Keldon
    Offline

    Keldon New Member

    Joined:
    Aug 26, 2014
    Messages:
    27
    Likes Received:
    4
    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.
     
  6. The_Real_Jeff
    Offline

    The_Real_Jeff Active Member

    Joined:
    May 9, 2015
    Messages:
    108
    Likes Received:
    30
    Code (C#):
    1.  else if (!ZeldaQuestStarter && m.Player)
    2. {
    3.     m.Location = new Point3D( 6132, 1315, 15 );
    4.     m.Map = Map.Trammel;
    Unless I'm missing something (and its late, so i may be), he's moving the player with this code.
     
  7. Keldon
    Offline

    Keldon New Member

    Joined:
    Aug 26, 2014
    Messages:
    27
    Likes Received:
    4
    I think it is late for me also (work night shift).
     
  8. Exale
    Offline

    Exale Active Member

    Joined:
    Mar 2, 2014
    Messages:
    180
    Likes Received:
    15
    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.
     
  9. tass23
    Offline

    Moderator

    Joined:
    Aug 28, 2013
    Messages:
    1,014
    Likes Received:
    131
    @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 (C#):
    1.  
    2. SETONTRIGMOB/x/6203/y/775/z/4/Map/Felucca //Enter in your own coords obviously and change the Map destination accordingly.
    3.  
    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 Like x 1
  10. Exale
    Offline

    Exale Active Member

    Joined:
    Mar 2, 2014
    Messages:
    180
    Likes Received:
    15
    Thats a good idea too, thanks tass. Still would love to know what the issue is here. Hate being so stumped lol
     
  11. Crome969
    Offline

    Crome969 Member

    Joined:
    Jan 9, 2014
    Messages:
    196
    Likes Received:
    20
    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 (C#):
    1.      
    2.      if (m is PlayerMobile)
    3.      {
    4.      }
    5.      
    as Next Step i would recommning to cast your Mobile to PlayerMobile in order to access freely to more data :

    Code (C#):
    1.      
    2.      PlayerMobile pm = m as PlayerMobile;
    3.      
    As Final Step you can add your handling code.
     
  12. The_Real_Jeff
    Offline

    The_Real_Jeff Active Member

    Joined:
    May 9, 2015
    Messages:
    108
    Likes Received:
    30
    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 (C#):
    1. if(m is PlayerMobile)
    2. {
    3.     PlayerMobile pm = (PlayerMobile)m;
    4.     // logic for when its a player here...
    5. }
    6.  
    Or do this:

    Code (C#):
    1. PlayerMobile pm = m as PlayerMobile;
    2. if(pm != null)
    3. {    
    4.     // logic for when its a player here...
    5. }
    6.  
    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]
     
    • Two Thumbs Up Two Thumbs Up x 1
  13. Exale
    Offline

    Exale Active Member

    Joined:
    Mar 2, 2014
    Messages:
    180
    Likes Received:
    15
    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 (C#):
    1.  
    2. public override bool OnMoveOver(Mobile m)
    3.         {          
    4.             if(m is PlayerMobile)
    5.             {
    6.                 PlayerMobile pm = (PlayerMobile)m;
    7.                 Account acct = (Account)m.Account;
    8.                 bool ZeldaQuestStarter = Convert.ToBoolean(acct.GetTag("ZeldaQuestComplete"));
    9.                
    10.                 if (m.Holding != null)
    11.                 {
    12.                     m.SendLocalizedMessage(1071955); // You cannot teleport while dragging an object.
    13.                     return true;
    14.                 }
    15.                 else if (!ZeldaQuestStarter)
    16.                 {
    17.                     m.Location = new Point3D( 6132, 1315, 15  );
    18.                     //m.Map = Map.Trammel;
    19.                     m.PlaySound (510);
    20.                     //Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10, 10);
    21.                     return true;
    22.                 }
    23.                 else
    24.                 {
    25.                     m.SendMessage( "You have done all you can in the Newbie Dungeon. You are no longer allowed to access it on this account." );
    26.                     return true;
    27.                 }
    28.             }
    29.             return true;
    30.         }
    31.  
    Still just teleports me in and out right away which boggles my mind as to why.
     
  14. Milva
    Offline

    Admin Moderator

    Joined:
    Mar 3, 2013
    Messages:
    3,637
    Likes Received:
    398
    Just wanted to say "Thanks Jeff" for helping so many on the forums :)
     
  15. Crome969
    Offline

    Crome969 Member

    Joined:
    Jan 9, 2014
    Messages:
    196
    Likes Received:
    20
    Yes you are right, was not my best day yesterday :)
     
  16. The_Real_Jeff
    Offline

    The_Real_Jeff Active Member

    Joined:
    May 9, 2015
    Messages:
    108
    Likes Received:
    30
    Np, my pleasure.
    We all have those, it happens :)
     
    • Like Like x 1
  17. Exale
    Offline

    Exale Active Member

    Joined:
    Mar 2, 2014
    Messages:
    180
    Likes Received:
    15
    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);
     
Similar Threads: Server crashing
Forum Title Date
General Discussion server crashing, being a pain in my **vjofufgvjlhv** Nov 10, 2017
Windows Support Server Crashing after a createworld May 31, 2016
Windows Support Server crashing. May 17, 2016
General Discussion Server crashing going to custom map Nov 13, 2015
3rd Party Support CentrED+ server config Dec 4, 2017
ServUO Discussion Server Crashes when player uses this command(Fixed) Dec 3, 2017
Script Support How to ''lock'' server so people cant join? Nov 30, 2017