Cstrike: cs_set_weapon_silen - Add a new value for draw_animation to follow game behavior

- Player's model sequence will be properly played
- Disallow firing while animation is playing
This commit is contained in:
Arkshine 2015-07-04 19:50:57 +02:00
parent 87d740b92a
commit 7842d0160b
2 changed files with 62 additions and 6 deletions

View File

@ -189,18 +189,19 @@ static cell AMX_NATIVE_CALL cs_set_weapon_silenced(AMX *amx, cell *params)
CHECK_NONPLAYER(index);
edict_t *pWeapon = INDEXENT(index);
bool draw_animation = true;
int draw_animation = 1;
if ((params[0] / sizeof(cell)) >= 3)
{
draw_animation = params[3] != 0;
draw_animation = params[3];
}
int weaponType = get_pdata<int>(pWeapon, m_iId);
int weaponState = get_pdata<int>(pWeapon, m_iWeaponState);
int weaponNewState = weaponState;
int animation = 0;
switch (get_pdata<int>(pWeapon, m_iId))
switch (weaponType)
{
case CSW_M4A1:
{
@ -236,9 +237,61 @@ static cell AMX_NATIVE_CALL cs_set_weapon_silenced(AMX *amx, cell *params)
{
set_pdata<int>(pWeapon, m_iWeaponState, weaponNewState);
if (draw_animation && UTIL_IsPlayer(pWeapon->v.owner))
edict_t *pPlayer = pWeapon->v.owner;
if (draw_animation > 0 && UTIL_IsPlayer(pPlayer))
{
pWeapon->v.owner->v.weaponanim = animation;
int currentWeapon = *static_cast<int *>(MF_PlayerPropAddr(ENTINDEX(pPlayer), Player_CurrentWeapon));
if (currentWeapon != weaponType)
{
return 1;
}
pPlayer->v.weaponanim = animation;
if (draw_animation >= 2)
{
// Skip if cl_lw client cvar (client-side weapon firing prediction) is set.
// Technically, this should be associated to UseDecrement(), but it's true by default in game at compilation.
if (!ENGINE_CANSKIP(pPlayer))
{
MESSAGE_BEGIN(MSG_ONE, SVC_WEAPONANIM, nullptr, pPlayer);
WRITE_BYTE(animation);
WRITE_BYTE(pWeapon->v.body);
MESSAGE_END();
}
GET_OFFSET("CBasePlayer", m_szAnimExtention);
GET_OFFSET("CBasePlayerWeapon", m_flTimeWeaponIdle);
GET_OFFSET("CBasePlayerWeapon", m_flNextSecondaryAttack);
GET_OFFSET("CBasePlayerWeapon", m_flNextPrimaryAttack);
char animExt[12];
float time;
switch (weaponType)
{
case CSW_M4A1:
{
strcpy(animExt, "rifle");
time = 2.0f;
break;
}
case CSW_USP:
{
strcpy(animExt, "onehanded");
time = 3.0f;
break;
}
}
set_pdata<const char*>(pPlayer, m_szAnimExtention, STRING(MAKE_STRING(animExt)));
set_pdata<float>(pWeapon, m_flTimeWeaponIdle, time);
set_pdata<float>(pWeapon, m_flNextSecondaryAttack, time);
set_pdata<float>(pWeapon, m_flNextPrimaryAttack, time);
}
}
return 1;

View File

@ -698,9 +698,12 @@ native cs_get_weapon_silen(index);
* @param index Weapon entity index
* @param silence If nonzero the weapon will be put into silenced
* mode, otherwise the silenced mode will be removed
* @param draw_animation If nonzero and the weapon is currently held by a
* @param draw_animation If 1 and the weapon is currently held by a
* client, the appropriate weapon animation will be
* played
* If 2, same as 1 but follows game behavior by playing
* the associated player's model sequence and disallowing
* firing while animation is playing.
*
* @return 1 if silenced mode set successfully, 0 if entity is
* not an applicable weapon