Post tutorial RSS HL2 Remplacing grenadelauncher by subshotgun

Simple code for replace, the grenadelaucher of smg1 for a shotgun shot. Originally the tutorial were going to explain how to make a clone of SMG1(SMGNOVA) and add the shotgun as secondary, but that would be a name remplacement so I decide just show how to edit the smg1.

Posted by on - Basic Server Side Coding

Open weapon_smg1.cpp

before this line

extern ConVar    sk_plr_dmg_smg1_grenade;	

add

extern ConVar	 sk_plr_num_shotgun_pellets;

you can create other variable if you want star something more serious, but for a simple mod is ok!
Now we go to the secondary attack, and found this:

	//Create the grenade
	QAngle angles;
	VectorAngles( vecThrow, angles );
	CGrenadeAR2 *pGrenade = (CGrenadeAR2*)Create( "grenade_ar2", vecSrc, angles, pPlayer );
	pGrenade->SetAbsVelocity( vecThrow );

	pGrenade->SetLocalAngularVelocity( RandomAngle( -400, 400 ) );
	pGrenade->SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); 
	pGrenade->SetThrower( GetOwner() );
	pGrenade->SetDamage( sk_plr_dmg_smg1_grenade.GetFloat() );

we need to comment this code, no more no less than this code...
and bellow that we add this:

	Vector	vecAiming	= pPlayer->GetAutoaimVector( AUTOAIM_SCALE_DEFAULT );	

	pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 1.0 );
	
	// Fire the bullets, and force the first shot to be perfectly accuracy
	pPlayer->FireBullets( sk_plr_num_shotgun_pellets.GetInt(), vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iSecondaryAmmoType, 0, -1, -1, 0, NULL, true, true );
	
	pPlayer->ViewPunch( QAngle( random->RandomFloat( -2, -1 ), random->RandomFloat( -2, 2 ), 0 ) );

Ok thats all in .cpp (actually you can comment more code about the grenade, wich will be useless, but you will no had compilation problems.
now we need to edit our weapon_smg1.cfg in ours mod folder/script
you must replace:

	"clip2_size"			"-1"

by

	"clip2_size"			"1"

and replace

	"secondary_ammo"		"SMG1_Grenade"

by

"secondary_ammo"		"Buckshot"

And at last if you want you can change the sound of the shot, but the grenadelauncher sounds isnt bad for me. Anyway find this line

"double_shot"		"Weapon_SMG1.Double"

and replace by

"double_shot"		"Weapon_Shotgun.Single"

well compile and check! if theres some bug PM me!

Good luck

Comments
Tom12
Tom12

i cannot find weapon_smg1.cpp!

Reply Good karma Bad karma+1 vote
$n!p3r
$n!p3r

same here

Reply Good karma Bad karma+1 vote
Bioko
Bioko

it is located in server/hl2 or something like that.

Reply Good karma Bad karma+1 vote
pspslimboy
pspslimboy

I get a compile error that says: 'CBaseEntity::FireBullets' : no overloaded function takes 13 arguments

Reply Good karma Bad karma+1 vote
Foxtrop Author
Foxtrop

Weird... you should copy the firebullets from your shotgun file, maybe valve updates the SDK or maybe you are using a diferent version of SDK

Reply Good karma+1 vote
LiamFarley1998
LiamFarley1998

You can also go to scripts smg 1 or 2 and change the ammotype to buckshot, then change the sounds too, a whole lot easier.

Reply Good karma Bad karma+1 vote
Foxtrop Author
Foxtrop

Sure that work? I mean I think that would consume shotgun ammo but shoot grenades, but well I dont know about the scripting of HL2

Reply Good karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.