Need help with Online Time Counter
#1

Hey. I need help with Player Online Time Counter.
Im gonna use it on /stats
Код:
enum pInfo
{
	pOnline
}

new PlayerInfo[MAX_PLAYERS][pInfo];
So when player connects timer will start and every 1 hour he will get 1 hour to online time.
Im gonna use only hours. Thanks in advance. So timer should start when player connects and it should start again after every hour giving score to player.
Reply
#2

Hi, so I found this on my script, could be useful for you.
First you got this:
pawn Код:
enum pInfo
{
TotalTime,
hours,
mins,
secs,
ConnectTime
};
new PlayerInfo[MAX_PLAYERS][pInfo];

// now this
TotalGameTime(playerid, &h=0, &m=0, &s=0)
{
    PlayerInfo[playerid][TotalTime] = ( (gettime() - PlayerInfo[playerid][ConnectTime]) + (PlayerInfo[playerid][hours]*60*60) + (PlayerInfo[playerid][mins]*60) + (PlayerInfo[playerid][secs]) );

    h = floatround(PlayerInfo[playerid][TotalTime] / 3600, floatround_floor);
    m = floatround(PlayerInfo[playerid][TotalTime] / 60,   floatround_floor) % 60;
    s = floatround(PlayerInfo[playerid][TotalTime] % 60,   floatround_floor);

    return PlayerInfo[playerid][TotalTime];
}
Now when you want to see the total game time(example, in /stats), use the following:
pawn Код:
TotalGameTime(playerid, h, m, s);
//now to preview it:
format(string, sizeof(string), "Total Time: %d hours %d minutes %d seconds", h, m, s);
SendClientMessage(playerid, -1, string);
Let's load it OnPlayerConnect:
pawn Код:
PlayerInfo[playerid][ConnectTime] = gettime();
I hope this is what you need!


Oh, also you need to save the time OnplayerDisconnect.
Reply
#3

EDIT: Problem solved.
I did it with this way.
Код:
SetTimer("OnlineTime",3600000,true);

forward OnlineTime(playerid);

public OnlineTime(playerid)
{
	PlayerInfo[playerid][pOnline]++;
	GivePlayerScore(playerid, 1);
	SendClientMessage(playerid, COLOR_WHITE,"TEST");
}
Its very simple but it works.
Reply
#4

Yea, can be done both ways.
Reply
#5

Can you help me with the OnPlayerDisconnect ?
Everything ok, my srv loads the Hrs ,Mins and Secs but when i disconnect it doesn't remember my added secs mins and hrs ? Pls Help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)