PDA

View Full Version : Sticky Grenades


jrNinja2
06-24-2007, 02:42 PM
I would like to say hello to everyone on these forums, as I am completely new to modding and development on the Source engine. I have just begun developing using the SDK and have followed the instructions on creating "My First Mod" in the SDK docs, but I cannot figure out how to get HL2 frag grenades to "stick" on their targets... similar to the plasma grenade effect from Halo.

I have located the GrenadeThrown.cpp file, but nothing I modify within it seems to affect the actual grenade, and I cannot even see a Warning() message I have put inside the Throw() function.

I have also looked at the base_grenade.cpp file and added the function:
void CBaseGrenade::StickTouch( CBaseEntity *pOther )
{
// don't hit the guy that launched this grenade
if ( pOther == GetThrower() )
return;
Vector vel;
vel.Init();
SetAbsVelocity( vel );
}

The attempt here was to initialize a 0 vector when SetTouch() is called from:
void CThrownGrenade::Spawn( void )
{
// point sized, solid, bouncing
//SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );
SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_CUSTOM );
//SetSolid( SOLID_BBOX );
SetSolid( SOLID_CUSTOM );
UTIL_SetSize(this, vec3_origin, vec3_origin);

// Movement
//SetGravity( UTIL_ScaleForGravity( 628 ) );
SetGravity(0.0f);
//SetFriction(0.6);
SetFriction(100.0f);

QAngle angles;
VectorAngles( GetAbsVelocity(), angles );
SetLocalAngles( angles );
QAngle vecAngVel( random->RandomFloat ( -100, -500 ), 0, 0 );
SetLocalAngularVelocity( vecAngVel );

SetTouch( &CThrownGrenade::StickTouch );
Warning("Grenade set to StickTouch in Spawn function...\n");
}

I never actually see the Warning message in the console, so it appears the function is never being called. Is there another place to affect the way a grenade would "stick" to a target, as opposed to bouncing or sliding?

I am really stuck here, thanks for any help.

-John

Marine
06-24-2007, 03:09 PM
If these functions are overridden in the other grenade files then they will not be called in the baseclass. Take a look for grenade_frag.cpp and stuff :)

lodle
06-24-2007, 04:43 PM
What happens is that for grenades the weapon doesnt control the actual grenade.

When you press fire the weapon spawns a grenade 1 unit away from u then pushes it in y direction. So look in grenade_frag.cpp and you should see some movement code in there you can change.

When u work out that you hit something you prob want to parent it to that object or if its a wall stop the movement check all together.

jrNinja2
06-24-2007, 08:02 PM
It doesn't look as though there is anything useful in the grenade_frag.cpp file, but the CThrownGrenade class inherits from CBaseGrenade, so the one I was looking at actually determines if the grenade touches something (or so it seems).

lodle - I am not quite sure how to make an object a parent of another object.

If I could get the grenade to stop dead in the air on contact I will consider that progress :)

Thanks for the replies,
-John

jrNinja2
07-07-2007, 11:12 AM
With a lot of help from Razvan and his fire crossbow bolt modification (http://www.freewebs.com/razvanadrian/snippet2.htm) , I've figured out how to get the grenades to stick to enemies only. I will be posting a tutorial once I finally get it working the way I finally want it to... complete with the blue plasma flames and hopefully a plugin for CS:S.