SA-MP Forums Archive
[Loop] Weapon-Command problem - 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: [Loop] Weapon-Command problem (/showthread.php?tid=124972)



[Loop] Weapon-Command problem - canard - 01.02.2010

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?


Re: [Loop] Weapon-Command problem - MadeMan - 01.02.2010

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


Re: [Loop] Weapon-Command problem - canard - 01.02.2010

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.


Re: [Loop] Weapon-Command problem - MadeMan - 01.02.2010

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


Re: [Loop] Weapon-Command problem - Joe Staff - 01.02.2010

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.


Re: [Loop] Weapon-Command problem - canard - 03.02.2010

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


Re: [Loop] Weapon-Command problem - MadeMan - 03.02.2010

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;
    }