SetTimerEx -
CroM256 - 13.03.2014
Hi,
I made system to count minutes, hours and days online for player, but I don't know is it lagg or what? First time timer late 5-10sec but on 5th time it late 1 minute.
I put this on player login/register
Код:
SetTimerEx("TimeOnServer", 60000, 1, "i", playerid);
and this is public for timer:
Код:
forward TimeOnServer(playerid);
public TimeOnServer(playerid)
{
PlayerInfo[playerid][pMin] ++;
if(PlayerInfo[playerid][pMin]>=60)
{
PlayerInfo[playerid][pHour]++;
PlayerInfo[playerid][pMin]=0;
if(PlayerInfo[playerid][pHour] < 60)
{
SendClientMessage(playerid, COLOR_GRAY, ""COL_YELLOW"[SERVER]: +1 Hour online! +5 Score and $5000");
sGivePlayerMoney(playerid, 5000);
PlayerInfo[playerid][pCash] += 5000;
SetPlayerScore(playerid, GetPlayerScore(playerid)+5);
PlayerInfo[playerid][pScore] += 5;
}
}
if(PlayerInfo[playerid][pHour]>=60)
{
PlayerInfo[playerid][pHour]=0;
PlayerInfo[playerid][pDay]++;
SendClientMessage(playerid, COLOR_GRAY, ""COL_YELLOW"[SERVER]: +1 Day online! +20 Score and $20000");
sGivePlayerMoney(playerid, 20000);
PlayerInfo[playerid][pCash] += 20000;
SetPlayerScore(playerid, GetPlayerScore(playerid)+20);
PlayerInfo[playerid][pScore] += 20;
}
}
Re: SetTimerEx -
Matess - 13.03.2014
Yeah there is delay. 60000 (60 samp seconds) != 60 real seconds
Re: SetTimerEx -
Ruben_Alonso - 13.03.2014
Do you even know that a day has 24 hours?
Re: SetTimerEx -
CroM256 - 13.03.2014
@Matess can i fix it?
@Ruben thank you for noticing xD, it was an old system from some other guy, it has hours,mins,and seconds so he set 60 sec for minute and 60 mins for hour...I have days/hours/mins and forgot to change it, don't think I'm stupid xD
AW: SetTimerEx -
Macronix - 13.03.2014
And I also wouldn't do it as SetTimerEx for a specific player. I would do a general timer, that does exactly the same as in your code but in a loop for all players
Otherwise you would start too much timers.
Re: SetTimerEx -
CroM256 - 13.03.2014
That is not good, with that system I can login 5 sec before that timer comes to 60 and get +1min
EDIT:Or maybe it is better, thank you for advice I will make it like you said.
Re: SetTimerEx -
Ruben_Alonso - 13.03.2014
Oh hahaha I didn't think it, i just wanted some drama! And you should not have any delay, how many timers do you have?
Re: SetTimerEx -
CroM256 - 13.03.2014
I don't understand you lol
Re: SetTimerEx -
Richie© - 13.03.2014
Why not use NetStats_GetConnectedTime which was introduced in 0.3z?
Its more accurate and you don't need 1 timer per player.
https://sampwiki.blast.hk/wiki/NetStats_GetConnectedTime
Re: SetTimerEx -
CroM256 - 13.03.2014
So how should it look like?
Код:
if(NetStats_GetConnectedTime(playerid) >= 60000)
{
PlayerInfo[playerid][pMin]++;
if(PlayerInfo[playerid][pMin]>=60)
{
PlayerInfo[playerid][pHour]++;
PlayerInfo[playerid][pMin]=0;
if(PlayerInfo[playerid][pHour] < 24)
{
SendClientMessage(playerid, COLOR_GRAY, ""COL_YELLOW"[SERVER]: +1 Hour online! +5 Score and $5000");
sGivePlayerMoney(playerid, 5000);
PlayerInfo[playerid][pCash] += 5000;
SetPlayerScore(playerid, GetPlayerScore(playerid)+5);
PlayerInfo[playerid][pScore] += 5;
}
if(PlayerInfo[playerid][pHour]>=24)
{
PlayerInfo[playerid][pHour]=0;
PlayerInfo[playerid][pDay]++;
SendClientMessage(playerid, COLOR_GRAY, ""COL_YELLOW"[SERVER]: +1 Day online! +20 Score and $20000");
sGivePlayerMoney(playerid, 20000);
PlayerInfo[playerid][pCash] += 20000;
SetPlayerScore(playerid, GetPlayerScore(playerid)+20);
PlayerInfo[playerid][pScore] += 20;
}
}
}
Something like this? It is not working on this way...because I can't set connected time on 0 so it will spam me every few seconds: +1hour...I put this on onplayerupdate