13.07.2013, 11:25
when I type /stats to see the total online time it actually shows wrong
It changes too fast.
How to solve this?
It changes too fast.
How to solve this?
public OnPlayerSpawn(playerid)
{
SetPlayerCheckpoint(playerid, BANK_X, BANK_Y, BANK_Z, 3.0);
zoneupdates[playerid] = 1;
player_zone[playerid] = -1;
if(!zoneupdate) zoneupdate = SetTimer("update_zones",1000,4);
SetTimerEx("GameTime",1000,1,"i",playerid); // Player Total Online Time
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.");
new ReturnName[MAX_PLAYER_NAME];
GetPlayerName(id, ReturnName, sizeof(ReturnName));
new Float:ratio=floatdiv(PlayerInfo[id][Kills], PlayerInfo[id][Deaths]);
format(szString, 256, "%d %d %.2f", PlayerInfo[id][Kills], PlayerInfo[id][Deaths], ratio);
format(szString, sizeof(szString), "* Player stats for %s (ID:%d)", ReturnName, id);
SendClientMessage(playerid, COLOR_YELLOW, szString);
format(szString, sizeof(szString), "* Admin Level > %d | VIP Level > %d | Kills > %d | Deaths > %d | (K/D): %.2f", PlayerInfo[id][AdminLevel], PlayerInfo[id][VIPLevel], PlayerInfo[id][Kills], PlayerInfo[id][Deaths], ratio);
SendClientMessage(playerid, COLOR_YELLOW, szString);
format(szString, sizeof(szString), "* Score > %d | Cookies > %d | Reaction Wins > %d", PlayerInfo[id][Score], PlayerInfo[id][Cookies], PlayerInfo[id][ReactionWins]);
SendClientMessage(playerid, COLOR_YELLOW, szString);
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;
}
public GameTime(playerid) {
PlayerInfo[playerid][Seconds]++;
if(PlayerInfo[playerid][Seconds] == 60) {
PlayerInfo[playerid][Minutes]++;
PlayerInfo[playerid][Seconds] = 0;
}
if(PlayerInfo[playerid][Minutes] == 60) {
PlayerInfo[playerid][Hours]++;
PlayerInfo[playerid][Minutes] = 0;
PlayerInfo[playerid][Seconds] = 0;
}
return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
PlayerInfo[playerid][Hours] = 0;
PlayerInfo[playerid][Minutes] = 0;
PlayerInfo[playerid][Seconds] = 0;
return 1;
}
Your code seems to be correct. Are you setting all the variables to 0 when the player disconnects (just in case a new player connects with the same ID)? I mean:
pawn Код:
|