Timer Help
#1

Hi,

Could anyone please explain to me how I could use a timer to have a delay between two lines of code being processed when a specific command is done?

For example, a command will send three /me commands on behalf of the player...

PHP код:
    SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 1"ReturnName(playerid0));
    
SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 2"ReturnName(playerid0));
    
SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 3"ReturnName(playerid0)); 
before carrying out it's function. How could I have a delay between those three messages of say 5 seconds?
Reply
#2

Send the first message first. Then create a function containing the second message and use SetTimeEx to call it after the first. Create another function and call it after the second.
Reply
#3

Should this work?

PHP код:

forward Delay1
(playerid);
public 
Delay1(playerid)
{
    
SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 2"ReturnName(playerid0));
    return 
1;
}
forward Delay2(playerid);
public 
Delay2(playerid)
{
    
SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 3"ReturnName(playerid0));
    return 
1;

PHP код:
    SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 1"ReturnName(playerid0));
    
SetTimerEx("Delay1"10000false"i"playerid);
    
SetTimerEx("Delay2"10000false"i"playerid); 
Reply
#4

PHP код:
forward Delay1(playerid); 
public 
Delay1(playerid

    
SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 2"ReturnName(playerid0));
    
SetTimerEx("Delay2"10000false"i"playerid); 
    return 
1

forward Delay2(playerid); 
public 
Delay2(playerid

    
SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 3"ReturnName(playerid0)); 
    return 
1

PHP код:
    SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 1"ReturnName(playerid0)); 
    
SetTimerEx("Delay1"10000false"i"playerid); 
That ^ will send message one, wait 10 seconds, send the second one then wait another 10 seconds to send the last message.
Reply
#5

A better way to do it would be to create the timer for example: 20 seconds. Do a check to see when it reaches 10 seconds and then send the next message, no need to create two timers to do the same job and you can make it repeat if necessary.

Like this:

pawn Код:
public Delay1(playerid)
{
    new time;
    time++;
    if(time == 10)
    {
        SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 1", ReturnName(playerid, 0));
    }
    if(time == 20)
    {
        SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 2", ReturnName(playerid, 0));
    }
    return 1;
}
You can do this as many times as you like and when you kill the timer 'time' is reset.
Reply
#6

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
PHP код:
forward Delay1(playerid); 
public 
Delay1(playerid

    
SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 2"ReturnName(playerid0));
    
SetTimerEx("Delay2"10000false"i"playerid); 
    return 
1

forward Delay2(playerid); 
public 
Delay2(playerid

    
SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 3"ReturnName(playerid0)); 
    return 
1

PHP код:
    SendNearbyMessage(playerid30.0COLOR_PURPLE"MESSAGE 1"ReturnName(playerid0)); 
    
SetTimerEx("Delay1"10000false"i"playerid); 
That ^ will send message one, wait 10 seconds, send the second one then wait another 10 seconds to send the last message.
Got it, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)