SA-MP Forums Archive
Best way to make timers. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Best way to make timers. (/showthread.php?tid=119131)



Best way to make timers. - CaHbKo - 06.01.2010

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.


Re: Best way to make timers. - Miguel - 06.01.2010

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;