Author Topic: Explosion: Continuous shockwave  (Read 1386 times)

Im trying to create an explosion that lingers for a long period of time, dealing out a constant shockwave even after the initial blast. I am planning on doing this by spawning empty projectiles with invisible explosions similar to the initial blast for a short time period after the initial blast. I'm having some trouble making it work.

Code: [Select]
function DoomNukeRocketProjectile::onExplode(%this,%obj)
{
parent::onExplode(%this, %obj);

DoomNukeRocketProjectile.Schedule(400, "launchWave",%waves);

}

function DoomNukeRocketProjectile::LaunchWave(%this,%obj)
{
      %projectile = NukeWaveProjectile;
   %position = %obj.getPosition();

   %waves = 1;

   for(%numbar=0; %numbar<%waves; %numbar++)
   {
      %vector = %position;

      if(!%times == 8)
      {
           %x = (getRandom(-7,7) - 0.5) * 3.141592653;
       %y = (getRandom(-7,7) - 0.5) * 3.141592653;
       %z = (getRandom(-7,7) - 0.5) * 3.141592653;
       %velocity = %x SPC %y SPC %z;

       %p = new projectile()
       {
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %position;
sourceObject = %obj;
sourceSlot = %obj.client.player.lastFragslot;
client = %obj.client;
       };
$times = $times + 1;

DoomNukeRocketProjectile.Schedule(400, "launchWave",%p);
      }    
      else
{
$times = 0;
}    

      MissionCleanup.add(%p);
    
   }
  
}


By adding 1 to $times every time the function is called, it keeps track of how many shockwave explosions have been launched. Setting the schedule delay to a constant multiplied by the maximum number of shockwaves allowed before it stops, the blast can be set to linger for the exact lifetime of the visible explosion. When $times exceeds the maximum # of waves, it resets to 0 for the next projectile. I need some help getting it to work.
« Last Edit: January 02, 2011, 05:01:54 PM by takato14 »

so, what isn't working?

Hm, its not spawning any projectiles, so no explosions occur. $times doesnt increase from the explosion. I didnt see any problems either, but I'm not a genius at scripting, so I made this topic to get help. Apparently, things dont work that way. xC
« Last Edit: January 02, 2011, 10:03:21 PM by takato14 »

Cmon people 15 views and no ideas?

%vector = %position;
it doesn't look like you're using %vector in there
$times = $times + 1;
that would be a global varaible i think, and $times++; would work too
if(!%times == 8)
wouldn't that be if(%times != 8), but there is no %times as it's $times i think, and why not use >= or something?
function DoomNukeRocketProjectile::LaunchWave(%this,%obj)
DoomNukeRocketProjectile.Sche dule(400, "launchWave",%p);
it looks like you're giving it 3 things, while it's only taking 2

im not real sure what effect your going for here with %waves always set to 1.

but try this and see if it makes more sense. note its UNTESTED

Code: [Select]
function DoomNukeRocketProjectile::onExplode(%this,%obj)
 {
  parent::onExplode(%this, %obj);
  schedule(400, 0, "DoomNukeRocketProjectile::LaunchWave", %this, %obj, 1);
 }

function DoomNukeRocketProjectile::LaunchWave(%this,%obj, %waves)
 {
  %projectile = NukeWaveProjectile;
  %position = %obj.getPosition();

   for (%numbar=0; %numbar<%waves; %numbar++)
     {
      if ($times > 8)
        {
         $times = 0;
         return;
        }

      %x = (getRandom(-7,7) - 0.5) * 3.141592653;
      %y = (getRandom(-7,7) - 0.5) * 3.141592653;
      %z = (getRandom(-7,7) - 0.5) * 3.141592653;
      %velocity = %x SPC %y SPC %z;

      %p = new projectile()
       {
        dataBlock = %projectile;
        initialVelocity = %velocity;
        initialPosition = %position;
        sourceObject = %obj;
        sourceSlot = %obj.client.player.lastFragslot;
        client = %obj.client;
       };
      $times++;
      %this.schedule(400, "LaunchWave", %p, %waves);
  
      MissionCleanup.add(%p);
     }
  }
« Last Edit: January 04, 2011, 06:27:37 PM by Red_Guy »

