SA-MP Forums Archive
how to get player total online time ? - 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 to get player total online time ? (/showthread.php?tid=515258)



how to get player total online time ? - Vaishnav - 25.05.2014

hi guys my problem is I want to get the player total online time MySQL and I searched for some tutorials etc but can't get it pls someone help.


Re: how to get player total online time ? - Ciandlah - 25.05.2014

If you want to get a player's total online you need to create a variable that every minute they are online or hour they are online +1 gets added to that variable, so when they type /stats or something it shows the online time.


Re: how to get player total online time ? - Vaishnav - 25.05.2014

can u tell me how to do that ?


Re: how to get player total online time ? - Ciandlah - 25.05.2014

Have you atleast attempted to make a peice of code for it? This section is scripting help, not scripting create


Re: how to get player total online time ? - BroZeus - 25.05.2014

pawn Код:
Mins[MAX_PLAYERS],MinTimer[MAX_PLAYERS];//on top under includes


forward IncreaseMin(playerid);
public IncreaseMin(playerid)
{
Mins[playerid]++;
return 1;
}


OnPlayerDisconnect(playerid, reason)
{
//save variable Min[playerid] in player file
Min[playerid]=0;
KillTimer(MinTimer[playerid]);
return 1;
}

OnPlayerConnect(playerid)
{
//load the total min online from file and store in Min[playerid]
MinTimer[playerid]=SetTimerEx("IncreaseMin",1000*60,true,"i",playerid);
return 1;
}



Re: how to get player total online time ? - Konstantinos - 25.05.2014

You don't need a timer for that! By using gettime function (without parameters) and storing the unix timestamp on connect, you can get the seconds the player is online by subtracting the unix timestamp from the current gettime with the one you stored on connect. You can then convert seconds to hours, minutes or whatever you want.


Re: how to get player total online time ? - ball - 25.05.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You don't need a timer for that! By using gettime function (without parameters) and storing the unix timestamp on connect, you can get the seconds the player is online by subtracting the unix timestamp from the current gettime with the one you stored on connect. You can then convert seconds to hours, minutes or whatever you want.
With timer you can count player time without afk time, there is better solution to get player time on the server - function NetStats_GetConnectedTime

Код:
new __time = NetStats_GetConnectedTime(playerid) / 1000; //player time on the server in seconds
//here you can save this time
But if you want count player time without afk time you have to create timer and global player variable.


Re: how to get player total online time ? - Vaishnav - 25.05.2014

thank you so much guys got it thanks again


Re: how to get player total online time ? - Konstantinos - 25.05.2014

Quote:
Originally Posted by ball
Посмотреть сообщение
With timer you can count player time without afk time, there is better solution to get player time on the server - function NetStats_GetConnectedTime

Код:
new __time = NetStats_GetConnectedTime(playerid) / 1000; //player time on the server in seconds
//here you can save this time
But if you want count player time without afk time you have to create timer and global player variable.
You can do the same thing for how many seconds the player is afk and subtract it from the original one.

By the way if I remember correctly, the function NetStats_GetConnectedTime does not work in OnPlayerDisconnect callback that's why I suggested unix timestamp.

Avoid timers as much as you can!