Timer delay according to gettime()
#7

Quote:
Originally Posted by DOL4N
Посмотреть сообщение
It's working like that, MeCom. Thank you so much!
Rep++
The code he showed you is a) inefficient (no need for a 1s timer, 10min is enough) and b) only working for player 0.

Create a global array and a define:

Код:
#define REWARD_TIME 3600000 // ms, one hour
new tPlayerLogin[MAX_PLAYERS];
In OnPlayerConnect:

Код:
tPlayerLogin[playerid] = GetTickCount();
Set a 600 seconds timer which calls the following function. The timer only defines when the check is done, so it can be anything below one hour but should be around 5-10 minutes to give rewards on time.

Код:
forward PlayedTimer();
public PlayedTimer()
{
	new curTick = GetTickCount();
	
	for(new playerid = 0; playerid < GetMaxPlayers(); playerid ++) // Could be replaced by foreach
	{
		if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid)) continue;
		
		new timedif = curTick - tPlayerLogin[playerid];
		if(timedif > REWARD_TIME)
		{
			tPlayerLogin[playerid] += REWARD_TIME;

			// Code to do when he played another hour
		}
	}
}
This is an always precise reward timer, to make it exact throughout multiple logins save and load the difference between GetTickCount() and tPlayerLogin, then substract it from the GetTickCount() in OnPlayerConnect.
Reply


Messages In This Thread
Timer delay according to gettime() - by DOL4N - 02.03.2016, 20:19
Re: Timer delay according to gettime() - by Vince - 02.03.2016, 20:41
Re: Timer delay according to gettime() - by DOL4N - 02.03.2016, 20:56
Re: Timer delay according to gettime() - by xEF - 02.03.2016, 21:00
Re: Timer delay according to gettime() - by MeCom - 02.03.2016, 21:01
Re: Timer delay according to gettime() - by DOL4N - 02.03.2016, 21:34
Re: Timer delay according to gettime() - by NaS - 02.03.2016, 22:00

Forum Jump:


Users browsing this thread: 2 Guest(s)