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

Speech Command while mounted

Discussion in 'Script Support' started by RedBeard, Feb 10, 2014.

  1. RedBeard
    Offline

    RedBeard Active Member

    Joined:
    May 19, 2013
    Messages:
    365
    Likes Received:
    72
    Publish Number:
    54
    Here is what I have so far :
    Error is in BlackCloud section
    Code (C#):
    1. using System;
    2. using Server;
    3. using Server.Items;
    4. using Server.Mobiles;
    5. using System.Collections;
    6. using System.Collections.Generic;
    7. using Server.Network;
    8. using Server.Spells;
    9. namespace Server.Mobiles
    10. {
    11. [CorpseName( "a dread warhorse corpse" )]
    12. public class DreadWarHorseTemp : BaseMount
    13. {
    14.   [Constructable]
    15.   public DreadWarHorseTemp() : this( "a dread warhorse" )
    16.   {
    17.   }
    18.   [Constructable]
    19.   public DreadWarHorseTemp( string name ) : base( name, 0x74, 0x3EA7, AIType.AI_Mage, FightMode.Closest, 10, 1, 0.2, 0.4 )
    20.   {
    21.   BodyValue = 177;
    22.   BaseSoundID = 0xA8;
    23.   Hue = 1175;
    24.   SetStr( 502, 551 );
    25.   SetDex( 89, 123 );
    26.   SetInt( 100, 159 );
    27.   SetHits( 555, 648 );
    28.   SetDamage( 20, 26 );
    29.   SetDamageType( ResistanceType.Physical, 40 );
    30.   SetDamageType( ResistanceType.Poison, 20 );
    31.   SetDamageType( ResistanceType.Energy, 40 );
    32.   SetResistance( ResistanceType.Physical, 65, 75 );
    33.   SetResistance( ResistanceType.Fire, 20, 40 );
    34.   SetResistance( ResistanceType.Cold, 20, 40 );
    35.   SetResistance( ResistanceType.Poison, 50, 60 );
    36.   SetResistance( ResistanceType.Energy, 40, 50 );
    37.   SetSkill( SkillName.EvalInt, 30.5, 50.0 );
    38.   SetSkill( SkillName.Magery, 42.4, 50.0 );
    39.   SetSkill( SkillName.MagicResist, 92.6, 96.4 );
    40.   SetSkill( SkillName.Tactics, 97.6, 109.1 );
    41.   SetSkill( SkillName.Wrestling, 80.5, 95.8 );
    42.   Fame = 14000;
    43.   Karma = -14000;
    44.   VirtualArmor = 60;
    45.   Tamable = true;
    46.   ControlSlots = 3;
    47.   MinTameSkill = 105.0;
    48.   m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 5, 30 ) );
    49.   }
    50.   public override void GenerateLoot()
    51.   {
    52.   AddLoot( LootPack.Rich );
    53.   AddLoot( LootPack.Average );
    54.   AddLoot( LootPack.LowScrolls );
    55.   AddLoot( LootPack.Potions );
    56.   }
    57.   public override int GetAngerSound()
    58.   {
    59.   if ( !Controlled )
    60.     return 0x16A;
    61.   return base.GetAngerSound();
    62.   }
    63.   private DateTime m_NextAbilityTime;
    64.   public override void OnActionCombat()
    65.   {
    66.   Mobile combatant = Combatant;
    67.   if ( DateTime.Now < m_NextAbilityTime || combatant == null || combatant.Deleted || combatant.Map != Map || !InRange( combatant, 3 ) || !CanBeHarmful( combatant ) || !InLOS( combatant ) )
    68.     return;
    69.   m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 5, 30 ) );
    70.   if ( Utility.RandomBool() )
    71.   {
    72.     this.FixedParticles( 0x376A, 9, 32, 0x2539, EffectLayer.LeftHand );
    73.     this.PlaySound( 0x1DE );
    74.     foreach ( Mobile m in this.GetMobilesInRange( 2 ) )
    75.     {
    76.     if ( m != this && IsEnemy( m ) )
    77.     {
    78.       m.ApplyPoison( this, Poison.Deadly );
    79.     }
    80.     }
    81.   }
    82.   }
    83.   public override bool HasBreath{ get{ return true; } } // fire breath enabled
    84.   public override int Meat{ get{ return 5; } }
    85.   public override int Hides{ get{ return 10; } }
    86.   public override HideType HideType{ get{ return HideType.Barbed; } }
    87.   public override FoodType FavoriteFood{ get{ return FoodType.Meat; } }
    88.   public override bool CanAngerOnTame { get { return true; } }
    89.  
    90.         #region [ BlackCloud Ability ]
    91.         public virtual bool BlackCloud (mobile from)  //(Basecreature m)
    92.         {
    93.                     from.Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y, from.Z + 4), from.Map, 0x3728, 13);
    94.                     from.Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y, from.Z), from.Map, 0x3728, 13);
    95.                     from.Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y, from.Z - 4), from.Map, 0x3728, 13);
    96.                     from.Effects.SendLocationEffect(new Point3D(from.X, from.Y + 1, from.Z + 4), from.Map, 0x3728, 13);
    97.                     from.Effects.SendLocationEffect(new Point3D(from.X, from.Y + 1, from.Z), from.Map, 0x3728, 13);
    98.                     from.Effects.SendLocationEffect(new Point3D(from.X, from.Y + 1, from.Z - 4), from.Map, 0x3728, 13);
    99.                     from.Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z + 11), from.Map, 0x3728, 13);
    100.                     from.Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z + 7), from.Map, 0x3728, 13);
    101.                     from.Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z + 3), from.Map, 0x3728, 13);
    102.                     from.Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z - 1), from.Map, 0x3728, 13);
    103.                     from.PlaySound(0x228);
    104.                     from.Hidden = true;
    105.                     break;
    106.         }
    107.         #endregion
    108.         #region [OnSpeech]
    109.         public override void OnSpeech(SpeechEventArgs e)
    110.         {
    111.         if (this.Rider == null || attacker == null) //sanity
    112.                 return false;
    113.             if (!e.Handled && e.Mobile.InRange(this, 6))
    114.             {
    115.                 int[] keywords = e.Keywords;
    116.                 string speech = e.Speech;
    117.                 if ((e.HasKeyword("Trick") == true))
    118.                 {
    119.                     if (this.Controlled == false)
    120.                     {
    121.                         e.Handled = this.BlackCloud(this);
    122.                     }
    123.                     else
    124.                     {
    125.                         this.Say("You must be mounted to perform this ability.");
    126.                     }
    127.                 }
    128.             }
    129.             base.OnSpeech(e);
    130.         }
    131.         #endregion
    132.   public DreadWarHorseTemp( Serial serial ) : base( serial )
    133.   {
    134.   }
    135.   public override void GetProperties( ObjectPropertyList list )
    136.   {
    137.   base.GetProperties( list );
    138.   }
    139.   public override void Serialize( GenericWriter writer )
    140.   {
    141.   base.Serialize( writer );
    142.   writer.Write( (int) 0 ); // version
    143.   }
    144.   public override void Deserialize( GenericReader reader )
    145.   {
    146.   base.Deserialize( reader );
    147.   int version = reader.ReadInt();
    148.   }
    149. }
    150. }
    151.  
     
    #1 RedBeard, Feb 10, 2014
    Last edited: Feb 10, 2014
  2. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    Line 90:
    Code (C#):
    1. public virtual bool BlackCloud (mobile from)
    'Mobile' should be capitalized.
    Line 92-101:
    Code (C#):
    1. from.Effects.SendLocationEffect(new Point3D(from.X+1, from.Y, from.Z+4), from.Map, 0x3728, 13);
    All these 'from.Effects.SendLocationEffect' should just be 'Effects.SendLocationEffect'
    Line 104: Method is a bool but has no return type, instead you used 'break;'
    Line 110-112:
    Code (C#):
    1. public override void OnSpeech(SpeechEventArgs e)
    2. {
    3.     if (this.Rider == null || attacker == null) //sanity
    4.         return false;
    Pretty sure you want to check if Rider is not null if you are going to return. Sorry didn't read the thread title, if you are doing this for mounted this ignore this comment.
    There is no attacker variable, should be removed?
    'return false;' can't return a bool when the method is a void. If you just want to exit the method just use 'return;'
    Line 116:
    Code (C#):
    1. if ((e.HasKeyword("Trick") == true))
    'e.HasKeyword' only accept int parameters
     
  3. RedBeard
    Offline

    RedBeard Active Member

    Joined:
    May 19, 2013
    Messages:
    365
    Likes Received:
    72
    How to I fix this

    Line 116:
    Code (csharp):
    1. if ((e.HasKeyword("Trick") == true))
    'e.HasKeyword' only accept int parameters
     
  4. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    Use the 'e.Speech' instead to compare to a string. Try something like this:
    Code (C#):
    1. if (Insensitive.Equals(e.Speech, "Trick"))
     
  5. RedBeard
    Offline

    RedBeard Active Member

    Joined:
    May 19, 2013
    Messages:
    365
    Likes Received:
    72
    Ok compiled but the ability doesn't work

    Code (C#):
    1.  
    2. #region [ BlackCloud Ability ]
    3. publicvirtualbool BlackCloud(Mobile from)
    4. {
    5. Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y, from.Z + 4), from.Map, 0x3728, 13);
    6. Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y, from.Z), from.Map, 0x3728, 13);
    7. Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y, from.Z - 4), from.Map, 0x3728, 13);
    8. Effects.SendLocationEffect(new Point3D(from.X, from.Y + 1, from.Z + 4), from.Map, 0x3728, 13);
    9. Effects.SendLocationEffect(new Point3D(from.X, from.Y + 1, from.Z), from.Map, 0x3728, 13);
    10. Effects.SendLocationEffect(new Point3D(from.X, from.Y + 1, from.Z - 4), from.Map, 0x3728, 13);
    11. Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z + 11), from.Map, 0x3728, 13);
    12. Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z + 7), from.Map, 0x3728, 13);
    13. Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z + 3), from.Map, 0x3728, 13);
    14. Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z - 1), from.Map, 0x3728, 13);
    15. from.PlaySound(0x228);
    16. from.Hidden = true;
    17. returntrue;
    18. }
    19. #endregion
    20. #region [OnSpeech]
    21. publicoverridevoid OnSpeech(SpeechEventArgs e)
    22. {
    23. if (this.Rider == null)  //sanity
    24. return;
    25. if (!e.Handled && e.Mobile.InRange(this, 6))
    26. {
    27. string speech = e.Speech;
    28. if (Insensitive.Equals(e.Speech, "Trick"))
    29. {
    30. if (this.Controlled == false)
    31. {
    32. e.Handled = this.BlackCloud(this);
    33. }
    34. else
    35. {
    36. this.Say("You must be mounted to perform this ability.");
    37. }
    38. }
    39. }
    40. base.OnSpeech(e);
    41. }
    42. #endregion
    43.  
     
    #5 RedBeard, Feb 11, 2014
    Last edited: Feb 11, 2014
  6. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    *FacePalm* Didn't even think about this when I was looking over your code. You can't use OnSpeech for mobiles while they are mounted. The server sends the mount to the internal map when you mount them. While mounted they aren't really there, what you see is just graphics added to your character so the OnSpeech will never trigger for the mount.

    Since the base Mobile class won't fire off the OnSpeech for the mount what you can do is bypass it and use the Speech Event.

    Initialize the event like this:
    Code (C#):
    1. public static void Initialize()
    2. {
    3.     EventSink.Speech += new SpeechEventHandler(EventSink_Speech);
    4. }
    Then add this method and put your code you have inside OnSpeech inside this method instead.
    Code (C#):
    1. private static void EventSink_Speech(SpeechEventArgs e)
    2. {
    3.     // Put code here
    4. }
    Edit: Still nothing thinking straight, it's way too late. This is still going to cause problems with your range check so you'll have to get creative. When the event fires instead of checking the range you can check the Mobile doing the speech is the same as the Rider.

    Edit 2: You'll also need to change the Effects to appear around the mobile instead of the mount. 'e.Handled = this.BlackCloud(e.Mobile);'
     
    #6 Kalamus, Feb 11, 2014
    Last edited: Feb 11, 2014
  7. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    I decided to rewrite your methods some for you as what I stated above needed a bit more work than I explained ;). Use these methods and let me know how it works as it needs testing.
    Code (C#):
    1. public static void Initialize()
    2. {
    3.     EventSink.Speech += new SpeechEventHandler(EventSink_Speech);
    4. }
    5.  
    6. #region [ BlackCloud Ability ]
    7. private static void BlackCloud(Mobile from)
    8. {
    9.     Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y, from.Z + 4), from.Map, 0x3728, 13);
    10.     Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y, from.Z), from.Map, 0x3728, 13);
    11.     Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y, from.Z - 4), from.Map, 0x3728, 13);
    12.     Effects.SendLocationEffect(new Point3D(from.X, from.Y + 1, from.Z + 4), from.Map, 0x3728, 13);
    13.     Effects.SendLocationEffect(new Point3D(from.X, from.Y + 1, from.Z), from.Map, 0x3728, 13);
    14.     Effects.SendLocationEffect(new Point3D(from.X, from.Y + 1, from.Z - 4), from.Map, 0x3728, 13);
    15.     Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z + 11), from.Map, 0x3728, 13);
    16.     Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z + 7), from.Map, 0x3728, 13);
    17.     Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z + 3), from.Map, 0x3728, 13);
    18.     Effects.SendLocationEffect(new Point3D(from.X + 1, from.Y + 1, from.Z - 1), from.Map, 0x3728, 13);
    19.     from.PlaySound(0x228);
    20.     from.Hidden = true;
    21. }
    22. #endregion
    23.  
    24. #region [OnSpeech]
    25. private static void EventSink_Speech(SpeechEventArgs e)
    26. {
    27.     if (e.Handled)
    28.     {
    29.         return;
    30.     }
    31.  
    32.     if (e.Mobile is PlayerMobile && e.Mobile.Mounted && e.Mobile.Mount is DreadWarHorseTemp)
    33.     {
    34.         if (Insensitive.Equals(e.Speech, "Trick"))
    35.         {
    36.             BlackCloud(e.Mobile);
    37.             e.Handled = true;
    38.         }
    39.     }
    40. }
    41. #endregion
     
  8. RedBeard
    Offline

    RedBeard Active Member

    Joined:
    May 19, 2013
    Messages:
    365
    Likes Received:
    72
    This works good but only for owners Does it need a check for access level?
     
  9. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    What part is working 'only for owners'? The speech command or the world effects you see?
     
  10. RedBeard
    Offline

    RedBeard Active Member

    Joined:
    May 19, 2013
    Messages:
    365
    Likes Received:
    72
    Neither but intended for players. For owner it works great effects plus it hide you. As player you get effect but doesn't hide a player makes me think there is a restriction somewhere to override.
     
  11. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    I understand what you are saying now. Yeah that's another wall I didn't think of. The problem is the character is getting revealed because of the speech. The event fires before the speech checks, character gets hidden, speech checks kick in and then character gets revealed so it looks like the character was never hidden. Was trying to use the event to avoid distro edits but didn't think about the revealing action that gets called after.

    Could try kicking off a short delay timer to do the hiding part and allow the speech code time to finish but I don't think this will be reliable since you have no control over how long all the other speech events will take and your timer might fire off first still.

    Starting to think the easiest solution for you is a distro edit to achieve what you are looking for. The easiest solution would be to add your checks to PlayerMobile OnSpeech. There's more solutions to get around a distro edit but they will require some creativity and quite a bit more work and knowledge of what you are doing. One idea I can think of is to create a custom hidden item that gets placed on the player when mounting the DreadWarHorse and remove it on unmount. Give the item HandlesOnSpeech and then use the item's OnSpeech to do all your checks.
     
  12. RedBeard
    Offline

    RedBeard Active Member

    Joined:
    May 19, 2013
    Messages:
    365
    Likes Received:
    72
    I found another issue In the ability to do Area poison attack. If in Felucca it poisons the pet owner also. LOL never thought bout Felucca

    Code (C#):
    1.  
    2. privateDateTime m_NextAbilityTime;
    3. publicoverridevoid OnActionCombat()
    4. {
    5. Mobile combatant = Combatant;
    6. if ( DateTime.Now < m_NextAbilityTime || combatant == null || combatant.Deleted || combatant.Map != Map || !InRange( combatant, 3 ) || !CanBeHarmful( combatant ) || !InLOS( combatant ) )
    7. return;
    8. m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 5, 30 ) );
    9. if ( Utility.RandomBool() )
    10. {
    11. this.FixedParticles( 0x376A, 9, 32, 0x2539, EffectLayer.LeftHand );
    12. this.PlaySound( 0x1DE );
    13. foreach ( Mobile m inthis.GetMobilesInRange( 2 ) )
    14. {
    15. if ( m != this && IsEnemy( m ) )
    16. {
    17. m.ApplyPoison( this, Poison.Greater );
    18. }
    19. }
    20. }
    21. }
    22.  
     
  13. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    Try adding 'm != this.ControlMaster' to your mobile checks.
    Code (C#):
    1. foreach (Mobile m in this.GetMobilesInRange(2))
    2. {
    3.     if (m != this && m != this.ControlMaster && IsEnemy(m))
    4.     {
    5.         m.ApplyPoison(this, Poison.Deadly);
    6.     }
    7. }
     
    • Two Thumbs Up Two Thumbs Up x 1
  14. RedBeard
    Offline

    RedBeard Active Member

    Joined:
    May 19, 2013
    Messages:
    365
    Likes Received:
    72
    Yip that fix it. Thank you for all your help with this.
     
Similar Threads: Speech Command
Forum Title Date
Custom Releases I Honor Thee - Speech Command Jul 8, 2015
Script Support Changing HasKeyWord to args.Speech.ToLower Apr 18, 2017
Script Support DoSpeech question Feb 18, 2017
Script Support Spell fizzle on player speech Jan 25, 2017
Script Support Do anyone has a clue about what it is NPCSpeech script? Sep 12, 2015
3rd Party Applications Speech Viewer Apr 18, 2015
3rd Party Applications Speech editor Apr 18, 2015