25.05.2014, 09:26
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.
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;
}
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.
|
new __time = NetStats_GetConnectedTime(playerid) / 1000; //player time on the server in seconds //here you can save this time
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 |