[Huge Question] Events Triggered by Time [5165]

03/02/2010 02:27 -NewDawn-#1
Ok, I've been wanting to create events that happen at a certain time on the server. What I mean is, at an "x" time, i want something that will trigger an event that does "y".

For example:
------------
- I would like a "/c" command message to be sent to everyone at 5:00 pm saying "Event Test". (That's basicly what I've been trying to do)

My big question is, does the client support it? If it does, where do I put the even code? If it doesn't then can someone help me out? I've been working on this for a few days and had no luck.

Thanks =\
03/02/2010 02:52 spare2#2
It does, a simple timer can be used to solve your problem.
You can use the [Only registered and activated users can see links. Click Here To Register...] class.
03/02/2010 03:27 -NewDawn-#3
Quote:
Originally Posted by spare2 View Post
It does, a simple timer can be used to solve your problem.
You can use the [Only registered and activated users can see links. Click Here To Register...] class.
Holy ****. Lol...
I can't understand that. I'm self taught and I've only been looking at code for a week and a half. Can you or someone help me out and give me an example? =\

Code:
using System;
using System.Timers;

public class Timer1
{
    private static System.Timers.Timer aTimer;

    public static void Main()
    {
        // Normally, the timer is declared at the class level,
        // so that it stays in scope as long as it is needed.
        // If the timer is declared in a long-running method,  
        // KeepAlive must be used to prevent the JIT compiler 
        // from allowing aggressive garbage collection to occur 
        // before the method ends. (See end of method.)
        //System.Timers.Timer aTimer;

        // Create a timer with a ten second interval.
        aTimer = new System.Timers.Timer(10000);

        // Hook up the Elapsed event for the timer.
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

        // Set the Interval to 2 seconds (2000 milliseconds).
        aTimer.Interval = 2000;
        aTimer.Enabled = true;

        Console.WriteLine("Press the Enter key to exit the program.");
        Console.ReadLine();

        // If the timer is declared in a long-running method, use
        // KeepAlive to prevent garbage collection from occurring
        // before the method ends.
        //GC.KeepAlive(aTimer);
    }

    // Specify what you want to happen when the Elapsed event is 
    // raised.
    private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
    }
}

/* This code example produces output similar to the following:

Press the Enter key to exit the program.
The Elapsed event was raised at 5/20/2007 8:42:27 PM
The Elapsed event was raised at 5/20/2007 8:42:29 PM
The Elapsed event was raised at 5/20/2007 8:42:31 PM
...
 */
is the example they give but I don't really understand it...
03/02/2010 03:32 walmartboi#4
Code:
using System.Timers;
Code:
double minutes_to_send = NUMBER OF MINUTES YOU WANT IT TO SEND AT;
Timer Broadcast = new Timer();
Broadcast.Elapsed += new ElaspedEventHandler( sendmsg );
Broadcast.Interval = (minutes_to_send * 60 * 1000);
Broadcast.Start();
That's EXTREMELY basic, and you have to code the sendmsg void like this:

Code:
public static void sendmsg(object o, ElapsedEventArgs e)
{

}
And that was all hard coded in a quick reply box, so the errors you might get will be easy to fix, and will give you practice, but it DOES work. :)
03/02/2010 04:09 hunterman01#5
Here is a little tip though

Don't use a lot of timers if you do it will cause major lag spikes + it takes up a lot of memory
03/02/2010 04:25 -NewDawn-#6
Figured it out on my own.
#request close (<-- if that's how one does it xP)
03/02/2010 04:34 walmartboi#7
Not even a simple thanks for me typing my code on a standard text editor? :(
03/02/2010 04:35 ImFlamedCOD#8
If (Date.Time.Hour == 1 && Date.Time.Minute == 30)
{
Global.Public.Events.Start(PKEvent)//just made this part up but you get my idea.
}
03/02/2010 04:51 walmartboi#9
Just thought of this:

Code:
byte triggerhour = hour;
byte triggermin = minute;
for (; ; ) //Never-ending loop
{
    System.Threading.Thread.Sleep(60 * 1000);//checks every minute
    if (Date.Time.Hour == triggerhour && Date.Time.Minute == triggermin)
    {
       PKEvent.PKer.Start();
    }
    
}
:D
03/02/2010 05:06 -NewDawn-#10
Well you're all wrong. lol.
I figured it out and I'll release it when I'm done with a huge project i'm trying to release. i'm thinking it'll be done in a few weeks. It's a huge project =P I'm so proud of it working (so far >< lol). Thanks for your help though. I just have no idea what u're talking about =P
03/02/2010 05:11 spare2#11
Quote:
Originally Posted by -NewDawn- View Post
Well you're all wrong. lol.
I figured it out and I'll release it when I'm done with a huge project i'm trying to release. i'm thinking it'll be done in a few weeks. It's a huge project =P I'm so proud of it working (so far >< lol). Thanks for your help though. I just have no idea what u're talking about =P
I doubt that's true. It's just you did it another way.
03/02/2010 06:55 .Ocularis#12
PHP Code:
        static void EventTimer()
        {
            switch (
DateTime.Now.Minute)
            {
                case 
00:
                    {
                        if (
DateTime.Now.Hour == 23)
                        {
                            
World.API.SendMessAll2("Family Guy time!"1);
                        }
                        break;
                    } 
                case 
10:
                case 
20:
                case 
30:
                case 
40:
                case 
50:
                break;
            }
        } 
Fairly simple.... Easily expandable. Put it somewhere like.... World... Idk
I made this for my 1.0 pioneer source, so don't use the broadcast
Make a new one
03/02/2010 07:58 Nullable#13
Quote:
Originally Posted by walmartboi View Post
Code:
using System.Timers;
Code:
double minutes_to_send = NUMBER OF MINUTES YOU WANT IT TO SEND AT;
Timer Broadcast = new Timer();
Broadcast.Elapsed += new ElaspedEventHandler( sendmsg );
Broadcast.Interval = (minutes_to_send * 60 * 1000);
Broadcast.Start();
That's EXTREMELY basic, and you have to code the sendmsg void like this:

Code:
public static void sendmsg(object o, ElapsedEventArgs e)
{

}
And that was all hard coded in a quick reply box, so the errors you might get will be easy to fix, and will give you practice, but it DOES work. :)
You don't.
Code:
double minutes_to_send = NUMBER OF MINUTES YOU WANT IT TO SEND AT;
Timer Broadcast = new Timer();
Broadcast.Elapsed += delegate { sendmsg(arguments); };
Broadcast.Interval = (minutes_to_send * 60 * 1000);
Broadcast.Start();
*Where arguments is whatever you want to pass to the method.
03/06/2010 16:16 Paralyzer[GM]#14
Ok then well is there a way to like make it repeat it self ever 2 hours so like i dono sleep == Hours);

so an event can auto start every 2 hours ?
03/06/2010 16:27 Nullable#15
Quote:
Originally Posted by Paralyzer[GM] View Post
Ok then well is there a way to like make it repeat it self ever 2 hours so like i dono sleep == Hours);

so an event can auto start every 2 hours ?
Using timers, this is really easy, all what you have to do is set the timer class member AutoReset to true;
like
Code:
Timer T = new Timer(2 HOURS VAL);
T.AutoReset = true;
T.Start();