17.08.2011, 18:19
how can i make every 2 hours player gets a score?
new hour, minute, second, starts[MAX_PLAYERS][3];
printf("2-hours score has started for %d. The time currently is %02d:%02d:%02d", hour, minute, second);
starts[playerid][0] = hour;
starts[playerid][1] = minute;
starts[playerid][2] = second;
new hour, minute, second;
getTime(hour, minute, second));
if(hour == starts[playerid][0]+2 && minute == starts[playerid][1] && second = starts[playerid][2])
{
/* EXPLANATION FOR ABOVE
Since you want it only 2 hours. You don't need to edit the minutes or seconds because you want it once 2 hours
It just checks if the player since he connected is 2 hours long on the server
*/
SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
printf("Player %d has received an extra score for being online on the server for 2 hours. Time is %02d:%02d:%02d", getTime(hour, minute, second));
}
starts[playerid][0] = 0;
starts[playerid][1] = 0;
starts[playerid][2] = 0;
forward OnlineTimeUpdate(playerid);
public OnlineTimeUpdate(playerid)
{
PlayerData[playerid][MinutesPlayed] ++;
if(PlayerData[playerid][MinutesPlayed] == 60)
{
PlayerData[playerid][HoursPlayed] ++;
PlayerData[playerid][MinutesPlayed] = 0;
}
return 1;
}
new Timer[MAX_PLAYERS]
public OnPlayerConnect(playerid)
{
Timer[playerid] = SetTimerEx("OnlineTimeUpdate",216000000,1,"%d",playerid);
return 1;
}
public OnPlayerDisconnect(playeridmreason)
{
KillTimer(Timer[playerid]);
return 1;
}
forward OnlineTimeUpdate(playerid);
public OnlineTimeUpdate(playerid)
{
SetPlayerScore(playerid,GetPlayerScore(playerid)++);
return 1;
}