Timer is bugged
#1

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?
Reply
#2

Do you kill the timers when a player disconnects?
Reply
#3

No, i dont
Reply
#4

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.
Reply
#5

I just added that

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

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;

Reply
#7

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;
}
Reply
#8

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
Reply
#9

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

Thank you! I will try it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)