Lowering your weapon on sprint: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
m (Declarations should be under public and not private, if they are under private then it won't work to load this code in another weapon file's ItemPostFrame!)
Line 4: Line 4:
{{note|1=This has only been tested with the latest HL2MP OB engine code.}}
{{note|1=This has only been tested with the latest HL2MP OB engine code.}}
{{note|1=This will not work if your weapon doesn't have the ACT_VM_IDLE_LOWERED animation in its .qc file (The Viewmodel). To fix this install Studio Compiler and decompile your Viewmodel and decompile one of your other models which has this animation, then add that animation into your decompiled .qc file. To find out how to add the animation just copy the animation from the working viewmodel .qc file.}}
{{note|1=This will not work if your weapon doesn't have the ACT_VM_IDLE_LOWERED animation in its .qc file (The Viewmodel). To fix this install Studio Compiler and decompile your Viewmodel and decompile one of your other models which has this animation, then add that animation into your decompiled .qc file. To find out how to add the animation just copy the animation from the working viewmodel .qc file.}}
{{note|1=If your weapon_yourweaponname.cpp has an ItemPostFrame in it overriding the base ItemPostFrame then you have to place this code in there as well, for example in the weapon_shotgun.cpp, it has an ItemPostFrame overriding the Baseweapon_Shared ItemPostFrame which means that the lowering weapon code will not work for this weapon, unless you add this code in the weapon's ItemPostFrame function!}}
{{note|1=If your weapon_yourweaponname.cpp has an ItemPostFrame in it overriding the base ItemPostFrame then you have to place this code in there as well, for example in the weapon_shotgun.cpp, it has an ItemPostFrame overriding the Basecombatweapon_Shared ItemPostFrame which means that the lowering weapon code will not work for this weapon, unless you add this code in the weapon's ItemPostFrame function! '''Remember to put the Basecombatweapon_Share.h declarations under public so that you can make use of these variables in other files, like the weapon_shotgun.cpp's ItemPostFrame, if you don't do this you will get undeclared identifier errors'''}}
{{note|1=Download the Studio Compiler here [http://www.chaosincarnate.net/cannonfodder/download.php?id=StudioCompilerSetup.V0.4A.exe] (only necessary if your weapon don't got the ACT_VM_IDLE_LOWERED animation!)}}
{{note|1=Download the Studio Compiler here [http://www.chaosincarnate.net/cannonfodder/download.php?id=StudioCompilerSetup.V0.4A.exe] (only necessary if your weapon don't got the ACT_VM_IDLE_LOWERED animation!)}}


Line 67: Line 67:
===BASECOMBATWEAPON_SHARED.H===
===BASECOMBATWEAPON_SHARED.H===


Add these member variables under private at line 466 below '''CNetworkVar( CBaseCombatCharacterHandle, m_hOwner ); // Player carrying this weapon''':
Add these declarations under public at line 181 below '''bool IsViewModelSequenceFinished( void ); // Returns if the viewmodel's current animation is finished''':
<source lang=cpp>
<source lang=cpp>



Revision as of 13:38, 10 August 2011

This article will deal with Lowering your weapon while sprinting and disable the ability to shoot at the same time. This was based on a topic on the Steam Forums located here: [1]

Note.pngNote:This has only been tested with the latest HL2MP OB engine code.
Note.pngNote:This will not work if your weapon doesn't have the ACT_VM_IDLE_LOWERED animation in its .qc file (The Viewmodel). To fix this install Studio Compiler and decompile your Viewmodel and decompile one of your other models which has this animation, then add that animation into your decompiled .qc file. To find out how to add the animation just copy the animation from the working viewmodel .qc file.
Note.pngNote:If your weapon_yourweaponname.cpp has an ItemPostFrame in it overriding the base ItemPostFrame then you have to place this code in there as well, for example in the weapon_shotgun.cpp, it has an ItemPostFrame overriding the Basecombatweapon_Shared ItemPostFrame which means that the lowering weapon code will not work for this weapon, unless you add this code in the weapon's ItemPostFrame function! Remember to put the Basecombatweapon_Share.h declarations under public so that you can make use of these variables in other files, like the weapon_shotgun.cpp's ItemPostFrame, if you don't do this you will get undeclared identifier errors
Note.pngNote:Download the Studio Compiler here [2] (only necessary if your weapon don't got the ACT_VM_IDLE_LOWERED animation!)

The Code

Note.pngNote:In this Tutorial you will do this by coding only, so open up your basecombatweapon_shared.cpp and basecombatweapon_shared.h

BASECOMBATWEAPON_SHARED.CPP

Hit CTRL+F and search for this code:

void CBaseCombatWeapon::ItemPostFrame( void )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
	if (!pOwner)
		return;

Then copy and paste this below it:

if ( !bLowered && (pOwner->m_nButtons & IN_SPEED ) )
{
	bLowered = true;
	SendWeaponAnim( ACT_VM_IDLE_LOWERED );
	m_fLoweredReady = gpGlobals->curtime + GetViewModelSequenceDuration();
}
else if ( bLowered && !(pOwner->m_nButtons & IN_SPEED ) )
{
	bLowered = false;
	SendWeaponAnim( ACT_VM_IDLE );
	m_fLoweredReady = gpGlobals->curtime + GetViewModelSequenceDuration();
}

if ( bLowered )
{
	if ( gpGlobals->curtime > m_fLoweredReady )
	{
		bLowered = true;
		SendWeaponAnim( ACT_VM_IDLE_LOWERED );
		m_fLoweredReady = gpGlobals->curtime + GetViewModelSequenceDuration();
	}
	return;
}
else if ( bLowered )
{
	if ( gpGlobals->curtime > m_fLoweredReady )
	{
		bLowered = false;
		SendWeaponAnim( ACT_VM_IDLE );
		m_fLoweredReady = gpGlobals->curtime + GetViewModelSequenceDuration();
	}
	return;
}

BASECOMBATWEAPON_SHARED.H

Add these declarations under public at line 181 below bool IsViewModelSequenceFinished( void ); // Returns if the viewmodel's current animation is finished:

		bool                    m_bLowered;
		bool                    bLowered;
		float                   m_fLowered;
		float                   m_fLoweredReady;

Finish

Now your weapon should be lowered when you hit the sprint button and you will not be available to shoot either until you release the button!