Welcome, Guest! Login | Register

Adding explosion to the Xbow bolt [Print this Article]
Posted by: Twilight Suzuka
Date posted: Feb 20 2005
User Rating: 3 out of 5.0
Number of views: 4991
Number of comments: 6
Description: Remember HL1's cross bow bolt exploded when it hit? Get that, in HL2.
Most of the coding for re-adding this effect is already in the code. We just need to re-activate it.

1. Open up weapon_crossbow.cpp

2. Add this to the includes:
 CODE  
#include "explode.h"


2. Go to the function:
 CODE  
CCrossbowBolt::BoltTouch( CBaseEntity *pOther )


3. Go down inside this function until you find:
 CODE  
if ( g_pGameRules->IsMultiplayer() )


4. Uncomment this line:
 CODE  
ExplosionCreate( GetAbsOrigin(), GetAbsAngles(), GetOwnerEntity(), 50, 200, SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE, 0.0f, this);


Congrats! Your Xbow bolts will now make an explosion effect when they hit something.
However, we also need to make a damaging effect.

5. Add under the explosion effect:
 CODE  
RadiusDamage ( CTakeDamageInfo( this, GetOwnerEntity(), 50, DMG_BLAST ), GetAbsOrigin(), 200, CLASS_NONE, NULL );


EXTRA:
How about we also spawn an energy ball when it hits?

6. Add these includes:
 CODE  

#include "prop_combine_ball.h"
#include "npc_combine.h"


7. Go back down to your function, and make a random vector for it to bounce off of:
 CODE  

    Vector vecVelocity;
    vecVelocity.x = random->RandomFloat( -1000.0f, 1000.0f );
    vecVelocity.y = random->RandomFloat( -1000.0f, 1000.0f );
    vecVelocity.z = random->RandomFloat( -1000.0f, 1000.0f );


8. Now, give it a random lifetime, and a random radius of damage.
 CODE  

    float lifetime = random->RandomFloat( 1.0, 4.0);
    int radi = random->RandomInt( 1, 10);



9. Add the energy ball spawn, and normalize the random's.

 CODE  

    CreateCombineBall(  GetAbsOrigin(),
        vecVelocity,
        radi * 100.0,
        20.0,
        lifetime,
        pOwner );


10. Wrap it all up, compile it, and your done.

Rate This Article
This article is currently rated: 3 out of 5.0 (2 Votes)

You have to register to rate this article.
User Comments Showing comments 1-6

Posted By: Unknown on Mar 19 2005 at 16:02:54
Hey, Good Tutorial!

But i think there is something not right.

4. Uncomment this line:

CODE
ExplosionCreate( GetAbsOrigin(), GetAbsAngles(), GetOwnerEntity(), 50, 200, SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE, 0.0f, this);

That line doesnt seem to exist. I only see this one

if ( g_pGameRules->IsMultiplayer() )
{
// SetThink( &CCrossbowBolt::ExplodeThink );
// SetNextThink( gpGlobals->curtime + 0.1f );
}
}Edited by Unknown on Mar 19 2005, 16:03:05

Posted By: Twilight Suzuka on Mar 20 2005 at 19:18:43
I meant add not uncomment.
You should also probably replace pOwner with GetOwner()

Posted By: Unknown on Mar 20 2005 at 22:02:00
Ahhh.. lol I'll try thatEdited by Unknown on Mar 20 2005, 22:02:09

Posted By: Unknown on Mar 21 2005 at 19:23:04
Ok it works now and you dont have to replace pOwner with GetOwner()

Posted By: hopper on Mar 28 2005 at 19:35:12
A cool addition:

in BoltTouch(), find where the code that handles what to do with the bolt when it hits the world. Instead of setting the Think() function to the time-delayed remove, you set it to a Detonate function. just like the commented out code:

SetThink(&CCrossbowBolt::ExplodeThink);
SetNextThink(gpGlobals->curtime+1.0f);

Then define your ExplodeThink() function to do the explosion and then remove the arrow from the world. Then you get a time-delayed detonating arrow.Edited by hopper on Mar 28 2005, 19:36:42

Posted By: RaccoonKing on Aug 31 2005 at 16:55:39
From what I can tell, you need to #include "explode.h" and the others after the else in:
 CODE  
#ifdef CLIENT_DLL
    #include "c_hl2mp_player.h"
    #include "c_te_effect_dispatch.h"
#else


It wouldn't work for me otherwise.

Also (if anyone's still reading this) the combineball segment of modding seems to not be able to find pOwner or GetOwner()

Maybe I'm just retarded, but if anyone knows the answer, please post. Thanks.


You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 05 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005


Latest Comments
knock knock
General | News
By: omega | Dec 22 2016
 
knock knock
General | News
By: MIFUNE | Oct 10 2015
 
New HL HUD Message System
Half-Life | Coding | Shared Tutorials
By: chbrules | Dec 31 2011
 
knock knock
General | News
By: Whistler | Nov 05 2011
 
Particle Engine tutorial part 4
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 18 2010
 
Particle Engine tutorial part 2
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Particle Engine tutorial part 3
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Game Movement Series #2: Analog Jumping and Floating
Half-Life 2 | Coding | Shared Tutorials
By: mars3554 | Oct 26 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Deadpool | Aug 02 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Persuter | Aug 02 2009
 

Site Info
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (3 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!