SA-MP Forums Archive
How save played Time (Y_INI) - 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)
+--- Thread: How save played Time (Y_INI) (/showthread.php?tid=284740)



How save played Time (Y_INI) - Bartando - 20.09.2011

hello i have two qwestion
how can i save player played timer?
and how can i load it?

I Using Y_INI


Re: How save played Time (Y_INI) - Hiddos - 20.09.2011

Basically, you start counting the playing time for a user when he joins the game and stop counting it when he disconnects:
pawn Code:
new PlayingTime[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
  PlayingTime[playerid] = GetTickCount(); //To store when the player connected
  return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  PlayingTime[playerid] = GetTickCount() - PlayingTime[playerid]; // Here we get the difference between when the player joined the game and left the game
  return 1;
}
This way you'll know exactly how much milliseconds a player was in-game. All you gotta do is save this information when the player disconnects, and of course make a new variable which stores the complete playing time (which will be loaded when the player logs in).


Re: How save played Time (Y_INI) - park4bmx - 20.09.2011

i have a timer witch is saves & loads with Y_INI in my register system u can take a look
but here is an example
pawn Code:
//firs Start a timer that runs every 1 seconds then ito the callback

//start the timer
SetTimerEx("TimeOnServer", 1000, 1, "i", playerid);

forward TimeOnServer(playerid);
public TimeOnServer(playerid)
{
PlayerInfo[playerid][Sec] ++;
if(PlayerInfo[playerid][Sec]>=60)
    {
        PlayerInfo[playerid][Min]++;
        PlayerInfo[playerid][Sec]=0;
    }
if(PlayerInfo[playerid][Min]>=60)
    {
        PlayerInfo[playerid][Min]=0;
        PlayerInfo[playerid][Hour]++;
    }
}
//and that's all you need to have a timer with [hours,mins,sec]

//This is to save it
INI_WriteInt(Acc,"Min",PlayerInfo[playerid][Min]);
INI_WriteInt(Acc,"Hour",PlayerInfo[playerid][Hour]);
INI_WriteInt(Acc,"Sec",PlayerInfo[playerid][Sec]);

//To load it
PlayerInfo[playerid][Min] = GetPVarInt(playerid, "Min");
PlayerInfo[playerid][Hour] = GetPVarInt(playerid, "Hour");
PlayerInfo[playerid][Sec] = GetPVarInt(playerid, "Sec");



Re: How save played Time (Y_INI) - Bartando - 20.09.2011

Yes thank to you


Re: How save played Time (Y_INI) - danish007 - 09.05.2014

Quote:

SetTimerEx("TimeOnServer", 1000, 1, "i", playerid);

Where To put This,


Re: How save played Time (Y_INI) - Konstantinos - 09.05.2014

I wouldn't recommend using timers at all for such as things. Unix timestamps is the best way but I'd use gettime() instead of GetTickCount function and then you can convert seconds to days/hours/minutes/seconds or whatever you want.


Re: How save played Time (Y_INI) - fuckingcruse - 14.04.2015

Not working