SA-MP Forums Archive
Timer is bugged - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Timer is bugged (/showthread.php?tid=265124)



Timer is bugged - BizzyD - 29.06.2011

Hello, I got a problem with my timers, I am using progress bars, When you are more players online, The hunger & drink bar gets bigger alot quicker. For some reason. This is my timers:

Код:
new hungertimer[MAX_PLAYERS];
new thirsttimer[MAX_PLAYERS];
forward hunger(playerid);
forward thirsty(playerid);
OnPlayerSpawn
pawn Код:
hungertimer[playerid] = SetTimerEx("hunger", 1200000, false, "i", playerid);
thirsttimer[playerid] = SetTimerEx("thirsty", 1200000, false, "i", playerid);
pawn Код:
public hunger(playerid)
{
    Hungry[playerid] += 1;
    hungertimer[playerid] = SetTimerEx("hunger", 1200000, false, "i", playerid);
    return 1;
}
public thirsty(playerid)
{
    Thirsty[playerid] += 1;
    thirsttimer[playerid] = SetTimerEx("thirsty", 1200000, false, "i", playerid);
    return 1;
}
Anyone knows the problem?


AW: Timer is bugged - Blowfish - 29.06.2011

Do you kill the timers when a player disconnects?


Re: Timer is bugged - BizzyD - 29.06.2011

No, i dont


AW: Timer is bugged - Blowfish - 29.06.2011

Well, that's your problem.
Put this into OnPlayerDisconnect:
PHP код:
KillTimer(hungertimer[playerid]);
KillTimer(thirsttimer[playerid]); 
By the way: A better solution would be to use only one timer
and loop through all the players.


Re: Timer is bugged - BizzyD - 29.06.2011

I just added that

But do you mean like:
Код:
hungertimer[playerid] = SetTimerEx("hunger", 1200000, true,//Added true "i", playerid);
Like that?


AW: Timer is bugged - Blowfish - 29.06.2011

This is what I meant:
PHP код:
forward hungerTimer();
public 
OnGameModeInit() {
        
SetTimer("hungerTimer"1200001);
        return 
0;
}
public 
hungerTimer() {
        for(new 
iMAX_PLAYERSi++) {
                if(
IsPlayerConnected(i)) {
                        
Thirsty[i]++;
                        
Hungry[i]++;
                }
        }
        return 
0;




Re: Timer is bugged - Sasino97 - 29.06.2011

Quote:
Originally Posted by AlexzzPro
Посмотреть сообщение
Hello, I got a problem with my timers, I am using progress bars, When you are more players online, The hunger & drink bar gets bigger alot quicker. For some reason. This is my timers:

Код:
new hungertimer[MAX_PLAYERS];
new thirsttimer[MAX_PLAYERS];
forward hunger(playerid);
forward thirsty(playerid);
OnPlayerSpawn
pawn Код:
hungertimer[playerid] = SetTimerEx("hunger", 1200000, false, "i", playerid);
thirsttimer[playerid] = SetTimerEx("thirsty", 1200000, false, "i", playerid);
pawn Код:
public hunger(playerid)
{
    Hungry[playerid] += 1;
    hungertimer[playerid] = SetTimerEx("hunger", 1200000, false, "i", playerid);
    return 1;
}
public thirsty(playerid)
{
    Thirsty[playerid] += 1;
    thirsttimer[playerid] = SetTimerEx("thirsty", 1200000, false, "i", playerid);
    return 1;
}
Anyone knows the problem?
I know this isn't the problem, but it'll be more fast and flexible:

pawn Код:
hungertimer[playerid] = SetTimerEx("hunger", 1200000, true, "i", playerid);
thirsttimer[playerid] = SetTimerEx("thirsty", 1200000, true, "i", playerid);
pawn Код:
public hunger(playerid)
{
    Hungry[playerid] += 1;
    return 1;
}
public thirsty(playerid)
{
    Thirsty[playerid] += 1;
    return 1;
}



Re: AW: Timer is bugged - BizzyD - 29.06.2011

Quote:
Originally Posted by Blowfish
Посмотреть сообщение
This is what I meant:
PHP код:
forward hungerTimer();
public 
OnGameModeInit() {
        
SetTimer("hungerTimer"1200001);
        return 
0;
}
public 
hungerTimer() {
        for(new 
iMAX_PLAYERSi++) {
                if(
IsPlayerConnected(i)) {
                        
Thirsty[i]++;
                        
Hungry[i]++;
                }
        }
        return 
0;

I will try that, But then i deleted killtimer from OnplayerDisconnect


AW: Timer is bugged - Blowfish - 29.06.2011

Yes, when you're using this you won't need the KillTimer thingy anymore.


Re: Timer is bugged - BizzyD - 29.06.2011

Thank you! I will try it