SA-MP Forums Archive
Pauses in a "LOOP" - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Pauses in a "LOOP" (/showthread.php?tid=206970)



Pauses in a "LOOP" - Dark734 - 05.01.2011

Hello,

Here's my code:
pawn Код:
public RandFire()
{
   
    for(new i = 0; i < 30000; i++)
    {
    CreateExplosion(-854.5049, 1538.4235, 22.5146, 2, 15);
    }
}
I want that the code waits like 5 seconds before doing another explosions. How is that possible?

Thank you,
-Alex


AW: Pauses in a "LOOP" - Meta - 05.01.2011

Create a Timer that gets called every 5 Seconds
SetTimer
SetTimerEx


Re: Pauses in a "LOOP" - Dark734 - 05.01.2011

I used a timer for RandFire.
But can you explain more about that, i don't understand how to implent a timer in that code

Thanks


Re: Pauses in a "LOOP" - Calgon - 05.01.2011

<retracted, read title incorrectly>


AW: Pauses in a "LOOP" - Meta - 05.01.2011

pawn Код:
forward ExplosionTimer();
public ExplosionTimer()
{
    CreateExplosion(-854.5049, 1538.4235, 22.5146, 2, 15);
}
Then use
pawn Код:
SetTimer("ExplosionTimer", 5000, 0);
to start the ExplosionTimer
If you want to kill it later, it's recommented to take a variable to store the Timer's ID in.
pawn Код:
new foo;
AnyFunction()
{
    foo = SetTimer("ExplosionTimer", 5000, 0);
}
...
//later to kill it
...
KillTimer(foo);



Re: Pauses in a "LOOP" - Dark734 - 05.01.2011

Yeah but explosions happens like a minigun! I don't want that, i want that the script waits 5 seconds before doing another explosions. I'm not a pro of PAWN coding, so please explain a bit.


Quote:
Originally Posted by Meta
Посмотреть сообщение
pawn Код:
forward ExplosionTimer();
public ExplosionTimer()
{
    CreateExplosion(-854.5049, 1538.4235, 22.5146, 2, 15);
}
Then use
pawn Код:
SetTimer("ExplosionTimer", 5000, 0);
to start the ExplosionTimer
If you want to kill it later, it's recommented to take a variable to store the Timer's ID in.
pawn Код:
new foo;
AnyFunction()
{
    foo = SetTimer("ExplosionTimer", 5000, 0);
}
...
//later to kill it
...
KillTimer(foo);
But, this kills the timer. It doesnt make it wait 5 seconds ..


AW: Pauses in a "LOOP" - Meta - 05.01.2011

Don't use
pawn Код:
for(new i = 0; i < 30000; i++)
{
}



Re: Pauses in a "LOOP" - Doom8890 - 05.01.2011

NVM, it is answered already.


AW: Re: Pauses in a "LOOP" - Meta - 05.01.2011

Quote:
Originally Posted by Dark734
Посмотреть сообщение
But, this kills the timer. It doesnt make it wait 5 seconds ..
Only use "KillTimer(foo);" if you want to kill the Timer


Re: AW: Re: Pauses in a "LOOP" - Dark734 - 05.01.2011

Quote:
Originally Posted by Meta
Посмотреть сообщение
Only use "KillTimer(foo);" if you want to kill the Timer
I don't want to kill the timer. I want to make it wait 5 seconds before he does another explosion. ....