2. MXG Weapon Mod - Explosion and SFX Depending on Material
by Marcus L · 05/13/2010 (7:08 am) · 15 comments
Tested on: 1.1b2
Note: I will only keep my resources up to date until next stable release (1.1 final)
This resource will give you the ability to define custom particle effects, explosions and sound effects for your materials. Like the previous, the system is not perfect but it works.
Like the previous, this is how to install it:
Where it says // Added, it means that the line is added.
Where it says // Removed, it means that the line is removed.
Where it says // Changed, it means that the line is changed.
Where it says ..., it means that there is code between what ever that was last written.
Whenever it says ..., there will be an comment below describing what function it is.
I recommend you using CTRL + F to find where to put the code blocks. Remember to backup before installing.
Unfortunately you'll have to install all my previous resources to install this one (Scroll down to see a list of my Weapon Mod resources). Of course this resource is easily modifiable if you for example only want this resource but no other.
We'll start by editing materials/materialDefinition.cpp
Now for materials/materialDefinition.h
Then you'll have to edit T3D/projectile.cpp
Last, edit T3D/projectile.h
Start (re)building while you add the next part.
The next part is the part I would like to avoid, this will be fixed in a later resource
Edit scripts/server/customMatFX.cs that you created in the previous resouce, and add:
Now, add variable customExplosion = true; in the projectile of the weapons you want to be affected by the custom explosions , this is good for RocketLaunchers which usually have the same explosion unregardless of material.
To test:
Run game,
Load level,
Load up an random shape,
Find the material name of the shape and enter material.setCustomExplosion(explosion); in the console, where material is the name/id of the material, and explosion is the name/id of the explosion.
And try shooting it.
If you stumble upon some issues, let me know.
Also know that my methods might not be correct, nor the most professional. Therefore if you see some silly mistakes please leave a comment with the "fix".
Other resources in my Weapon Mod:
1. MXG Weapon Mod - Decals Depending on Material
2. MXG Weapon Mod - Explosion and SFX Depending on Material
3. MXG Weapon Mod - Structure and Armor Piercing Projectiles
4. MXG Weapon Mod - Advanced Crosshair
Thanks,
Marcus L.
Note: I will only keep my resources up to date until next stable release (1.1 final)
This resource will give you the ability to define custom particle effects, explosions and sound effects for your materials. Like the previous, the system is not perfect but it works.
Like the previous, this is how to install it:
Where it says // Added, it means that the line is added.
Where it says // Removed, it means that the line is removed.
Where it says // Changed, it means that the line is changed.
Where it says ..., it means that there is code between what ever that was last written.
Whenever it says ..., there will be an comment below describing what function it is.
I recommend you using CTRL + F to find where to put the code blocks. Remember to backup before installing.
Unfortunately you'll have to install all my previous resources to install this one (Scroll down to see a list of my Weapon Mod resources). Of course this resource is easily modifiable if you for example only want this resource but no other.
We'll start by editing materials/materialDefinition.cpp
...
//In the includes
#include "sfx/sfxTrack.h"
#include "sfx/sfxTypes.h"
#include "T3D/decal/decalManager.h"
#include "T3D/decal/decalData.h"
#include "T3D/fx/explosion.h" // Added
...
//In Material::Material()
mFootstepSoundCustom = 0; mImpactSoundCustom = 0;
mCustomDecal = NULL;
mCustomExplosion = NULL; // Added
...
//In Material::initPersistFields()
addField( "customImpactSound", TypeSFXTrackName, Offset( mImpactSoundCustom, Material ),
"The sound to play when the player impacts on the surface with a velocity equal or greater than PlayerData::groundImpactMinSpeed. "
"If this is set, it overrides #impactSoundId. This field is useful for directly assigning custom impact sounds to materials "
"without having to rely on the PlayerData sound assignment.nn"
"@warn Be aware that materials are client-side objects. This means that the SFXTracks assigned to materials must be client-side, too." );
addField( "customDecal", TYPEID< DecalData >(), Offset( mCustomDecal, Material ) );
addField( "customExplosion", TYPEID< ExplosionData >(),Offset( mCustomExplosion, Material ) ); // Added
...
//Custom code, put it where you want
void Material::setCustomExplosion(ExplosionData *explosion)
{
this->mCustomExplosion = explosion;
}
ConsoleMethod( Material, setCustomExplosion, void, 3, 3,
"setExplosionDecal: Set a spesific explosion for assigned material." )
{
ExplosionData* explosion;
if (Sim::findObject(argv[2],explosion))
object->setCustomExplosion(explosion);
}Now for materials/materialDefinition.h
...
//In friend class definition
class MaterialPhysicsProfile;
class DecalData;
class ExplosionData; // Added
...
//In public of class Material
SFXTrack* mImpactSoundCustom;
DecalData* mCustomDecal;
ExplosionData* mCustomExplosion; // Added
...
//Same
virtual void setAutoGenerated(bool isAutoGenerated) { mAutoGenerated = isAutoGenerated; }
virtual void setCustomDecal(DecalData *decal);
virtual void setCustomExplosion(ExplosionData *explosion); // AddedThen you'll have to edit T3D/projectile.cpp
...
//In ProjectileData::ProjectileData()
decalId = 0;
customDecal = false;
customExplosion = false; // Added
...
//In void ProjectileData::initPersistFields()
addField("waterExplosion", TYPEID< ExplosionData >(), Offset(waterExplosion, ProjectileData));
addField("customDecal", TypeBool, Offset(customDecal, ProjectileData));
addField("customExplosion", TypeBool, Offset(customExplosion, ProjectileData)); // Added
...
//In Projectile::simulate( F32 dt )
//if(mSourceObject)
//mSourceObject->enableCollision();
// Get the rayCasts material info // Changed ->
Material* material = ( rInfo.material ? dynamic_cast< Material* >( rInfo.material->getMaterial() ) : 0 );
DecalData* decal = NULL;
ExplosionData* explosion = NULL;
if(material != NULL)
{
if(mDataBlock->customDecal && material->mCustomDecal != NULL)
// Uses custom decal, initalizing custom decal
decal = material->mCustomDecal;
else
// Initalizing default decal
decal = mDataBlock->decal;
if(mDataBlock->customExplosion && material->mCustomExplosion != NULL)
// Uses custom explosion, ititalizing custom explosion
explosion = material->mCustomExplosion;
else
// Initalizing default explosion
explosion = mDataBlock->explosion;
} // Changed <-
// Ok, here is how this works:
// onCollision is called to notify the server scripts that a collision has occurred, then
...
//Same
onCollision(rInfo.point, rInfo.normal, rInfo.object);
explode(rInfo.point, rInfo.normal, decal, explosion, objectType ); // Changed
...
//In void Projectile::unpackUpdate(NetConnection* con, BitStream* stream)
stream->read(&mCollideHitType);
DecalData* decal = NULL;
ExplosionData* explosion = NULL; // Added
// start the explosion visuals
explode(explodePoint, explodeNormal, decal, explosion, mCollideHitType); // Changed
...
//In void Projectile::explode( const Point3F &p, const Point3F &n, DecalData* decal, const U32 collideType )
void Projectile::explode( const Point3F &p, const Point3F &n, DecalData* decal, ExplosionData* explosion, const U32 collideType ) // Changed
{
...
//Same void Projectile::explode( const Point3F &p, const Point3F &n, DecalData* decal, ExplosionData* explosion, const U32 collideType )
// Client just plays the explosion at the right place...
//
Explosion* pExplosion = NULL;
if (explosion != NULL) // Added ->
{
pExplosion = new Explosion;
pExplosion->onNewDataBlock(explosion);
}
else // Added <-
...
//Same
pExplosion = new Explosion;
pExplosion->onNewDataBlock(mDataBlock->waterExplosion);
}
else
if (mDataBlock->explosion && explosion == mDataBlock->explosion) // ChangedLast, edit T3D/projectile.h
... //In public of class ProjectileData S32 decalId; // (impact) Decal ID bool customDecal; bool customExplosion; // Added ... //In protected of class Projectile virtual void explode(const Point3F& p, const Point3F& n, DecalData* decal, ExplosionData* explosion, const U32 collideType ); // Changed
Start (re)building while you add the next part.
The next part is the part I would like to avoid, this will be fixed in a later resource
Edit scripts/server/customMatFX.cs that you created in the previous resouce, and add:
function loadCustomExplosion()
{
// Where material is the name/id of the material
// and explosion is the name/id of the explosion
material.setCustomDecal(explosion);
}and last, adding this line to game/gameCore.cs:$Game::Schedule = schedule($Game::Duration * 1000 * 60, 0, "onGameDurationEnd"); $Game::Running = true; loadCustomDecals(); loadCustomExplosion(); // Added
Now, add variable customExplosion = true; in the projectile of the weapons you want to be affected by the custom explosions , this is good for RocketLaunchers which usually have the same explosion unregardless of material.
To test:
Run game,
Load level,
Load up an random shape,
Find the material name of the shape and enter material.setCustomExplosion(explosion); in the console, where material is the name/id of the material, and explosion is the name/id of the explosion.
And try shooting it.
If you stumble upon some issues, let me know.
Also know that my methods might not be correct, nor the most professional. Therefore if you see some silly mistakes please leave a comment with the "fix".
Other resources in my Weapon Mod:
1. MXG Weapon Mod - Decals Depending on Material
2. MXG Weapon Mod - Explosion and SFX Depending on Material
3. MXG Weapon Mod - Structure and Armor Piercing Projectiles
4. MXG Weapon Mod - Advanced Crosshair
Thanks,
Marcus L.
About the author
#2
I am glad to see people are making something like this in T3D.
05/17/2010 (1:53 pm)
I wish I had thought of something like this LOL.I am glad to see people are making something like this in T3D.
#3
05/18/2010 (9:52 am)
Great work Marcus! Nice continuation of your previous resource.
#4
@ Ron Nelson, i would believe it shouldn't be that hard to modify it for TGEA. It's mostly based on original Torque codes.
05/18/2010 (12:28 pm)
Thanks for so supportive comments (again).@ Ron Nelson, i would believe it shouldn't be that hard to modify it for TGEA. It's mostly based on original Torque codes.
#5
05/21/2010 (10:23 pm)
@Marcus, he's joking. He has already provided a resource that has surface dependent explosions, plus much more.
#6
05/22/2010 (4:07 am)
Seriously? Why didn't i ever find that =/. Then aren't this resource kinda useless. Argh, and i who though i had done something useful for the community.
#7
@C2 - It is nice to be remembered LOL.
06/08/2010 (4:29 pm)
Hey Marcus I just hope that others can take what I did and come up with even better new stuff. I am glad to see someone going down the same road I did though, hope to see great things from you.@C2 - It is nice to be remembered LOL.
#8
const char* mCustomExplosion;
to
ExplosionData* mCustomExplosion;
and passing it in as
explosion = material->mCustomExplosion
introduce any problems later on?
07/07/2010 (9:53 am)
Hey I have one question...could changing the line: const char* mCustomExplosion;
to
ExplosionData* mCustomExplosion;
and passing it in as
explosion = material->mCustomExplosion
introduce any problems later on?
#9
EDIT: Wait a second... think i have the solution. brb.
07/07/2010 (10:16 am)
Well, it will of course work, but then all you weapons will have the same explosion against that material. The reason i used:if(material->mCustomExplosion != NULL)
{
if(mDataBlock->metalExplosion != NULL && !dStrcmp(material->mCustomExplosion, "metal"))
explosion = mDataBlock->metalExplosion;
else if(mDataBlock->concreteExplosion != NULL && !dStrcmp(material->mCustomExplosion, "concrete"))
explosion = mDataBlock->concreteExplosion;
else if(mDataBlock->woodExplosion != NULL && !dStrcmp(material->mCustomExplosion, "wood"))
explosion = mDataBlock->woodExplosion;
else
explosion = mDataBlock->explosion;
}instead of:if(material->mCustomExplosion != NULL) // Uses custom explosion, initalizing custom explosion explosion = material->mCustomExplosion; else // Initalizing default explosion explosion = mDataBlock->explosion;is that then you can't make individualized weapon explosions against the same material. I might look into alternative solutions here, but there is no other way that string compare than i can come up with atm =/.
EDIT: Wait a second... think i have the solution. brb.
#10
07/07/2010 (10:33 am)
Ok, so this will only work if i could do the following:if(material->mCustomExplosion != NULL) // If in this case material->mCustomExplosion would be metalExplosion // then explosion would be mDataBlock->metalExplosion explosion = "mDataBlock->" @ material->mCustomExplosion; else // Initalizing default explosion explosion = mDataBlock->explosion;If you see my comment in there, you see what i mean. Anyone knows how to do this? Or else I'll just stick with the pervious method.
#11
08/09/2010 (4:49 pm)
I'm no expert at C++, but could you just useexplosion = matierial->mCustomExplosion; explosion = mDataBlock->explosion;
#12
08/09/2010 (4:56 pm)
*facepalm* why didn't i think of that :P. Well, I'll test it and report back (i have yet to integrate my own resource in 1.1b2, lol).
#13
08/09/2010 (6:15 pm)
Haha, I was wondering if my memory of C++ was impaired for me to catch that but not you. Glad I could be the voice of common sense whispering in your ear.
#14
Updated the original resource
EDIT: If you haven't read this yet Jonathan, know that you can link to my first resouce in this Weapon Mod series in you recent blog. Thanks.
08/09/2010 (7:25 pm)
Quote:I was wondering if my memory of C++ was impaired for me to catch that but not youJust for the record, I'm not an C++ expert (you probably know more than me O_o). Unfortunately I was unable to fix the problem however, your words enlighten my brain to think "Whats the point of individualized weapon explosions/effects when mostly all bullet weapons have the same effect?". Therefore i decided to change:
if(material->mCustomExplosion != NULL)
{
if(mDataBlock->metalExplosion != NULL && !dStrcmp(material->mCustomExplosion, "metal"))
explosion = mDataBlock->metalExplosion;
else if(mDataBlock->concreteExplosion != NULL && !dStrcmp(material->mCustomExplosion, "concrete"))
explosion = mDataBlock->concreteExplosion;
else if(mDataBlock->woodExplosion != NULL && !dStrcmp(material->mCustomExplosion, "wood"))
explosion = mDataBlock->woodExplosion;
else
explosion = mDataBlock->explosion;
}toif(mDataBlock->customExplosion && material->mCustomExplosion != NULL)
{
explosion = material->mCustomExplosion;
}else{
explosion = mDataBlock->explosion;
}Quote:Glad I could be the voice of common sense whispering in your ear.Yeah, that's what i need. An external common sense :D.
Updated the original resource
EDIT: If you haven't read this yet Jonathan, know that you can link to my first resouce in this Weapon Mod series in you recent blog. Thanks.
#15
And thanks for that, will do, especially after comment #2 on your first resource
08/09/2010 (11:08 pm)
Glad I could help.And thanks for that, will do, especially after comment #2 on your first resource
Quote: this is a necessary or "must be" resource for T3DCan't argue with that.

Torque Owner Cyril Rousselet
Gallica Game Studio