27.11.2016, 12:21
I created a timer to know how long the player is connected to the server but gave it fail, it does not reset, if a player logs in now and stays 13 min, and I log in 1 hour, it will have the same time for both.
The code is this:
My goal is to show a player how long he is online, for example, for me that I just logged in, 10 seconds, and for another that is already logged in an hour ago, obviously 1 hour, but this is not happening ...
The time stays the same for everyone, regardless if it is already logged in, or will log in, help me, please ...
Sorry for my bad english :/
The code is this:
PHP код:
new Text:CMlt;
new horaslt[MAX_PLAYERS], minutoslt[MAX_PLAYERS], segundoslt[MAX_PLAYERS], timerlt[MAX_PLAYERS];
forward CreateCMlt();
public CreateCMlt()
{
CMlt = TextDrawCreate(498.000000, 125.000000, " ");
TextDrawBackgroundColor(CMlt, 255);
TextDrawFont(CMlt, 1);
TextDrawLetterSize(CMlt, 0.500000, 1.000000);
TextDrawColor(CMlt, -1);
TextDrawSetOutline(CMlt, 1);
TextDrawSetProportional(CMlt, 1);
return 1;
}
forward ccmlt(playerid);
public ccmlt(playerid)
{
segundoslt[playerid]++;
if(segundoslt[playerid] > 59)
{
segundoslt[playerid] = 0;
minutoslt[playerid] ++;
if(minutoslt[playerid] > 59)
{
minutoslt[playerid] = 0;
horaslt[playerid]++;
}
}
new ccmltstr[24];
format(ccmltstr, sizeof(ccmltstr), "%02d:%02d:%02d", horaslt, minutoslt, segundoslt);
TextDrawSetString(CMlt, ccmltstr);
return 1;
}
public OnPlayerConnect(playerid)
{
timerlt[playerid] = SetTimerEx("ccmlt", 1000, true, "d", playerid);
return 1;
}
public OnPlayerSpawn(playerid)
{
TextDrawShowForPlayer(playerid, CMlt);
return 1;
}
OnPlayerDisconnect(playerid)
{
KillTimer(timerlt[playerid]);
return 1;
}
The time stays the same for everyone, regardless if it is already logged in, or will log in, help me, please ...
Sorry for my bad english :/