/advtimer

Re: /advtimer

Postby ismellike » 15 Jul 2013, 20:43

It would be better if you made it with the actual timer class.
Here is an example

Code: Select all
using System.Timers;

int seconds;
Timer timer = new Timer(1000); //1 second
public override void Init()
{
    timer.Elapsed+=new ElapsedEventHandler(elapsed);
}
void elapsed(object sender, ElapsedEventArgs e)
{
   seconds-=1;
   Player.GlobalMessage(seconds.ToString());
}
public override void Use(Player p, string message)
{
   string[] split = message.Trim().Split(' ');
  switch(split[0])
    {
          case "start":
         if(!timer.Enabled)
             timer.Start();
        break;
       case "stop":
          if(timer.Enabled)
             timer.Stop();
          break;
       default:
            Help(p);
         break;
    }
}
public override void Help(Player p)
{
   Player.SendMessage(p,"hi");
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /advtimer

Postby HETAL » 15 Jul 2013, 20:48

/advtimer goes up to 1000 seconds so I would have like 10000 lines if I used the timer class
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: /advtimer

Postby ismellike » 15 Jul 2013, 20:56

Not really, you would have a similar amount of lines as I demonstrated in my example.

I forgot a few things though, like

Code: Select all
if(seconds==0)
{
timer.Stop();
}


Code: Select all
case "start":
   if(!timer.Enabled){
  seconds=Convert.ToInt32(split[1]);
timer.Start();
}
break;
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /advtimer

Postby Clowny » 15 Jul 2013, 21:00

There should be a way to abort it.. surprised you don't know
Founder Of MC Classic Hosting Community http://mcclassichosting.webs.com
Founder of MC Classic Software MCReborn http://mcreborn.tk
Professional Hoster and Basic C# Coder
Image
User avatar
Clowny
 
Posts: 112
Joined: 14 Jul 2013, 03:53

Re: /advtimer

Postby ismellike » 15 Jul 2013, 21:28

There is a way to abort it.
You can make a bool enabled = false; outside of the use method, and then inside of the for loop you would just put if(enabled){ }...

So to stop it you would just do enabled=false;.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Previous

Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron