task GlobalTimer[1000]() { new H, M, S; gettime(H, M, S); foreach(new i: Player) { if(!PlayerInfo[i][IsLoggedIn]) continue; if(M == 0 && S == 0) { if(PlayerInfo[i][pConnectedTime] >= 25) { // If the player have at least 25 minutes played during the entire hour. PlayerInfo[i][pConnectedTime] = 0; } else { // If not SendErrorMessage } } else if(S == 0) { // Add +1 each minutes if(PlayerInfo[i][pConnectedTime] < 25) { ++PlayerInfo[i][pConnectedTime]; } } } return 1; }
Well so basically, there are some ways:
1. Use a global timer, like you do 2. Per player timers 3. OnPlayerUpdate I'd consider a global timer using foreach (like u do), that's just my opinion though |
stock getTickDiff(newTick, oldTick)
{
if (oldTick < 0 && newTick >= 0) {
return newTick - oldTick;
} else if (oldTick >= 0 && newTick < 0 || oldTick > newTick) {
return (cellmax - oldTick + 1) - (cellmin - newTick);
}
return newTick - oldTick;
}
4. check if the difference (in ms) is more or equal to 25 minutes (assuming u want the payday to hapen every 25 minutes) |
new connectTick[MAX_PLAYERS];
public OnGameModeInit()
{
SetTimer("paydaycheck", 3600000/*1 Hour*/, true);
}
public OnPlayerConnect(playerid)
{
connectTick[playerid] = GetTickCount();
}
forward paydaycheck();
public paydaycheck()
{
foreach(new player : Player)
{
new tickDifference = getTickDiff(GetTickCount(), connectTick[playerid]);
if(tickDifference >= 1500000/*25 Minutes*/)
{
PAYDAY();
}
}
}
stock getTickDiff(newTick, oldTick)
{
if (oldTick < 0 && newTick >= 0) {
return newTick - oldTick;
} else if (oldTick >= 0 && newTick < 0 || oldTick > newTick) {
return (cellmax - oldTick + 1) - (cellmin - newTick);
}
return newTick - oldTick;
}