Pauses in a "LOOP"
#1

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
Reply
#2

Create a Timer that gets called every 5 Seconds
SetTimer
SetTimerEx
Reply
#3

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
Reply
#4

<retracted, read title incorrectly>
Reply
#5

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);
Reply
#6

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 ..
Reply
#7

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

NVM, it is answered already.
Reply
#9

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
Reply
#10

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. ....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)