SA-MP Forums Archive
Timer isn't working - 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)
+--- Thread: Timer isn't working (/showthread.php?tid=617399)



Timer isn't working - mongi - 20.09.2016

This are the codes

the problem is that the timer don't start :/

PHP код:
new ending
PHP код:
public OnGameModeInit()
{
    
    for (new 
id 0id MAX_PLAYERS;id++)
    {
        if(
IsPlayerConnected(id))
        {
         
SetTimerEx("Unfreeze"120000false"i"id);
        }
    }

PHP код:
forward Unfreeze(id);
public 
Unfreeze(id)
{
    
SendClientMessage(idCOLOR_PEACH"Test message");
     if(
spawn[id] == 1)
     {
        
TogglePlayerControllable(id1);
        
SendClientMessage(idCOLOR_PEACH"The race has been started! Go!");
    }
    
ending SetTimer("Next"180000false);
    return 
1;
}
forward Next();
public 
Next()
{
    
SendRconCommand("changemode Proj");
    return 
1;

i think every thing is fine, any help?


Re: Timer isn't working - ranme15 - 20.09.2016

You've put the timer at OnGameModeInit() which is being called exactly when the server loads up, which means there are no players online yet. You gotta put it in the start of the race. (as much as I see, you are building a race)


Re: Timer isn't working - mongi - 20.09.2016

Quote:
Originally Posted by ranme15
Посмотреть сообщение
You've put the timer at OnGameModeInit() which is being called exactly when the server loads up, which means there are no players online yet. You gotta put it in the start of the race. (as much as I see, you are building a race)
i was using this code:

PHP код:
SetTimer("Unfreeze"120000false); 
and the same thing, the timer didn't work. also the race will start when the timer end


Edit: the function "Unfreeze" will be called after 2 mns, and when i join the server, nothing happen
so the problem is the timer don't start at the 1st time


Re: Timer isn't working - Dragony92 - 20.09.2016

You are doing it in wrong way, first you are starting timers under OnGameModeInit for every connected player (if(IsPlayerConnected(id))), at that point noone is connected.
SetTimer("Unfreeze", 120000, false);
False means don't reapeat action, do it just one time.


Re: Timer isn't working - mongi - 20.09.2016

Quote:
Originally Posted by Dragony92
Посмотреть сообщение
You are doing it in wrong way, first you are starting timers under OnGameModeInit for every connected player (if(IsPlayerConnected(id))), at that point noone is connected.
SetTimer("Unfreeze", 120000, false);
False means don't reapeat action, do it just one time.
i already said

Quote:
Originally Posted by mongi
Посмотреть сообщение
i was using this code:

PHP код:
SetTimer("Unfreeze"120000false); 
and the same thing, the timer didn't work. also the race will start when the timer end


Edit: the function "Unfreeze" will be called after 2 mns, and when i join the server, nothing happen
so the problem is the timer don't start at the 1st time



Re: Timer isn't working - oMa37 - 20.09.2016

You are not listening to what they said!
You are making a loop through the online players OnGameModeInit(), And this callback get called ONLY when you start the server!
You have to remove the loop and make the timer repeating and make the loop inside the timer.


Re: Timer isn't working - mongi - 20.09.2016

PHP код:
new ending
PHP код:
public OnGameModeInit()
{
    
SetTimer("Unfreeze"120000false); //After 2mns, "Unfreeze" will be called to unfreeze the online players
    
return 1;

PHP код:
forward Unfreeze();
public 
Unfreeze()
{
    for(new 
id=0;id<MAX_PLAYERS;id++)
    {
        
SendClientMessage(idCOLOR_PEACH"Test message");
         if(
spawn[id] == 1)
         {
            
TogglePlayerControllable(id1);
            
SendClientMessage(idCOLOR_PEACH"The race has been started! Go!");
        }
    }
    
ending SetTimer("Next"180000false);
    return 
1;
}
forward Next();
public 
Next()
{
    
SendRconCommand("changemode Proj");
    return 
1;




Re: Timer isn't working - oMa37 - 20.09.2016

I don't know ahat are you trying to do with this code, But it won't work for the players who join after 2 minutes of the server start.


Re: Timer isn't working - mongi - 21.09.2016

Quote:
Originally Posted by oMa37
Посмотреть сообщение
I don't know ahat are you trying to do with this code, But it won't work for the players who join after 2 minutes of the server start.
i already know this, and after 2 mns players won't be able to spawn b/c the race already started (i didn't finish the "unfreeze" function yet)

and the players who join before the 2mns, will be in cars and forzen, this function will unfreeze them.