Discussion in   Coding Corner   started     11 years ago   August 05, 2013, 06:55:56 AM   by   Keldon

Mobs talking?

Keldon
Offline
223 Posts
Topic :   Mobs talking?
11 years ago  August 05, 2013, 06:55:56 AM

The code you suggest for the mobs talking would not compile.  I took some basics from the Juka Lord and some of what you suggest Kyn and came up with a hybrid.  How does this look?


Also I seem to be failing at using the code tags on the forum.  HTML is obviously not my thing.



        public static bool m_Talked;

        public override void OnMovement(Mobile m, Point3D oldLocation)
        {
            if (m_Talked == false)
            {
                if (m.InRange(this, 3) && m is PlayerMobile)
                {
                    string[] WeaponSmugglerSay = new string[]
                   {
                        "Your weapon will please The Dark One",
                        "I want your armor, it will make my job easier",
                        "The Dark One will take over these lands",
                        "I want you to die",
                        "The Dark One is Lord, embrace him",
                        "Drop to your knees and praise The Dark One",
                        "If you are not with The Dark One you are against him, prepare for WAR!",
                        "Please don't kill me",
                        "I am here by force, The Dark One is too powerful",
                   };
                    m_Talked = true;
                    this.Say(true, String.Format(WeaponSmugglerSay[Utility.Random(WeaponSmugglerSay.Length)]));
                    this.Move(GetDirectionTo(m.Location));
                    SpamTimer t = new SpamTimer();
                    t.Start();
                }
            }
        }




        public class SpamTimer : Timer
        {
            public SpamTimer()
                : base(TimeSpan.FromSeconds(30))
            {
                Priority = TimerPriority.OneSecond;
            }
            protected override void OnTick()
            {
                m_Talked = false;
            }

        }

Keldon
Offline
223 Posts
#1 Re :   Mobs talking?
11 years ago  August 05, 2013, 06:57:08 AM

added note this will compile, my previous method did not compile.

Kyn
Offline
336 Posts
#2 Re :   Mobs talking?
11 years ago  August 05, 2013, 12:36:12 PM

Code: [Select]
private static bool m_Talked;
          string[]InsertMobileNameHereSay = new string[]
          {
"blah blah blah!",
"blah blah blah!",
"blah blah blah!",
"blah blah blah!",
"blah blah blah!",
"blah blah blah!",
};




public override void OnMovement( Mobile m, Point3D oldLocation )
            {


                 if( m_Talked == false )
                 {
                      if ( m.InRange( this, 3 ) && m is PlayerMobile)
                       {


                             m_Talked = true;
                             SayRandom(InsertMobileNameHereSay, this );
                             this.Move( GetDirectionTo( m.Location ) );
                             SpamTimer t = new SpamTimer();
                             t.Start();
                        }
                   }
              }
           
           
  private class SpamTimer : Timer
              {
                   public SpamTimer() : base( TimeSpan.FromSeconds( 12 ) )
                   {
                        Priority = TimerPriority.OneSecond;
                   }


                   protected override void OnTick()
                   {
                           m_Talked = false;
                   }
               }


               private static void SayRandom( string[] say, Mobile m )
               {
                    m.Say( say[Utility.Random( say.Length )] );
               }
   }}


The code I suggested wasn't complete. You need to define a few other things. IE) this one is using the OnMovement method. as well as a random utility as seen in "Private static void SayRandom"

Keldon
Offline
223 Posts
#3 Re :   Mobs talking?
11 years ago  August 05, 2013, 02:54:15 PM

Yes, I had all of that and for some reason the void SayRandom portion would not compile.


I think I need to now work on setting up RUNUO on my system so I can spawn some of these mobs/items and start testing them (besides just a compile check).

Kyn
Offline
336 Posts
#4 Re :   Mobs talking?
11 years ago  August 05, 2013, 03:23:27 PM

Yes, I had all of that and for some reason the void SayRandom portion would not compile.


I think I need to now work on setting up RUNUO on my system so I can spawn some of these mobs/items and start testing them (besides just a compile check).


What was the error?


Also, you need to insert the mobiles name into the sayrandom method

Keldon
Offline
223 Posts
#5 Re :   Mobs talking?
11 years ago  August 05, 2013, 03:47:47 PM


What was the error?


Also, you need to insert the mobiles name into the sayrandom method


insert the mobiles name into the sayrandom method?  I will need to look for that.  That might have been why it would not compile.  When I get time tonight I will dig around and see what I can figure out.

Keldon
Offline
223 Posts
#6 Re :   Mobs talking?
11 years ago  August 07, 2013, 01:32:10 AM

I changed the mobs to talk ondamage instead of onmovement.  onmovement the mob was saying stuff every 30 seconds no matter what.  I figure why add a group of mobs that are always talking even if no one is around.  I testing the mob and my code compiles and the mob talks as expected.