Guest User

Untitled

a guest
Jan 23rd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1. /*      ***** NOTE *****
  2.  *
  3.  *  Use of this script requires replacing the OnTick method in
  4.  *  Scripts/Misc/WelcomeTimer.cs
  5.  *  with the OnTick method provided below.
  6.  *
  7.  *  and requires adding the following namespace reference to the top of WelcomeTimer.cs
  8.  *
  9.  *  using Server.Accounting;
  10.  *
  11.  ***************************************************
  12.  *
  13.  *  protected override void OnTick()
  14.  *  {
  15.  *      if ( m_State < m_Count )
  16.  *          m_Mobile.SendMessage( 0x35, m_Messages[m_State++] );
  17.  *
  18.  *      if ( m_State == m_Count )
  19.  *      {
  20.  *          Stop();            
  21.  *
  22.  *          if( Server.Accounting.DupeCharName.checkForDupeCharName( m_Mobile ) )
  23.  *          {
  24.  *              m_Mobile.Prompt = new DupeCharName.ChangeNamePrompt( m_Mobile );               
  25.  *          }
  26.  *      }
  27.  *  }
  28.  *
  29.  */
  30.  
  31. using System;
  32. using Server;
  33. using Server.Gumps;
  34. using Server.Prompts;
  35. using Server.Misc;
  36. using Server.Network;
  37. using System.Collections;
  38. using Server.Mobiles;
  39. using Server.Accounting;
  40.  
  41. namespace Server.Accounting
  42. {
  43.     public class DupeCharName
  44.     {
  45.        
  46.         public static bool checkForDupeCharName( Mobile m )
  47.         {
  48.             if( m == null )
  49.                 return true;
  50.            
  51.             ArrayList results = new ArrayList();
  52.             string matchEntry = m.Name;
  53.             string search = matchEntry.ToLower();
  54.             ArrayList mobiles = new ArrayList( World.Mobiles.Values );
  55.  
  56.             foreach( Mobile m_toCheck in mobiles )
  57.             {
  58.                 if ( m_toCheck != null && m_toCheck != m && m_toCheck.Name != null && m_toCheck.Name.ToLower().IndexOf( search ) >= 0 )
  59.                 {
  60.                     if ( m_toCheck is PlayerMobile )
  61.                     {
  62.                         results.Add( m_toCheck );
  63.                     }
  64.                 }
  65.             }
  66.             if ( results.Count == 0 )
  67.             {
  68.                 return false;
  69.             }
  70.             else
  71.             {
  72.                 return true;
  73.             }
  74.         }
  75.    
  76.  
  77.         public class ChangeNamePrompt : Prompt
  78.         {
  79.  
  80.             public ChangeNamePrompt( Mobile from )
  81.             {
  82.                 from.SendMessage( "Your chosen name {0} is already in use or is unacceptable for use on this shard.", from.Name );
  83.                 from.SendMessage( "Please type a new name now." );
  84.                 from.Name = "Generic Player";
  85.             }
  86.  
  87.             public override void OnCancel( Mobile from )
  88.             {
  89.                 if( from == null)
  90.                     return;
  91.                 from.Prompt = new ChangeNamePrompt( from );
  92.             }
  93.  
  94.             public override void OnResponse( Mobile from, string text )
  95.             {
  96.                 if( from == null)
  97.                 {
  98.                     return;
  99.                 }
  100.  
  101.                 if( text != null )
  102.                 {
  103.                     text = text.Trim();
  104.                 }
  105.                 else
  106.                 {
  107.                     text = "Generic Player";
  108.                 }
  109.  
  110.                 if ( text != "" )
  111.                 {
  112.                     from.Name = text;
  113.                     if( !checkForDupeCharName( from ) && NameVerification.Validate( text, 2, 16, true, true, true, 1, NameVerification.SpaceDashPeriodQuote ) )
  114.                     {
  115.                         from.SendMessage( "Your name is now {0}.", text );
  116.                     }
  117.                     else
  118.                     {                  
  119.                         from.Prompt = new ChangeNamePrompt( from );
  120.                     }  
  121.                 }
  122.                 else
  123.                 {
  124.                     from.Prompt = new ChangeNamePrompt( from );
  125.                 }
  126.             }
  127.         }
  128.     }
  129. }
Add Comment
Please, Sign In to add comment