Created 3 months ago2024-08-27 00:04:11 UTC by zhushengjie
int
to CMP5's header; int m_iMaxBurst
and m_iBurst
and initialise both of these to 3 in CMP5's Spawn() method.void CMP5::PrimaryAttack()
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3)
{
PlayEmptySound();
m_flNextPrimaryAttack = 0.15;
return;
}
if (m_iClip <= 0)
{
PlayEmptySound();
m_flNextPrimaryAttack = 0.15;
return;
}
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
m_iClip--;
m_iBurst--;
// ... rest of code
At the bottom:
// ... rest of code
m_flNextPrimaryAttack = GetNextAttackDelay(0.1);
if (m_flNextPrimaryAttack < UTIL_WeaponTimeBase())
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.1;
if (m_iBurst < 1)
{
m_flNextPrimaryAttack += 0.5;
m_iBurst = m_iMaxBurst;
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
}
You'd then need to make a check if the fire button had been released in the middle of a burst to reset m_iBurst back to m_iMaxBurst.m_fInBurst
(set to false in Spawn()) that you set to true in PrimaryAttack() if m_iBurst is equal to m_iMaxBurst, and set to false if m_iBurst is zero.m_flTimeWeaponIdle
to 0.1.void CMP5::WeaponIdle()
{
if (m_fInBurst && m_iBurst > 0)
{
PrimaryAttack();
m_flTimeWeaponIdle = 0.1;
return;
}
// ... rest of code
Essentially use PrimaryAttack() to start the burst fire, and let WeaponIdle() as a loop to call PrimaryAttack() until the burst count is exhausted.