02.03.2016, 22:00
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:
In OnPlayerConnect:
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.
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.
Create a global array and a define:
Код:
#define REWARD_TIME 3600000 // ms, one hour new tPlayerLogin[MAX_PLAYERS];
Код:
tPlayerLogin[playerid] = GetTickCount();
Код:
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 } } }