Best way to make timers.
#1

Hi,

I just wanted to ask how is it better to make timers. I had this version in past:
pawn Code:
public OnGameModeInit()
{
    SetTimer("Timer1",200,1);
    SetTimer("Timer2",60000,1);
    SetTimer("Timer3",1000,1); //1 sec
    SetTimer("Timer4",3000,1);
    SetTimer("Timer5",1000,1); //1 sec
    SetTimer("Timer6",1000,1); //1 sec
}
But today i made something like this:
pawn Code:
public OnGameModeInit()
{
    SetTimer("Timer1",200,1);
    SetTimer("Timer2",60000,1);
    SetTimer("oneSecTimer",1000,1); //1 sec
    SetTimer("Timer4",3000,1);
}

oneSecTimer();
{
    Timer3();
    Timer5();
    Timer6();
}
Which one is better/causes less lags? And are there any other ways to make timers?

Thanks.
Reply
#2

I don't like to use many timers:

pawn Code:
new
  Second,
  Minute,
  Hour;
pawn Code:
public OnGameModeInit()
{
  SetTimer("OneSecondTimer", 1000, true);
  return 1;
}
pawn Code:
public OneSecondTimer()
{
  Second ++;

  if(Second == 60) // one minute
  {
    SendClientMessage(playerid, COLOR, "60 Seconds.");
    Minute ++;
    Second == 0;
  }
  else if(Minute == 60) // one hour
  {
    SendClientMessage(playerid, COLOR, "60 Minutes.");
    Hour ++;
    Minute == 0;  
  }
  return 1;
}
Just remember if you want things to happen only once, reset the variables:

pawn Code:
Variable == 0;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)