Changed the singleplayer animation state to only be active when the model has appropriate animations

This commit is contained in:
Blixibon 2021-11-15 16:19:27 -06:00
parent 91978b2934
commit f975e7d10d
2 changed files with 31 additions and 6 deletions

View File

@ -120,7 +120,7 @@ ConVar sv_stickysprint("sv_stickysprint", "0", FCVAR_ARCHIVE | FCVAR_ARCHIVE_XBO
ConVar player_autoswitch_enabled( "player_autoswitch_enabled", "1", FCVAR_NONE, "This convar was added by Mapbase to toggle whether players automatically switch to their ''best'' weapon upon picking up ammo for it after it was dry." ); ConVar player_autoswitch_enabled( "player_autoswitch_enabled", "1", FCVAR_NONE, "This convar was added by Mapbase to toggle whether players automatically switch to their ''best'' weapon upon picking up ammo for it after it was dry." );
#ifdef SP_ANIM_STATE #ifdef SP_ANIM_STATE
ConVar hl2_use_sp_animstate( "hl2_use_sp_animstate", "1", FCVAR_NONE, "Allows SP HL2 players to use HL2:DM animations (for custom player models)" ); ConVar hl2_use_sp_animstate( "hl2_use_sp_animstate", "1", FCVAR_NONE, "Allows SP HL2 players to use HL2:DM animations for custom player models. (changes may not apply until model is reloaded)" );
#endif #endif
#endif #endif
@ -631,8 +631,6 @@ END_SCRIPTDESC();
CHL2_Player::CHL2_Player() CHL2_Player::CHL2_Player()
{ {
#ifdef SP_ANIM_STATE #ifdef SP_ANIM_STATE
// Here we create and init the player animation state.
m_pPlayerAnimState = CreatePlayerAnimationState(this);
m_angEyeAngles.Init(); m_angEyeAngles.Init();
#endif #endif
@ -1161,7 +1159,7 @@ void CHL2_Player::PostThink( void )
} }
#ifdef SP_ANIM_STATE #ifdef SP_ANIM_STATE
if (hl2_use_sp_animstate.GetBool()) if (m_pPlayerAnimState)
{ {
m_angEyeAngles = EyeAngles(); m_angEyeAngles = EyeAngles();
@ -1385,7 +1383,7 @@ void CHL2_Player::SpawnedAtPoint( CBaseEntity *pSpawnPoint )
// Set the activity based on an event or current state // Set the activity based on an event or current state
void CHL2_Player::SetAnimation( PLAYER_ANIM playerAnim ) void CHL2_Player::SetAnimation( PLAYER_ANIM playerAnim )
{ {
if (!hl2_use_sp_animstate.GetBool()) if (!m_pPlayerAnimState)
{ {
BaseClass::SetAnimation( playerAnim ); BaseClass::SetAnimation( playerAnim );
return; return;
@ -1396,12 +1394,37 @@ void CHL2_Player::SetAnimation( PLAYER_ANIM playerAnim )
void CHL2_Player::AddAnimStateLayer( int iSequence, float flBlendIn, float flBlendOut, float flPlaybackRate, bool bHoldAtEnd, bool bOnlyWhenStill ) void CHL2_Player::AddAnimStateLayer( int iSequence, float flBlendIn, float flBlendOut, float flPlaybackRate, bool bHoldAtEnd, bool bOnlyWhenStill )
{ {
if (!hl2_use_sp_animstate.GetBool()) if (!m_pPlayerAnimState)
return; return;
m_pPlayerAnimState->AddMiscSequence( iSequence, flBlendIn, flBlendOut, flPlaybackRate, bHoldAtEnd, bOnlyWhenStill ); m_pPlayerAnimState->AddMiscSequence( iSequence, flBlendIn, flBlendOut, flPlaybackRate, bHoldAtEnd, bOnlyWhenStill );
} }
#endif #endif
//-----------------------------------------------------------------------------
// Purpose: model-change notification. Fires on dynamic load completion as well
//-----------------------------------------------------------------------------
CStudioHdr *CHL2_Player::OnNewModel()
{
CStudioHdr *hdr = BaseClass::OnNewModel();
#ifdef SP_ANIM_STATE
if ( hdr && hdr->HaveSequenceForActivity(ACT_HL2MP_IDLE) && hl2_use_sp_animstate.GetBool() )
{
// Clears the animation state if we already have one.
if ( m_pPlayerAnimState != NULL )
{
m_pPlayerAnimState->Release();
m_pPlayerAnimState = NULL;
}
// Here we create and init the player animation state.
m_pPlayerAnimState = CreatePlayerAnimationState(this);
}
#endif
return hdr;
}
#endif #endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -138,6 +138,8 @@ public:
void AddAnimStateLayer( int iSequence, float flBlendIn = 0.0f, float flBlendOut = 0.0f, float flPlaybackRate = 1.0f, bool bHoldAtEnd = false, bool bOnlyWhenStill = false ); void AddAnimStateLayer( int iSequence, float flBlendIn = 0.0f, float flBlendOut = 0.0f, float flPlaybackRate = 1.0f, bool bHoldAtEnd = false, bool bOnlyWhenStill = false );
#endif #endif
virtual CStudioHdr* OnNewModel();
virtual const char *GetOverrideStepSound( const char *pszBaseStepSoundName ); virtual const char *GetOverrideStepSound( const char *pszBaseStepSoundName );
#endif #endif