Keld

Initiate
Hi all, I'd like to create a timing to insert a delay in a player command.
Stupid example:
C#:
private static void All_OnCommand(CommandEventArgs e)
{
   //INSERT DELAY CHECK TO BE ABLE TO BROADCAST AGAIN AFTER X SECONDS
   BroadcastMessage(AccessLevel.Player, 48, String.Format("[BC] {0}: "+ e.ArgString, e.Mobile.Name));
}
private static void BroadcastMessage(AccessLevel ac, int hue, string message)
{
   World.Broadcast(hue, false, ac, message);
}

Like for doubleclick on items "you have to wait x time to use it again". Is it possible? If yes, any help is appreciated. Thanks
 
Last edited:
I tried to insert a timer with a tag account check. Can be improved?
C#:
        private static void Message_OnCommand(CommandEventArgs e)
        {
            Account acct = e.Mobile.Account as Account;
            string lastMessage = acct.GetTag("MessageToAll");

            if( lastMessage == null )
            {
                BroadcastMessage(AccessLevel.Player, 48, String.Format("[ALL] {0}: "+ e.ArgString, e.Mobile.Name));
                acct.SetTag( "MessageToAll", "True" );
                TimeSpan duration = TimeSpan.FromSeconds(10);
                Timer t = new InternalTimer(e.Mobile, duration);
                t.Start();
            }
            else
            {
                e.Mobile.SendMessage("You have to wait 10 seconds to use the command again.");
            }
        }

        private class InternalTimer : Timer
        {
            private readonly Mobile m_Mobile;
            public InternalTimer(Mobile m, TimeSpan duration)
                : base(duration)
            {
                this.Priority = TimerPriority.OneSecond;
                this.m_Mobile = m;
            }

            protected override void OnTick()
            {
                Account acct = m_Mobile.Account as Account;
                acct.RemoveTag("MessageToAll");
            }
        }

        private static void BroadcastMessage(AccessLevel ac, int hue, string message)
        {
             World.Broadcast(hue, false, ac, message);
        }
 
Last edited:

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back