Total time online?
#1

Can somone show me an EXAMPLE, Not the whole thing, just an EXAMPLE Of how i would go about making a function to Save, Then Get, There total time online?
Reply
#2

Make a function every minute or hour, then just bump up a variable which saves to a file. When you want to know how long the user has being playing for, just grab that variable from the file.
Reply
#3

But what if they log off before that hour that the cycle goes through, Or they log in right before it goes through...

meaning they either miss an hour, or Get an hour.. was looking for something a little more accurate
Reply
#4

Make it minutes then. I wouldn't care if it was a minute out.
Reply
#5

minutes is good enuf for me. Make it cycle once a minute, then round it off to nearest hour correct?
Reply
#6

Or you could just leave it as "You have played on this server for x minutes"
Reply
#7

This is how I did it:

On the top-

pawn Код:
new TimerOwner[MAX_PLAYERS];
forward TimeOnlineCount(playerid);
public OnPlayerDisconnect(playerid, reason)

pawn Код:
KillTimer(TimerOwner[playerid]);
public OnPlayerSpawn(playerid)

pawn Код:
//your code.
TimerOwner[playerid] = SetTimerEx("TimeOnlineCount", 60000, 1, "i", playerid); //I use minutes in this.
Anywhere-
pawn Код:
public TimeOnlineCount(playerid)
{
    File[playerid][TimeOnline]++; //Just replace this to whatever variable you use. Also, if you use an Admin System, add the variable "TimeOnline" or rename it, if you wish.
    return 1;
}
Reply
#8

For windows user

pawn Код:
//OnPlayerConnect
SetPVarInt(playerid, "CTime", GetTickCount());
pawn Код:
//OnPlayerDisconnect - save to file using dini
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof name);
dini_SetInt("Time.txt", name, (
  dini_GetInt("Time.txt", name) +
    floatround( ( ( GetTickCount() - GetPVarInt(playerid, "CTime") ) / 1000.0 ), floatround_floor)
  )
);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)