Leveling system based on time played
#1

I know that you have to use a player time variable and a time function for this to work, but what would be the code for this? I'm new at this, sorry.
Reply
#2

Well, to calculate time played, you need to get the time at which the player started playing.
pawn Код:
new TimeJoined[MAX_PLAYERS]; //This is used to store the time that each player joined.

public OnPlayerConnect(playerid) //Called when a player connects
{
    TimeJoined[playerid] = gettime(); //Will store a unix timestamp as the time that the player joined.
    return 1;
}
Now in order to calculate the time played in the current session, you just simply get the current time and take away the time in which they joined, giving you the total amount in seconds.

pawn Код:
CMD:timeplayed(playerid, params[])
{
    new fstr[50];
    format(fstr, sizeof(fstr), "You have been playing for %d seconds.", gettime() - TimeJoined[playerid]);
    SendClientMessage(playerid, -1, fstr);
    return 1;
}
Functions used to achieve this:
gettime
Explanation of Unix timestamps

If you wanted to get the TOTAL time that the player has been on the server, you need to save the time to their personal file, load it when they rejoin then add their session time on top of it.

EDIT: I guess I can attempt to make some sort of saving/loading system for you if you really need it...
Reply
#3

Thank you! But how do do have timeplayed equal experience?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)