Full Version : QuestNPC near banker and baseescortable.
xmlspawner >>Troubleshooting >>QuestNPC near banker and baseescortable.


<< Prev | Next >>

Galfaroth- 02-05-2006
If xmlquestnpc say sth near baseescortable or banker server crashes... Maybe only on my server. Please check this.

ArteGordon- 02-05-2006
it is probably because the quest npcs actually speak, and you must have added a speech event handler that is assuming that all speech comes from players. If you post a crash log I can point out the problem script.

Galfaroth- 02-05-2006
Here is my banker part:
CODE
 public override bool HandlesOnSpeech( Mobile from )
 {
  if ( from.InRange( this.Location, 12 ) )
   return true;

  return base.HandlesOnSpeech( from );
 }

 public override void OnSpeech( SpeechEventArgs e )
 {
  PlayerMobile pm = e.Mobile as PlayerMobile;
  if ( pm.Rasa != 2 )
  {
 
  if ( !e.Handled && e.Mobile.InRange( this.Location, 12 ) )
  {
   
  if ( e.Speech.ToLower().IndexOf( "bank" ) > -1 && pm.Rasa != 2 )
  {
   e.Handled = true;

      if ( e.Mobile.Criminal )
      {
       this.Say( 500378 ); // Thou art a criminal and cannot access thy bank box.
      }

      BankBox box = e.Mobile.BankBox;

      if ( box != null )
       box.Open();
  }
 
   for ( int i = 0; i < e.Keywords.Length; ++i )
   {
    int keyword = e.Keywords[i];

    switch ( keyword )
    {
     case 0x0000: // *withdraw*
     {
      e.Handled = true;

      if ( e.Mobile.Criminal )
      {
       this.Say( 500389 ); // I will not do business with a criminal!
       break;
      }

      string[] split = e.Speech.Split( ' ' );

      if ( split.Length >= 2 )
      {
       int amount;

       try
       {
        amount = Convert.ToInt32( split[1] );
       }
       catch
       {
        break;
       }

       if ( amount > 5000 )
       {
        this.Say( 500381 ); // Thou canst not withdraw so much at one time!
       }
       else if ( amount > 0 )
       {
        BankBox box = e.Mobile.BankBox;

        if ( box == null || !box.ConsumeTotal( typeof( Gold ), amount ) )
        {
         this.Say( 500384 ); // Ah, art thou trying to fool me? Thou hast not so much gold!
        }
        else
        {
         e.Mobile.AddToBackpack( new Gold( amount ) );

         this.Say( 1010005 ); // Thou hast withdrawn gold from thy account.
        }
       }
      }

      break;
     }
     case 0x0001: // *balance*
     {
      e.Handled = true;

      if ( e.Mobile.Criminal )
      {
       this.Say( 500389 ); // I will not do business with a criminal!
       break;
      }

      BankBox box = e.Mobile.BankBox;

      if ( box != null )
      {
       this.Say( 1042759, box.TotalGold.ToString() ); // Thy current bank balance is ~1_AMOUNT~ gold.
      }

      break;
     }
     /*case 0x0002: // *bank*
     {
      e.Handled = true;

      if ( e.Mobile.Criminal )
      {
       this.Say( 500378 ); // Thou art a criminal and cannot access thy bank box.
       break;
      }

      BankBox box = e.Mobile.BankBox;

      if ( box != null )
       box.Open();

      break;
     }*/
     case 0x0003: // *check*
     {
      e.Handled = true;

      if ( e.Mobile.Criminal )
      {
       this.Say( 500389 ); // I will not do business with a criminal!
       break;
      }

      string[] split = e.Speech.Split( ' ' );

      if ( split.Length >= 2 )
      {
       int amount;

       try
       {
        amount = Convert.ToInt32( split[1] );
       }
       catch
       {
        break;
       }

       if ( amount < 5000 )
       {
        this.Say( 1010006 ); // We cannot create checks for such a paltry amount of gold!
       }
       else if ( amount > 1000000 )
       {
        this.Say( 1010007 ); // Our policies prevent us from creating checks worth that much!
       }
       else
       {
        BankCheck check = new BankCheck( amount );

        BankBox box = e.Mobile.BankBox;

        if ( box == null || !box.TryDropItem( e.Mobile, check, false ) )
        {
         this.Say( 500386 ); // There's not enough room in your bankbox for the check!
         check.Delete();
        }
        else if ( !box.ConsumeTotal( typeof( Gold ), amount ) )
        {
         this.Say( 500384 ); // Ah, art thou trying to fool me? Thou hast not so much gold!
         check.Delete();
        }
        else
        {
         this.Say( 1042673, AffixType.Append, amount.ToString(), "" ); // Into your bank box I have placed a check in the amount of:
        }
       }
      }

      break;
     }
    }
   }
  }
  }
  base.OnSpeech( e );
 }


BaseEscortable:
CODE
 public override bool HandlesOnSpeech( Mobile from )
 {
  if ( from.InRange( this.Location, 3 ) )
   return true;

  return base.HandlesOnSpeech( from );
 }

 public override void OnSpeech( SpeechEventArgs e )
 {
  base.OnSpeech( e );
  PlayerMobile pm = e.Mobile as PlayerMobile;
  EDI dest = GetDestination();
  if ( pm.Rasa != 2 )
  {
  if ( dest != null && !e.Handled && e.Mobile.InRange( this.Location, 3 ) )
  {
   if ( e.HasKeyword( 0x1D ) ) // *destination*
    e.Handled = SayDestinationTo( e.Mobile );
   else if ( e.HasKeyword( 0x1E ) ) // *i will take thee*
    e.Handled = AcceptEscorter( e.Mobile );
  }
  }
 }


Crash:
CODE
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
  at Server.Mobiles.BaseEscortable.OnSpeech(SpeechEventArgs e)
  at Server.Mobile.DoSpeech(String text, Int32[] keywords, MessageType type, Int32 hue)
  at Server.Engines.XmlSpawner2.XmlDialog.DelayedSpeech(Object state)
  at Server.DelayStateCallTimer.OnTick()
  at Server.Timer.Slice()
  at Server.Core.Main(String[] args)

ArteGordon- 02-05-2006
this code

CODE

public override void OnSpeech( SpeechEventArgs e )
{
 PlayerMobile pm = e.Mobile as PlayerMobile;
 if ( pm.Rasa != 2 )
 {


will fail because when e.Mobile is not a PlayerMobile, then pm will be null. Then when you try access the Rasa property on it, it will crash. You need to make sure that it is not null before you try to access things on it.

QUOTE

public override void OnSpeech( SpeechEventArgs e )
{
  PlayerMobile pm = e.Mobile as PlayerMobile;

if(pm == null) return;

  if ( pm.Rasa != 2 )
  {



same problem here

CODE

public override void OnSpeech( SpeechEventArgs e )
{
 base.OnSpeech( e );
 PlayerMobile pm = e.Mobile as PlayerMobile;
 EDI dest = GetDestination();
 if ( pm.Rasa != 2 )