Importing CSS Weapons Into HL2: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:


Update 9th Jan 14: Okay so I wrote this original monstrosity nearly 10 years ago (holy hell) and it is now 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.
Update 9th Jan 14: Okay so I wrote this original monstrosity nearly 10 years ago (holy hell) and it is now 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.
 
<br>
-------------------------------------------
=Section 1 - Model Editing=
'''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)
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)
 
<br>
-------------------------------------------
=Section 2 - Fine Tuning the Model=
'''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).
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).
Line 47: Line 43:
</code>
</code>
This will enable the cl_righthand cvar to be activated and your weapon model will no display on the correct side of the screen. Now just save and compile.
This will enable the cl_righthand cvar to be activated and your weapon model will no display on the correct side of the screen. Now just save and compile.
<br>
=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.


-------------------------------------------
<pre>
'''SECTION 3 - OPTIONAL TWEAKS'''
if ( input->CAM_IsThirdPerson() )
-------------------------------------------
{
C_BaseCombatWeapon *pWeapon = GetActiveWeapon();
pWeapon->GetAttachment( iAttachment+1, attachOrigin, attachAngles );
}
else
{
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 );
</pre>


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 there is a fix in the Snippets section of the Programming page on the VDC Wiki.
Go to fx.cpp, under the statement <code>pParticle->m_vecVelocity.Init();</code> in <code>FX_MuzzleFlash</code>, place the following code.


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



Revision as of 01:45, 9 January 2014

Broom icon.png
This article or section needs to be cleaned up to conform to a higher standard of quality.
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.
Broom icon.png
This article or section should be converted to third person to conform to wiki standards.

Update 9th Jan 14: Okay so I wrote this original monstrosity nearly 10 years ago (holy hell) and it is now 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 cl_righthand command, which we will enable next; go to your Mods Src folder (C:\MODNAME\src\cl_dll) and open 'c_baseviewmodel.cpp' and scroll down to line 25 and find the line that looks like this:

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

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 correct 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 );
 				}
 				else
 				{
 					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;

Enjoy!

Ferrety (ferrety6012@gmail.com)