06.07.2011, 14:56
Use this code as a timer (so set this as a timer in OnGameModeInit):
Then your function:
I haven't tested this, but most of it should work, if not it should be suitable as pseudo-code to work from.
pawn Code:
forward conTimeTimer();
public conTimeTimer() {
foreach(Player, x) {
SetPVarInt(x, "playerTime", GetPVarInt(x, "playerTime") + 1);
}
return 1;
}
pawn Code:
CMD:timespent(playerid, params[]) {
new
szMessage[64];
switch(GetPVarInt(playerid, "playerTime")) {
case 0..59: {
format(szMessage, sizeof(szMessage), "You have been online for: %d seconds.", GetPVarInt(playerid, "playerTime"));
}
case 60..3599: {
format(szMessage, sizeof(szMessage), "You have been online for: %d minutes.", GetPVarInt(playerid, "playerTime") / 60);
}
case 3600..86399: {
format(szMessage, sizeof(szMessage), "You have been online for: %d hours.", GetPVarInt(playerid, "playerTime") / 60);
}
case 86400..604800: {
format(szMessage, sizeof(szMessage), "You have been online for approximately %d days.", GetPVarInt(playerid, "playerTime") / 60 / 60 / 24);
}
}
SendClientMessage(playerid, 0, szMessage);
return 1;
}