Lowering your weapon on sprint: Difference between revisions
mNo edit summary |
|||
Line 82: | Line 82: | ||
{{note|1=}} | |||
To fix a bug that allows the player to queue shots while holding sprint and fire them all at one upon release, add | |||
<source lang = cpp> | |||
m_flNextPrimaryAttack = m_fLoweredReady; | |||
</source> | |||
after every occurrence of | |||
<source lang = cpp> | |||
m_fLoweredReady = gpGlobals->curtime + GetViewModelSequenceDuration(); | |||
</source> | |||
This will prevent the player from firing while the lowered idle sequence is playing. | |||
[[Category:Weapons programming]] {{DISPLAYTITLE:Lowering your weapon on sprint}} | [[Category:Weapons programming]] {{DISPLAYTITLE:Lowering your weapon on sprint}} | ||
[[Category:Tutorials]] | [[Category:Tutorials]] |
Revision as of 17:01, 25 November 2012
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




The Code

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!
Note:
To fix a bug that allows the player to queue shots while holding sprint and fire them all at one upon release, add
m_flNextPrimaryAttack = m_fLoweredReady;
after every occurrence of
m_fLoweredReady = gpGlobals->curtime + GetViewModelSequenceDuration();
This will prevent the player from firing while the lowered idle sequence is playing.