SA-MP Forums Archive
Total time online? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Total time online? (/showthread.php?tid=166509)



Total time online? - DiddyBop - 08.08.2010

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?


Re: Total time online? - Conroy - 08.08.2010

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.


Re: Total time online? - DiddyBop - 08.08.2010

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


Re: Total time online? - Conroy - 08.08.2010

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


Re: Total time online? - DiddyBop - 08.08.2010

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


Re: Total time online? - Conroy - 09.08.2010

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


Re: Total time online? - (.Aztec); - 09.08.2010

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;
}



Re: Total time online? - Nero_3D - 09.08.2010

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)
  )
);