Timer Bug?
#1

Hey!

I'm having weird timer bug.. I'm displaying countdown of 3 2 1 GO! with gametext etc..

Lets say all of them get displayed normally but for some reason there is 1 second gap between each number is shown.. so lets say it goes

3 (waits one second) 2 (waits one second) 1 (waits one second) GO!

And I dont want that.. I want it to go 3 2 1 GO without that one second gap.. but I cant seem to find issue in my code.. I'll post it here
PHP код:
Start_Map[DM] = SetTimerEx("StartMap"10001"d"DM); 
PHP код:
forward StartMap(mode);
public 
StartMap(mode)
{
    new 
string[128];
    switch(
mode)
    {
        case 
DM:
        {
            
Countdown[DM]--;
            for(new 
GetPlayerPoolSize(), 0<= j;  i++) if(IsPlayerConnected(i))
            {
                if(
pMode[i] == DM)
                {
                    if(
Countdown[DM] > )
                    {
                        
format(stringsizeof(string), "%d"Countdown[DM]);
                        
GameTextForPlayer(istring10004);
                    }
                    else
                    {
                        
GameTextForPlayer(i"Go!"10004);
                    
                        
KillTimer(Vehicle_Freeze[DM]);
                        
KillTimer(Start_Map[DM]);
                        
Countdown[DM] = 4;
                        
                        
TogglePlayerControllable(itrue);
                    }
                    
                }
            }
        }
    }
    return 
1;

EDIT: Here's GIF of how it goes.. As you can see there's 1 second gap between

https://gyazo.com/77b789188c91a1813c2c19cd9951a639
Reply
#2

Are you using any plugin or include related to timers? Are you running any code often which takes a lot of time to be executed? What OS are you running your server on?


Your code seems okay, I've tried to improve it a little bit tho. Feel free to take a look:
PHP код:
Start_Map[DM] = SetTimerEx("StartMap"1000true"d"DM);
forward StartMap(mode); 
public 
StartMap(mode

    
/*
        Two cells are okay for this array since the countdown
        displays just a character + EOS (for example 3 + \0).
        The EOS (\0) is used to close the string, and it takes one cell.
    */
    
new string[2];
    switch(
mode
    { 
        case 
DM
        { 
            
Countdown[DM]--;
            for(new 
0GetPlayerPoolSize(); <= ti++) 
            {
                
/*
                    This code skips the ID if the player is not
                    connected or if his pMode is not set to DM.
                */
                
if(!IsPlayerConnected(i) || pMode[i] != DM)
                {
                    continue;
                } 
                
/*
                    The code below is executed for connected
                    players who have pMode set to DM.
                */
                
if(Countdown[DM] > 0
                { 
                    
format(stringsizeof(string), "%d"Countdown[DM]);
                    
GameTextForPlayer(istring10004); 
                } 
                else 
                { 
                    
KillTimer(Vehicle_Freeze[DM]); 
                    
KillTimer(Start_Map[DM]); 
                      
Countdown[DM] = 4;
                    
GameTextForPlayer(i"Go!"10004); 
                    
TogglePlayerControllable(itrue); 
                }             
            } 
        } 
    } 
    return 
1

Reply
#3

Just increase game text time and it should be outside loop

pawn Код:
forward StartMap(mode);
public StartMap(mode)
{
    new string[4];
    switch(mode)
    {
        case DM:
        {
            if( --Countdown[DM] > 0 ) valstr(string, Countdown[DM]);
            else
            {
                string = "Go!";
                Countdown[DM] = 4;
                KillTimer(Vehicle_Freeze[DM]);
                KillTimer(Start_Map[DM]);
            }
            for(new i = GetPlayerPoolSize(); i > -1; i--)
                if(pMode[i] == DM && GameTextForPlayer(i, string, 2000, 4)) // mode == DM and player is connected
                {
                    if(Countdown[DM] == 4) // start
                        TogglePlayerControllable(i, true);
                }
        }
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by RIDE2DAY
Посмотреть сообщение
Are you using any plugin or include related to timers? Are you running any code often which takes a lot of time to be executed? What OS are you running your server on?


Your code seems okay, I've tried to improve it a little bit tho. Feel free to take a look:
PHP код:
Start_Map[DM] = SetTimerEx("StartMap"1000true"d"DM);
forward StartMap(mode); 
public 
StartMap(mode

    
/*
        Two cells are okay for this array since the countdown
        displays just a character + EOS (for example 3 + \0).
        The EOS (\0) is used to close the string, and it takes one cell.
    */
    
new string[2];
    switch(
mode
    { 
        case 
DM
        { 
            
Countdown[DM]--;
            for(new 
0GetPlayerPoolSize(); <= ti++) 
            {
                
/*
                    This code skips the ID if the player is not
                    connected or if his pMode is not set to DM.
                */
                
if(!IsPlayerConnected(i) || pMode[i] != DM)
                {
                    continue;
                } 
                
/*
                    The code below is executed for connected
                    players who have pMode set to DM.
                */
                
if(Countdown[DM] > 0
                { 
                    
format(stringsizeof(string), "%d"Countdown[DM]);
                    
GameTextForPlayer(istring10004); 
                } 
                else 
                { 
                    
KillTimer(Vehicle_Freeze[DM]); 
                    
KillTimer(Start_Map[DM]); 
                      
Countdown[DM] = 4;
                    
GameTextForPlayer(i"Go!"10004); 
                    
TogglePlayerControllable(itrue); 
                }             
            } 
        } 
    } 
    return 
1

I am not using any includes related to timer, but I am loading a map before the timer which is reading a file and creating dynamic objects + dynamic areas but I make sure that after its done reading I close the file and excecute timer after.. idk, might be issue but i dont know.
And I'm using Windows at the moment since its on localhost.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)