We'll use the most complex explosion script as an example since all parts usually used in explosions can be found in this script.
A good practice would be to have the Spg2\Scripts\ShipOnDestroy.sal opened up in Notepad++. Installing our N++ plugins is also advised as it is easier to read the script that way.
Only specific chunks of script code will be copied here to explain each segment. Script functions ARE NOT explained here. Review the Scripting section on each script function.
NOT all variables will be apparent in the copied chunks, but they are in the original script file!
THE THEORY BEHIND IT
Don't get intimidated by the size of the ShipOnDestroy script. It is not that complex. We're only repeating almost the same chunk several times to create a series of smaller explosions before the final bang.
In-game scripts are comprised of numerous individual parts:
To limit the number of almost identical scripts, the first part of the ShipOnDestroy.sal script sets some basic parameters regarding size of the exploding object.
The code above sets the appropriate sizes of the explosion parts that can be scaled dynamically, via script functions.
The above code handles those parts of the explosion script that cannot be scaled dynamically. For such instances, we created several sizes to cover all bases. Once again we checked the radius of the exploding object and in regards to that, we set the appropriate free model Ids (check FreeModel.wds database for reference). We've also included some randomization of the particle effects so they aren't the same every time. And finally, we've also linked the chance for a derelict to appear directly to object size. Larger objects will have higher chance of spawning a derelict when they're destroyed. We only set the flag here and do the actual chance calculations further down the script.
The initial blast, the first explosion in the chain has more elements than the rest.
This portion generates the texture-based explosion. These are simple series of sprites that together form a sprite animation.
This part of the code spawns fiery debris flying out fromt he center of explosion.
To improve the look and feel, we also added some metal debris that flies out from the explosion center.
This is the first instance of the particle explosion. This is one of those that cannot be scaled dynamically via script functions. It's lifetime should also correspond to the particle emitter lifetime so the emitter doesn't start respawning the explosion particles.
What's an explosion without sound, right? This part handles the sound effect.
SERIES OF SIMILAR EXPLOSIONS FOLLOW
If you take a look further in the script, you'll see several more blocks. These are simply new instances of the above (but without the texture-based explosion). Between each block, we placed a short pause so it doesn't all explode at the same time.
The final portion of the script handles how and when the exploding object will disappear. We use a simple approach of creating a flash particle placed between the exploding object and the camera to obscure the object at the time of its disappearance.
A BIT OF ADVICE
Perhaps a good advice to give at this time is that when handling explosions and removal of objects via explosions, feel free to reuse this or similar default scripts, or parts of it. And then, once you're more familiar with the whole structure and system, start creating your own customized explosion script. As always, if you get stuck or if you have questions, send us an email at modding at starpointgemini.com.
Copyright © 2005-2017 Intercorona d.o.o.
Intercorona, LGM Games, Starpoint Gemini and Whale Engine are trademarks of Intercorona d.o.o. All Rights Reserved.