i think you messed up the code boxes, and not sure how to do projectiles, although i can look over basic things, and isn't the schedule function supposed to be:
schedule(delay, 0, function name, arguments);?

i think you messed up the code boxes, and not sure how to do projectiles, although i can look over basic things, and isn't the schedule function supposed to be:
schedule(delay, 0, function name, arguments);?
If that's the case, then the example I used for the schedule(); (bushi's homing vector) is wrong. :/

Code: [Select]
[code]im not real sure what effect your going for here with %waves always set to 1.

but try this and see if it makes more sense. note its UNTESTED

function DoomNukeRocketProjectile::onExplode(%this,%obj)
 {
  parent::onExplode(%this, %obj);
  schedule(400, 0, "DoomNukeRocketProjectile::LaunchWave", %this, %obj, 1);
 }

function DoomNukeRocketProjectile::LaunchWave(%this,%obj, %waves)
 {
  %projectile = NukeWaveProjectile;
  %position = %obj.getPosition();

   for (%numbar=0; %numbar<%waves; %numbar++)
     {
      if ($times > 8)
        {
         $times = 0;
         return;
        }

      %x = (getRandom(-7,7) - 0.5) * 3.141592653;
      %y = (getRandom(-7,7) - 0.5) * 3.141592653;
      %z = (getRandom(-7,7) - 0.5) * 3.141592653;
      %velocity = %x SPC %y SPC %z;

      %p = new projectile()
       {
        dataBlock = %projectile;
        initialVelocity = %velocity;
        initialPosition = %position;
        sourceObject = %obj;
        sourceSlot = %obj.client.player.lastFragslot;
        client = %obj.client;
       };
      $times++;
      %this.schedule(400, "LaunchWave", %p, %waves);
  
      MissionCleanup.add(%p);
     }
  }
[/code]
%waves is always set to one, because I only want to spawn one projectile at a time. The launchWave function is meant to be run a certain number of times, then stop running. By increasing $times by one each time it is run, this can be done. However, I need to reset it once it reaches 8 or whatever I end up setting it to.

EDIT: Tested your function, it doesnt work :/
« Last Edit: January 04, 2011, 06:07:13 PM by takato14 »

i think you messed up the code boxes, and not sure how to do projectiles, although i can look over basic things, and isn't the schedule function supposed to be:
schedule(delay, 0, function name, arguments);?

schedule works 2 ways:

1)  schedule(delay, 0, function, args)

2) object.schedule(delay, function, args)
   - this calls function' on object

 takato14 - put some echo() statements in your code to see whats going on. 

Once you get past trivial scripts, the "compile and pray" method doesnt work anymore.


schedule works 2 ways:

1)  schedule(delay, 0, function, args)

2) object.schedule(delay, function, args)
   - this calls function' on object

 takato14 - put some echo() statements in your code to see whats going on. 

Once you get past trivial scripts, the "compile and pray" method doesnt work anymore.



Actually. I typed almost all of this code up myself. I used other scripts as examples. Implying that I copy-pasted sections from other codes is only going to make me mad. I have a logical idea of how this is supposed to work, I'm just not completely sure on the syntax.

Okay, I did the echo, and the LaunchWave function isnt being called.

Okay, I did the echo, and the LaunchWave function isnt being called.
well there is a good start.

is DoomNukeRocketProjectile::onExplode being called?

if so - change it to:
Code: [Select]
function DoomNukeRocketProjectile::onExplode(%this,%obj)
 {
  parent::onExplode(%this, %obj);
  %this.schedule(400, "LaunchWave", %obj, 1);
 }

if onExplode isnt being called - then theres an erorr somewhere else in your code.

schedule works 2 ways:

1)  schedule(delay, 0, function, args)

2) object.schedule(delay, function, args)
   - this calls function' on object
ah, i haven't been using objects, so that's probably why i had no clue :D

well there is a good start.

is DoomNukeRocketProjectile::onExplode being called?

if so - change it to:
Code: [Select]
function DoomNukeRocketProjectile::onExplode(%this,%obj)
 {
  parent::onExplode(%this, %obj);
  %this.schedule(400, "LaunchWave", %obj, 1);
 }
if onExplode isnt being called - then theres an erorr somewhere else in your code.

onExplode gets called. I'll try that.