04.12.2011, 20:17
Well here's an example that might help you:
PlayerInfo Variable:
OnPlayerConnect or OnPlayerSpawn:
If you wanted to put it into a /stats command (ZCMD & sscanf):
pawn Код:
enum pInfo { //
Seconds,
Minutes,
Hours,
}
pawn Код:
new PlayerInfo[MAX_PLAYERS][pInfo];
pawn Код:
SetTimerEx("GameTime",1000,1,"i",playerid); // Player Total Online Time every one second, seconds = + 1
pawn Код:
forward GameTime(playerid);
public GameTime(playerid) {
PlayerInfo[playerid][Seconds]++; // When GameTime is being called, seconds are updated +1
if(PlayerInfo[playerid][Seconds] == 60) { // If the total seconds = 60
PlayerInfo[playerid][Minutes]++; // + 1 minute
PlayerInfo[playerid][Seconds] = 0; // reset seconds to 0
}
if(PlayerInfo[playerid][Minutes] == 60) { // If the total minutes = 60
PlayerInfo[playerid][Hours]++; // + 1 hour
PlayerInfo[playerid][Minutes] = 0; // reset minutes to 0
PlayerInfo[playerid][Seconds] = 0; // reset minutes to 0
}
return 1;
}
pawn Код:
CMD:stats(playerid, params[]) {
new id;
if(sscanf(params,"d",id)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /stats [id]");
if (!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected.");
format(szString, sizeof(szString), "* Total Online Time: %i hours, %i minutes, and %i seconds", PlayerInfo[id][Hours], PlayerInfo[id][Minutes], PlayerInfo[id][Seconds]);
SendClientMessage(playerid, COLOR_YELLOW, szString);
return 1;
}