is this ok to use settimerex ? - 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: is this ok to use settimerex ? (
/showthread.php?tid=564640)
is this ok to use settimerex ? -
joec39 - 22.02.2015
heyllo there
is this ok with above 20 players ? make no lag ?
Код:
new TotalCheck[MAX_PLAYERS]; // on top
TotalCheck[playerid] = SetTimerEx("CheckTime", 1000, 1, "i", playerid); /// this will create onplayerconnect
// this is somewhere
function CheckTime(playerid) the function will loop every 1 second
{
PlayerInfo[playerid][Sec] ++;
if(PlayerInfo[playerid][Sec]>=60)
{
PlayerInfo[playerid][Min]++;
PlayerInfo[playerid][Sec]=0;
}
if(PlayerInfo[playerid][Min]>=60)
{
PlayerInfo[playerid][Min]=0;
PlayerInfo[playerid][Hour]++;
}
// and many other codes
return 1;
}
KillTimer(TotalCheck[playerid]); // this will run onplayerdisconnect
Re: is this ok to use settimerex ? -
Ritzy2K - 22.02.2015
whats the timer about? i mean what it does?
Re: is this ok to use settimerex ? -
Vince - 22.02.2015
You don't even need a timer for this at all. Check out Unix timestamps. Tutorial somewhere in the tutorial section. You save a Unix timestamp when they login. When they disconnect you subtract the value you saved earlier from the current timestamp. This will give you a value in seconds which can easily be converted to hours and minutes when needed. Ergo, you don't need the 'Hour' and 'Min' variables either.
pawn Код:
stock sec_to_time(input_seconds, &hours, &minutes, &seconds)
{
hours = input_seconds / 3600; // int divided by int is int
input_seconds -= (hours * 3600);
minutes = input_seconds / 60;
input_seconds -= (minutes * 60);
seconds = input_seconds;
}
pawn Код:
// e.g.:
new
hours,
minutes,
seconds;
sec_to_time(4512, hours, minutes, seconds);
// hours = 1, minutes = 15, seconds = 12
Re: is this ok to use settimerex ? -
AndySedeyn - 22.02.2015
EDIT: Too late. Vince has explained you clear enough how to achieve the same without looping every 1 second.