You need to login in order to create posts and topics. » Login
I can not find the code for changing the animation of HL-weapons in Pr ...

I study the principle of the operation of weapons. I cannot understand where the changing animation of the weapon is being caused during the shot.


// Code MP5
void CMP5::Precache( void )

m_iShell = PRECACHE_MODEL ("models/shell.mdl");// brass shellTE_MODEL

PRECACHE_MODEL("models/grenade.mdl"); // grenade



//Sounds of shots
PRECACHE_SOUND ("weapons/hks1.wav");
PRECACHE_SOUND ("weapons/hks2.wav");
PRECACHE_SOUND ("weapons/hks3.wav");

PRECACHE_SOUND( "weapons/glauncher.wav" );
PRECACHE_SOUND( "weapons/glauncher2.wav" );

PRECACHE_SOUND ("weapons/357_cock1.wav");

m_usMP5 = PRECACHE_EVENT( 1, "events/" );
m_usMP52 = PRECACHE_EVENT( 1, "events/" );

void CMP5::PrimaryAttack()
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3)
PlayEmptySound( );
m_flNextPrimaryAttack = 0.15;

if (m_iClip <= 0)
m_flNextPrimaryAttack = 0.15;

m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;


m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;

// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );

Vector vecSrc = m_pPlayer->GetGunPosition( );
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
Vector vecDir;

if ( !bIsMultiplayer() )
if ( !g_pGameRules->IsMultiplayer() )
// optimized multiplayer. Widened to make it easier to hit a moving player
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_6DEGREES, 8192, BULLET_PLAYER_MP5, 2, 0, m_pPlayer->pev, m_pPlayer->random_seed );
// single player spread
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_3DEGREES, 8192, BULLET_PLAYER_MP5, 2, 0, m_pPlayer->pev, m_pPlayer->random_seed );

int flags;
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
flags = 0;

PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usMP5, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0 );

if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
// HEV suit - indicate out of ammo condition
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);

m_flNextPrimaryAttack = GetNextAttackDelay(0.1);

if ( m_flNextPrimaryAttack < UTIL_WeaponTimeBase() )
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.1;

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );

BOOL CMP5:Deploy( )
return DefaultDeploy( "models/v_9mmAR.mdl", "models/p_9mmAR.mdl", MP5_DEPLOY, "mp5" );

void CMP5::Reload( void )
if ( m_pPlayer->ammo_9mm <= 0 )

DefaultReload( MP5_MAX_CLIP, MP5_RELOAD, 1.5 );


Procedure SendWeaponAnim is changing property pev->weaponanim. Procedure is called in DefaultDeploy and Reload. I think, engine is checking each animation of the weapon model (In our case - v_9mmar.mdl) contains the path to the sound file. Animation for fire of these model hasn't path to the sound file. If delete (/*commented*/) body PrimaryAttack then be playing sound fire and draw decal.

How? How does he know the path to the sound files and the number of weapons animations (This is in all the weapons of the project hldll). I can add code in PrimaryAttack procedure SendWeaponAnim and EMIT_SOUND_DYN for sound, but i'm interested in how to do better.

P.S. I'm used

I found out the answers to my questions. Maybe someone will come in handy.

Check the project hl_cdll.

Source Files->_hl->cl_dll->hl->ev_hldm.cpp.

Here are called sounds fire and more...

Glad you found it. Also Thanks for posting back with a solution 🙂

Stay in Touch

Discover the Community

Copyright © 2018
Sourcemodding is made in Ireland and brought to you by this Eejit.
All trademarks are property of their respective owners in the US and other countries.


Sourcemodding is in no way affiliated with the Valve Corporation. This a non-profit community driven website using content from myself, Valve and the Community. All files are provided as is and are simply mirrors of files that can easily be found through a smart Google/Bing/Yahoo/DuckDuckGo search. If you dispute anything on the website or want something removed please get in touch.