public void OnMovement( Mobile mob, Mobile mover, Point3D oldLocation )
public override bool HandlesOnSpeech( Mobile from )
{
InhumanSpeech speechType = this.SpeechType;
if ( speechType != null && (speechType.Flags & IHSFlags.OnSpeech) != 0 && from.InRange( this, 3 ) )
return true;
return ( m_AI != null && m_AI.HandlesOnSpeech( from ) && from.InRange( this, m_iRangePerception ) );
}
public override void OnSpeech( SpeechEventArgs e )
{
InhumanSpeech speechType = this.SpeechType;
if ( speechType != null && speechType.OnSpeech( this, e.Mobile, e.Speech ) )
e.Handled = true;
else if ( !e.Handled && m_AI != null && e.Mobile.InRange( this, m_iRangePerception ) )
m_AI.OnSpeech( e );
}
rsmiller21 said:However, if you look into InhumanSpeech.cs you will see that everything that is said is compleatly random and wont make any sense. And the trigger is:
Code:public void OnMovement( Mobile mob, Mobile mover, Point3D oldLocation )
The same method I used before. One question I have for you is, why do you want vendors to talk even if the player isn't there? If a tree falls in the forest and no one is there, does it make a sound?
private DateTime m_NextTalk;
private string m_name;
public DateTime NextTalk{ get{ return m_NextTalk; } set{ m_NextTalk = value; } }
public override void OnMovement( Mobile m, Point3D oldLocation )
{
if( m is BaseVendor )
{
if ( DateTime.Now >= m_NextTalk && InRange( m, 4 ) && InLOS( m ) ) // check if it's time to talk & if mobile in range & in los.
{
m_name = m.Name;
switch ( Utility.Random( 4 )) //the amount of lines you have it to choose from
{
case 0: Say(m_name + ", how are you doing today?"); break; //line 1
case 1: Say("I hate that guy don't you " + m_name + " ?"); break; //line 2
case 3: Say("I wonder what I am going to have for dinner."); break; //line 3
};
m_NextTalk = (DateTime.Now + TimeSpan.FromSeconds( 10 )); //channge the number 10 to the min amount of seconds to wait between talks.
}
}
if( m is PlayerMobile )
{
if ( DateTime.Now >= m_NextTalk && InRange( m, 4 ) && InLOS( m ) ) // check if it's time to talk & if mobile in range & in los.
{
m_name = m.Name;
switch ( Utility.Random( 4 )) //the amount of lines you have it to choose from
{
case 0: Say(m_name + ", how are you doing today?"); break; //line 1
case 1: Say("What can I do for you " + m_name + " ?"); break; //line 2
case 3: Say("I wonder what I am going to have for dinner."); break; //line 3
};
m_NextTalk = (DateTime.Now + TimeSpan.FromSeconds( 10 )); //channge the number 10 to the min amount of seconds to wait between talks.
}
}
}
private DateTime m_NextTalk;
private string m_name;
public DateTime NextTalk{ get{ return m_NextTalk; } set{ m_NextTalk = value; } }
public override void OnMovement( Mobile m, Point3D oldLocation )
{
if( m is BaseVendor )
{
if ( DateTime.Now >= m_NextTalk && InRange( m, 500 ) ) // check if it's time to talk & if mobile in range & in los.
{
m_name = m.Name;
switch ( Utility.Random( 8 )) //the amount of lines you have it to choose from
{
case 0: Say(m_name + ", how are you doing today?"); break; //line 1
case 1: Say("I hate that guy don't you " + m_name + " ?"); break; //line 2
case 3: Say("I wonder what I am going to have for dinner."); break; //line 3
};
m_NextTalk = (DateTime.Now + TimeSpan.FromSeconds( 10 )); //channge the number 10 to the min amount of seconds to wait between talks.
}
}
public override void OnThink( Mobile from)
{
if ( from is PlayerMobile )
{
PlayerMobile pm = (PlayerMobile)from;
if ( from.InRange( this, 4 ) )
{
//Speech goes here
}
}
base.OnThink();
}
rsmiller21 said:Packer
Ok, here we are. This snippet will respond to vendors and players. You can add more sayings by changing the Random number and adding more cases. This has been tested and works. Just throw it into and vendor, not basevendor:
Code:private DateTime m_NextTalk; private string m_name; public DateTime NextTalk{ get{ return m_NextTalk; } set{ m_NextTalk = value; } } public override void OnMovement( Mobile m, Point3D oldLocation ) { if( m is BaseVendor ) { if ( DateTime.Now >= m_NextTalk && InRange( m, 4 ) && InLOS( m ) ) // check if it's time to talk & if mobile in range & in los. { m_name = m.Name; switch ( Utility.Random( 4 )) //the amount of lines you have it to choose from { case 0: Say(m_name + ", how are you doing today?"); break; //line 1 case 1: Say("I hate that guy don't you " + m_name + " ?"); break; //line 2 case 3: Say("I wonder what I am going to have for dinner."); break; //line 3 }; m_NextTalk = (DateTime.Now + TimeSpan.FromSeconds( 10 )); //channge the number 10 to the min amount of seconds to wait between talks. } } if( m is PlayerMobile ) { if ( DateTime.Now >= m_NextTalk && InRange( m, 4 ) && InLOS( m ) ) // check if it's time to talk & if mobile in range & in los. { m_name = m.Name; switch ( Utility.Random( 4 )) //the amount of lines you have it to choose from { case 0: Say(m_name + ", how are you doing today?"); break; //line 1 case 1: Say("What can I do for you " + m_name + " ?"); break; //line 2 case 3: Say("I wonder what I am going to have for dinner."); break; //line 3 }; m_NextTalk = (DateTime.Now + TimeSpan.FromSeconds( 10 )); //channge the number 10 to the min amount of seconds to wait between talks. } } }
This however, should work the way you want regardless if anyone is present. The only trigger is the movement. This code is tested and works as well:
}Code:private DateTime m_NextTalk; private string m_name; public DateTime NextTalk{ get{ return m_NextTalk; } set{ m_NextTalk = value; } } public override void OnMovement( Mobile m, Point3D oldLocation ) { if( m is BaseVendor ) { if ( DateTime.Now >= m_NextTalk && InRange( m, 500 ) ) // check if it's time to talk & if mobile in range & in los. { m_name = m.Name; switch ( Utility.Random( 8 )) //the amount of lines you have it to choose from { case 0: Say(m_name + ", how are you doing today?"); break; //line 1 case 1: Say("I hate that guy don't you " + m_name + " ?"); break; //line 2 case 3: Say("I wonder what I am going to have for dinner."); break; //line 3 }; m_NextTalk = (DateTime.Now + TimeSpan.FromSeconds( 10 )); //channge the number 10 to the min amount of seconds to wait between talks. } }
But now it works good, when player see, it trigger, if no, it don't...Galfaroth said:Tested rsmiller... isn't there chance to rebuild it for basevendor?
siran said:Don't all basecreatures (of which are vendors) already use an OnThink method, which is repeatedly executed? Why not just add something like this:
Code:public override void OnThink () { if (Utility.RandomBool ()) // Insert talking logic here base.OnThink (); }
Actually yes.Packer898 said:Actually no. If you look in basevendor.cs they use OnDragDrop, OnSingleCLick etc...
They dont use the OnThink method probably for all the reasons we stated above.