Timer Help -
Luke_James - 17.08.2015
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(playerid, 30.0, COLOR_PURPLE, "MESSAGE 1", ReturnName(playerid, 0));
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 2", ReturnName(playerid, 0));
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 3", ReturnName(playerid, 0));
before carrying out it's function. How could I have a delay between those three messages of say 5 seconds?
Re: Timer Help -
ZBits - 17.08.2015
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.
Re: Timer Help -
Luke_James - 17.08.2015
Should this work?
PHP код:
forward Delay1(playerid);
public Delay1(playerid)
{
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 2", ReturnName(playerid, 0));
return 1;
}
forward Delay2(playerid);
public Delay2(playerid)
{
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 3", ReturnName(playerid, 0));
return 1;
}
PHP код:
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 1", ReturnName(playerid, 0));
SetTimerEx("Delay1", 10000, false, "i", playerid);
SetTimerEx("Delay2", 10000, false, "i", playerid);
Re: Timer Help -
Beckett - 17.08.2015
PHP код:
forward Delay1(playerid);
public Delay1(playerid)
{
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 2", ReturnName(playerid, 0));
SetTimerEx("Delay2", 10000, false, "i", playerid);
return 1;
}
forward Delay2(playerid);
public Delay2(playerid)
{
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 3", ReturnName(playerid, 0));
return 1;
}
PHP код:
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 1", ReturnName(playerid, 0));
SetTimerEx("Delay1", 10000, false, "i", playerid);
That ^ will send message one, wait 10 seconds, send the second one then wait another 10 seconds to send the last message.
Re: Timer Help -
Dokins - 17.08.2015
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.
Re: Timer Help -
Luke_James - 17.08.2015
Quote:
Originally Posted by DaniceMcHarley
PHP код:
forward Delay1(playerid);
public Delay1(playerid)
{
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 2", ReturnName(playerid, 0));
SetTimerEx("Delay2", 10000, false, "i", playerid);
return 1;
}
forward Delay2(playerid);
public Delay2(playerid)
{
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 3", ReturnName(playerid, 0));
return 1;
}
PHP код:
SendNearbyMessage(playerid, 30.0, COLOR_PURPLE, "MESSAGE 1", ReturnName(playerid, 0));
SetTimerEx("Delay1", 10000, false, "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!