is this ok to use settimerex ?
#1

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
Reply
#2

whats the timer about? i mean what it does?
Reply
#3

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
Reply
#4

EDIT: Too late. Vince has explained you clear enough how to achieve the same without looping every 1 second.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)