Timer doesn't work properly
#1

Hello, i have a little problem with timer.

I have timer that is counting points for pay on server. You need 60 points to get pay. For every min on server you get 1 point, and so on. Common pay system. Recently for no reason my timer started bugging. It worked all allright and suddenly. On some players it works and after some time it stops working, but mostly it doesn't work. It works fine 1-2 hours after server restart and then it starts bugging.

This is code that i'm using in function
Код:
public OnPlayerConnect(playerd)
Код:
PlataTimer[playerid] = SetTimerEx("TimerZaPlatu", 60000,true, "i", playerid);
This is code that i'm using in function
Код:
public OnPlayerDisconnect(playerid)
Код:
KillTimer(PlataTimer[playerid]);
And this is timer function code

Код:
forward TimerZaPlatu(playerid);
public TimerZaPlatu(playerid)
{
    new sat, minut, sekund, godina, mesec, dan;
	gettime(sat, minut, sekund);
	getdate(godina, mesec, dan);
	new szString[64], ime[MAX_PLAYER_NAME];
	RPIme(playerid, ime);
	PI[playerid][PayDayPoeni]++;
	if(PI[playerid][PayDayPoeni] == 50)
	{
		if(PI[playerid][Banka] < 0){
			format(szString, sizeof(szString), "| {1E90FF}Nova Banka{ffffff} | Stanje na vasem racunu je u minusu $%d, vratite dug kako ne biste bili kaznjeni.",PI[playerid][Banka]);
			SCM(playerid, -1, szString);
		}
	}
    if(PI[playerid][PayDayPoeni] >= 60){
		PayDay(playerid);
		PI[playerid][PayDayPoeni] = 0;
		hDobioPay[playerid] = 0;
		format(szString, sizeof(szString), "%s je dobio platu. Vreme: %d sati, %d min, %d sec",ime,sat,minut,sekund);
		UpisiLog(FAJL_PDDEBUGLOG, szString);
	}
	return 1;
}
How do i fix this? Any suggestions, advices... anything would be helpful.
Reply
#2

I'am suggestion to make a global timer.

pawn Код:
OnGameModeInit() {
    SetTimer("CheckMinute", 60000, true);
    return 1;
}

forward CheckMinute(); public CheckMinute() {
    foreach(new i: Players) { // you can use a loop it's just for more optimisation  

        new sat, minut, sekund, godina, mesec, dan;
    gettime(sat, minut, sekund);
    getdate(godina, mesec, dan);
    new szString[64], ime[MAX_PLAYER_NAME];
    RPIme(playerid, ime);
    PI[playerid][PayDayPoeni]++;
    if(PI[playerid][PayDayPoeni] == 50)
    {
        if(PI[playerid][Banka] < 0){
            format(szString, sizeof(szString), "| {1E90FF}Nova Banka{ffffff} | Stanje na vasem racunu je u minusu $%d, vratite dug kako ne biste bili kaznjeni.",PI[playerid][Banka]);
            SCM(playerid, -1, szString);
        }
    }
        if(PI[playerid][PayDayPoeni] >= 60){
        PayDay(playerid);
        PI[playerid][PayDayPoeni] = 0;
        hDobioPay[playerid] = 0;
        format(szString, sizeof(szString), "%s je dobio platu. Vreme: %d sati, %d min, %d sec",ime,sat,minut,sekund);
        UpisiLog(FAJL_PDDEBUGLOG, szString);
    }
    }
    return 1;
}
Reply
#3

I assumed first them when i got probel that global was answer, but nah. Still same problem even after global.
Reply
#4

Use Crashdetect plugin, I put my vote on PayDay(playerid); function, there is something which doesnt let script to be executed, usually its caused by accessing invalid indexes, like new Thing[10]; and then you use Thing[11] = 1; for example.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)