Dynamic Viewmodel FOVs: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Dymanic FOVs: A firend to anyone using HL2 and CS:S weapons in the same mod!)
 
No edit summary
Line 44: Line 44:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
     "ViewModelFOV"      "NaN"</syntaxhighlight>
     "ViewModelFOV"      "NaN"</syntaxhighlight>
To we weaponscript file and replace NaN with your FOV or choice. Here is a tip: CS:S weapons normaly look good with an FOV of 72, and HL2 weapons normaly look good with an FOV of 54.
To the weaponscript file and replace NaN with your FOV or choice. Here is a tip: CS:S weapons normaly look good with an FOV of 72, and HL2 weapons normaly look good with an FOV of 54.


[[Category:Weapons programming]]
[[Category:Weapons programming]]
[[Category:Tutorials]]
[[Category:Tutorials]]

Revision as of 12:44, 23 January 2015

This is a very simple copy-and-paste tutorial for seting a weapon's viewmodel FOV in it's script. Lets get started!

Add this to weapon_parse.h in the shared gamefolder:

	float m_flViewModelFOV; // Dynamic Viewmodel FOV

Put this under:

	char szAmmo2[MAX_WEAPON_AMMO_NAME]; // "secondary" ammo type

Next Add this string to weapon_parse.cpp in FileWeaponInfo_t::Parse:

	m_flViewModelFOV = pKeyValuesData->GetFloat("ViewModelFOV", 54.0f);

and then change ClientModeShared::GetViewModelFOV in clientmode_shared.cpp to say:

ConVar r_viewmodelfov("r_viewmodelfov", "0", FCVAR_CHEAT);

float ClientModeShared::GetViewModelFOV(void)
{
	float flFov = 90.0f;

	if (r_viewmodelfov.GetFloat() > 0)
		return r_viewmodelfov.GetFloat();

	CBasePlayer *pPlayer = CBasePlayer::GetLocalPlayer();

	if (!pPlayer)
		return flFov;

	C_BaseCombatWeapon *pWpn = pPlayer->GetActiveWeapon();

	if (pWpn)
	{
		flFov = pWpn->GetWpnData().m_flViewModelFOV;
	}

	return flFov;
}

Now, dude to this, the command "viewmodel_fov" will no longer work, but you will be able to set the FOVs of weapons in their script file! Just add:

    "ViewModelFOV"      "NaN"

To the weaponscript file and replace NaN with your FOV or choice. Here is a tip: CS:S weapons normaly look good with an FOV of 72, and HL2 weapons normaly look good with an FOV of 54.