how to get player total online time ?
#1

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.
Reply
#2

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.
Reply
#3

can u tell me how to do that ?
Reply
#4

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

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;
}
Reply
#6

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.
Reply
#7

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.
Reply
#8

thank you so much guys got it thanks again
Reply
#9

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)