Importing CSS Weapons Into HL2

From Valve Developer Community
Revision as of 12:50, 24 April 2016 by BitMage (talk | contribs) (Section 2 - Fine Tuning the Model: The 2013 line number)
Jump to: navigation, search

Update 9th Jan 14: Okay so I wrote this original monstrosity nearly 9 years ago (holy hell) and it is was very much so out of date and horribly untidy, I've gone through and removed anything that is no longer useful and had a general tidy up. This now conforms with the latest 2013 SDK.

Section 1 - Model Editing

EDIT: SNIPPED THIS SECTION OUT (The 2013 SDK will work with any existing CSS model without model editing, just a little bit of coding is required to remove one or two bugs)

Section 2 - Fine Tuning the Model

Once you have your v_model.mdl and w_model.mdl set up you will need to assign the models to a weapon using its weapon script file. Locate your new weapons script file eg. weapon_357.txt inside the 'scripts' folder (C:\Program Files\Steam\SteamApps\sourcemods\MODNAME\scripts).

Now to fix the issue of CSS weapons only displaying on the left side of the screen we can do the following.

Inside the weapon script file, add these two lines:

"BuiltRightHanded" "0" 
"AllowFlipping" "1"  

This will send information to the client regarding the cl_righthand command, which we will enable next; locate your Mods Src folder (C:\MODNAME\src\cl_dll) or ("C:\MODNAME\src\game\client" for Source SDK 2013) and open 'c_baseviewmodel.cpp' and scroll down to line 25 (35 in 2013) and find the line that looks like this:

ConVar cl_righthand( "cl_righthand", "1", FCVAR_ARCHIVE, "Use right-handed view models." ); 

And simply comment out the top and bottom lines like so:

// #ifdef CSTRIKE_DLL 
ConVar cl_righthand( "cl_righthand", "1", FCVAR_ARCHIVE, "Use right-handed view models." ); 
// #endif  

And go to line 173 and comment out these lines as follows:

// #ifdef CSTRIKE_DLL
	// If cl_righthand is set, then we want them all right-handed.
	CBaseCombatWeapon *pWeapon = m_hWeapon.Get();
	if ( pWeapon )
		const FileWeaponInfo_t *pInfo = &pWeapon->GetWpnData();
		return pInfo->m_bAllowFlipping && pInfo->m_bBuiltRightHanded != cl_righthand.GetBool();
// #endif

This will enable the cl_righthand cvar to be activated and your weapon model will no display on the wrong side of the screen. Now just save and compile.

Section 3 - Optional Tweaks

If you aren't using particle muzzle flashes (which you really should be, they're very pretty!) you may have some issues with the old style muzzle flashes when using CSS weapons. In that case you can use the fix below.

In c_baseanimating.cpp, at line 3024 (after the big switch statement), comment out the code so it looks like this

			if ( iAttachment != -1 && m_Attachments.Count() > iAttachment )
				GetAttachment( iAttachment+1, attachOrigin, attachAngles );
				int entId = render->GetViewEntity();
				ClientEntityHandle_t hEntity = ClientEntityList().EntIndexToHandle( entId );
				tempents->MuzzleFlash( attachOrigin, attachAngles, atoi( options ), hEntity, bFirstPerson );

and insert the following code after the comment.

 				if ( input->CAM_IsThirdPerson() )
 					C_BaseCombatWeapon *pWeapon = GetActiveWeapon();
 					pWeapon->GetAttachment( iAttachment+1, attachOrigin, attachAngles );
 					C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
 					CBaseViewModel *vm = pPlayer->GetViewModel();
 					vm->GetAttachment( iAttachment+1, attachOrigin, attachAngles );
 					engine->GetViewAngles( attachAngles );
 				g_pEffects->MuzzleFlash( attachOrigin, attachAngles, 1.0, MUZZLEFLASH_TYPE_DEFAULT );

Go to fx.cpp, under the statement pParticle->m_vecVelocity.Init(); in FX_MuzzleFlash, place the following code.

		C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
		Vector velocity = pPlayer->GetLocalVelocity();
		pParticle->m_vecVelocity += velocity;


Ferrety ([email protected])