Time Spent In Game
#1

Hello All.
I Figured One Thing,I Think This Is Possible But I Don't Know How To Do It.
I want to do command which show player time spent in server and do code which save player spent time and then he use command:
Code:
COMMAND:spenttime(playerid,params[])
{
///Spent Time Code
///
new time [80] ;
format( time , 80 , " You Spent Time In This Server:  %s " , //TIME CODE//);
return 1;
}
Something Like This This Is Just Command I Know How To Make Command But Don't Know How To Make Script Which Show What Of The Time Player Spent In Server If Possible Would Be And Days. :S
Sorry If In The Text Are Fouls Because I'am tired and I Learning English.
If Someone Can Help Please Help Thanks In Advice..
Reply
#2

Use this code as a timer (so set this as a timer in OnGameModeInit):

pawn Code:
forward conTimeTimer();
public conTimeTimer() {
    foreach(Player, x) {
        SetPVarInt(x, "playerTime", GetPVarInt(x, "playerTime") + 1);
    }
    return 1;
}
Then your function:
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;
}
I haven't tested this, but most of it should work, if not it should be suitable as pseudo-code to work from.
Reply
#3

Thanks For Help
Reply
#4

I get 2 errors maybe can you help fix it ?

Code:
error 017: undefined symbol "foreach"
error 017: undefined symbol "x"
Reply
#5

you need "foreach" include
Reply
#6

I Have It
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)