Author Topic: Spawning multiple debris/shells  (Read 4291 times)

Pretty self explanatory, I want to spawn several (in this case six) of a debris when a gun is reloading. Is there a way I can do this using just the debris data or the shell system?

Create an explosion datablock with only debris (no impulse, no damage, no camera shake; debrisNum = 6; as well); then, spawn an explosion.

Code: [Select]
function reloadDebris(%gun)
{
    %pos = %gun.getPosition(); //Adjust as needed.
    %obj = new Explosion()
    {
        datablock = ReloadDebris; //Adjust to name.
        position = %pos;
    };
}
Call the function with the argument %gun as the gun object. Offset to correct position as needed.

i don't know how to actually implement that
i presume it would become
function reloadDebris(%WingmanImage)
{
    %pos = %WingmanImage.getPosition();
    %obj = new Explosion()
    {
        datablock = shellExplosion;
        position = %pos;
    };
}


but i don't know how to actually call it? can i call more than one script in the states?

i don't know how to actually implement that
i presume it would become
function WingmanImage::whateverFunctionYouCallInThRe loadState(%datablock, %WingmanImage, %...)
{
    //Anything else you have in the function called during
    //reloading gets called here. If you already have a
    //function called during the reload sequence, simply
    //append the below code to the end of the function.
    //%WingmanImage is whatever argument in the reload
    //function that is the object in question.
    //If you already have the reload function and are
    //appending the below code, change %WingmanImage
    //below to whatever the variable is called in that function.

    %pos = %WingmanImage.getPosition();
    %obj = new Explosion()
    {
        datablock = shellExplosion;
        position = %pos;
    };
}


but i don't know how to actually call it? can i call more than one script in the states?

You might be able to call more that one script from a state (I'm not sure, never tried it), but I forgot you'd be calling it from the states, so I didn't really say what you should do for them specifically. Sorry. Instead, do something like that ^^(I edited your code above).

you cannot have multiple effects in the image states, but you can make a function that is called by the state that has a secondary effect in it.

you can use the eye shake explosion as an example of this, (alot of weapons have it) it is called during the fire state the fire state already has its own emitter going on, so its called through script.

although that's a somewhat bad example because the camera shake explosion is emitted by the %obj not the weapon. i don't know the code for spawning it at say, muzzlepoint.

you cannot have multiple effects in the image states, but you can make a function that is called by the state that has a secondary effect in it.

Just create a state loop (two states switching between each other) that ejects shells, and use stateScript with transitions to conditionally determine if it should stop.

What I've got now is:
function WingmanImage::OnWingmanOpen(%this, %obj, %slot)
{
    %obj.playThread(2, shiftleft);
   %obj.schedule(150, playThread, 2, activate);
   serverPlay3D(%this.RYG_ClipOutSound,%obj.getPosition());
   displayAmmo(%obj, %obj.getMountedImage(0));
   %pos = %WingmanImage.getPosition();
    %obj = new Explosion()
    {
        datablock = shellExplosion;
        position = %pos;
    };
}

But the shell explosion seems to be spawning at the world center rather than from the gun.

What I've got now is:
function WingmanImage::OnWingmanOpen(%this, %obj, %slot)
{
    %obj.playThread(2, shiftleft);
   %obj.schedule(150, playThread, 2, activate);
   serverPlay3D(%this.RYG_ClipOutSound,%obj.getPosition());
   displayAmmo(%obj, %obj.getMountedImage(0));
   %pos = %WingmanImage.getPosition();
    %obj = new Explosion()
    {
        datablock = shellExplosion;
        position = %pos;
    };
}

But the shell explosion seems to be spawning at the world center rather than from the gun.
That's because %WingmanImage does not exist. So %pos is blank and you get a console error when this function is called.

well sure, then what do i do

well sure, then what do i do
Where do you want to spawn the explosion? Where the player is? Where the muzzle of whatever they're holding is?

Where do you want to spawn the explosion? Where the player is? Where the muzzle of whatever they're holding is?
ideally from the ejectPoint of the gun but i'd be willing to settle for just the center of the model if that's too much of a pain

Pointless update: I have convinced the player to stuff out shells.

While entertaining, I wouldn't really call this progress.

   %pos = %obj.getPosition();
    %obj = new Explosion()
    {
        datablock = shellExplosion;
        position = %pos;
    };


My current guess is that I should be using %this.getPosition instead so I guess we'll see how that goes. Nope.
« Last Edit: September 14, 2014, 06:19:49 PM by Kishgal »

The reason it's spawning from the player is because %obj is the player object. To correct the position, use
Code: [Select]
%pos = %obj.getMountedObject(%slot).getPosition();

If %slot doesn't work for some reason, just change it to 0.

Wait... is a few shells falling out(like the shotgun) all you want?

The reason it's spawning from the player is because %obj is the player object. To correct the position, use
If %slot doesn't work for some reason, just change it to 0.
will try shortly, thanks

Wait... is a few shells falling out(like the shotgun) all you want?
well, yes
was that not apparent enough