Tukaram

Member
Is there a way to make an NPC set a timer to keep a player from talking to him for like 30 minutes?

I am working on a Halloween NPC (not really a quest). There is an NPC that you speak a key phrase to and he gives you an item (trick or treat). I found a sample in another quest. It works, but you can stand there and spam the NPC all day and get unlimited items. I have tried working with the BaseEscortable timer, and the WitchApprentice timer, but to no avail.

The NPC spawns in random body mods (like a Halloween costume). The idea is to place a few around, and let people find them to trick or treat.

I messed with the spawner but could just make him short lived, if you wait for him you can still get more - and an extended time between spawns would be unfair to others trying to do it. I really do not want to add an OnDrop command.

Is there a way to make an NPC set a timer to keep a player from talking to him for like 30 minutes?

I am including the script, but it will not compile for you as many of the gift items are not included. I am still making items for them to give out.
 

Attachments

  • TrickOrTreat.cs
    8.8 KB · Views: 8
add variable for delay:
C#:
        public static TimeSpan TrickDelay { get { return TimeSpan.FromSeconds(10); } }
and change your Speech method to:
C#:
        public override void OnSpeech(SpeechEventArgs e)
        {
            Mobile from = e.Mobile;
            bool isMatch = e.Speech.ToLower().Contains(String.Format("{0} or threat", Name).ToLower());

            if (isMatch)
            {
                if (from.CanBeginAction(this))
                {
                    from.AddToBackpack(new Apple());
                    from.SendMessage("You get your Trick or Treat reward.");

                    from.BeginAction(this);
                    Timer.DelayCall(TrickDelay, delegate
                    {
                        from.SendMessage("You can trick again.");
                        from.EndAction(this);
                    });

                    from.SendMessage("Next trick will aviable in {0} minutes.", Math.Round(TrickDelay.TotalMinutes, 1));
                }
                else
                    from.SendMessage("You must wait before trick again!");

                e.Handled = true;

                base.OnSpeech(e);
            }
        }
 
Awesome. That worked great. This is my first time to play with OnSpeech with an NPC, and I have never been good with timers. Thanks a lot. :cool:
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back