SA-MP Forums Archive
SetTimerEx or GetTickCount() ? - 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)
+--- Thread: SetTimerEx or GetTickCount() ? (/showthread.php?tid=314605)



SetTimerEx or GetTickCount() ? - Richie - 30.01.2012

I have time limiters on some commands, 60 - 90seconds and some up to 5 minuttes.
Which is better to use?
GetTickCount to check time or SetTimerEx( "Function", 90000, 0, "i", playerid );


Re: SetTimerEx or GetTickCount() ? - Jochemd - 30.01.2012

Use SetTimerEx - you would need a timer if you use GetTickCount so that would be kind of doubled.


Re: SetTimerEx or GetTickCount() ? - MP2 - 30.01.2012

No. If you want to add a 1 minute anti-spam to a command, all you need to do is:

pawn Код:
if(GetTickCount()-pLimit[playerid] < 60000) return SendClientMessage(playerid, COLOR_RED, "Please wait before using this command again.");
pLimit[playerid] = GetTickCount();
// Command



Re: SetTimerEx or GetTickCount() ? - Richie - 30.01.2012

Im using GetTickCount like you made there MP2 in anti command/chat spam.
But for other limiters like /takedrugs i use SetTimerEx to make limit to 3 minuttes.
Which one are the most efficient? Want to know if its worth replacing SetTimerEx with GetTickCount.


Re: SetTimerEx or GetTickCount() ? - Vince - 30.01.2012

One option you forgot is gettime(). A tick is not necessarily 1 millisecond. gettime (without parameters) returns the current unix timestamp, in seconds.


Re: SetTimerEx or GetTickCount() ? - Roperr - 30.01.2012

Honestly, GetTickCount is the best way. In some cases you pretty much can't use and you need to set up a timer.


Re: SetTimerEx or GetTickCount() ? - jamesbond007 - 30.01.2012

doesnt really matter which one i use, does it ?


Re: SetTimerEx or GetTickCount() ? - Richie - 30.01.2012

Vince, can it be used like this?
pawn Код:
PlayerSpam[playerid] = GetTime();

stock IsPlayerSpamming(playerid)
{
    if(GetTime() - PlayerSpam[playerid] < 30000)
        return 1;

    return 0;
}
and is this better then the two other, in cases like this?


Re: SetTimerEx or GetTickCount() ? - Vince - 30.01.2012

Yes, you can use it like that, but be aware that the function name is written in all lowercase letters and that the function returns time in SECONDS, not milliseconds.


Re: SetTimerEx or GetTickCount() ? - Richie - 30.01.2012

Yeah, i found on that on wiki. integer that increment every second. So my time there was not good one.
And using gettime instead of timers is better, right? Instead of having a timer running, it just gets current time in unix t-stamp and we can compare.