[Loop] Weapon-Command problem
#1

Hi

I tried to make a little Command script to create an explosion around the admin.
Problem is : I want to use a loop for it, and it doesn't work.
I don't know any other type of loop, but I dont think there's a problem from using this one.
Just take a look :

pawn Код:
public OnPlayerCommandText(playerid,cmdtext[])
    {
  if(!strcmp(cmdtext,"/ion",true))
  {
       new Float:x, Float:y, Float:z;

  // Get Player Position
  GetPlayerPos(playerid, x, y, z);
       for(new i=30; i<50; i++)
       {
  // Create an explosion around the Character from all around him 20 times
  CreateExplosion(x+0, y+i, z, 6, 50);
  CreateExplosion(x+i, y+i, z, 6, 50);
  CreateExplosion(x+i, y+0, z, 6, 50);
  CreateExplosion(x+i, y-i, z, 6, 50);
  CreateExplosion(x+0, y-i, z, 6, 50);
  CreateExplosion(x-i, y-i, z, 6, 50);
  CreateExplosion(x-i, y+0, z, 6, 50);
  CreateExplosion(x-i, y+i, z, 6, 50);
 
       return 1;
    }
    return 1;
  }
The result? Only one circle of explosions, instead of 20.
In any script i make, loop "For" don't work, even from code taked on the forum.
Any idears?
Reply
#2

It makes the 20 explosions so fast that you can't see it. You should use a timer.
Reply
#3

Well, for a moment, i tough so. But, i tryed this other command :

pawn Код:
if(!strcmp(cmdtext,"/supermanloop",true))
  {
  for(new s = 0; s <= 160; s++) SetPlayerVelocity(playerid,0.0,0.0,20000);
    return 1;
    }
In this one, the loop must push my character to jump 160 times. It don't work too :/
So, i don't know if it's really work. But I'll try a timer.
Reply
#4

When using this loop it all happens in about 0.00001 seconds.
Reply
#5

The reason the explosions don't work is because you can only set a few explosions off simultaneously, (I'm not entirely sure how much). And your SetPlayerVelocity won't work because there's a maximum positive Z velocity (like 0.5 or something) and all you're doing is setting the player to the same speed a bunch of times, so hhe'll go up as long as that script is running, which is like 0.001 seconds. Plus setplayervelocity only works when the player isn't on the ground.
Reply
#6

Well, i'll try with timers. Doesn't look so easy...
Thanks for your answers
Reply
#7

You can try this:

pawn Код:
forward MakeExplosions(playerid, timesmore);
public MakeExplosions(playerid, timesmore)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
   
    CreateExplosion(x+0, y+i, z, 6, 50);
    CreateExplosion(x+i, y+i, z, 6, 50);
    CreateExplosion(x+i, y+0, z, 6, 50);
    CreateExplosion(x+i, y-i, z, 6, 50);
    CreateExplosion(x+0, y-i, z, 6, 50);
    CreateExplosion(x-i, y-i, z, 6, 50);
    CreateExplosion(x-i, y+0, z, 6, 50);
    CreateExplosion(x-i, y+i, z, 6, 50);
   
    if(timesmore > 0)
    {
        SetTimerEx("MakeExplosions", 500, 0, "ii", playerid, timesmore-1);
    }
}

public OnPlayerCommandText(playerid,cmdtext[])
{
    if(!strcmp(cmdtext,"/ion",true))
    {
        SetTimerEx("MakeExplosions", 500, 0, "ii", playerid, 20);
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)