#include <amxmodx>
#include <hamsandwich>
#include <reapi>
/*~ ↓ Поддержка "кастомных" моделей. ( Раскомментируйте чтобы использовать ) ↓ ~*/
//#define CUSTOM_MODEL
#if defined CUSTOM_MODEL
/*~ ↓ Модель. ↓ ~*/
new const MODEL[ ] = "models/quick_strike.mdl";
/*~ ↓ Номер анимации. ↓ ~*/
const ANIM = 0;
/*~ ↓ Продолжительность анимации. ( Frames/FPS ) ↓ ~*/
#define ANIM_DURATION 24.0 / 30.0
public plugin_precache() precache_model( MODEL );
#endif
public plugin_init()
{
register_plugin( "Quick Strike", "1.1", "Ruby" );
RegisterKeyPressed(IN_USE, "OnHandler");
}
public OnHandler(const id, const fwid, const bool: pressed) {
// if(!g_bIsEnabledInUse) return;
if (pressed) CPlayer__UseEmpty_Post(id);
}
public CPlayer__UseEmpty_Post( const pPlayer )
{
new pActiveItem = get_member( pPlayer, m_pActiveItem );
if ( is_nullent( pActiveItem ) || get_member( pActiveItem, m_iId ) == WEAPON_KNIFE )
return;
new pKnife = rg_find_weapon_bpack_by_name( pPlayer, "weapon_knife" );
if ( is_nullent( pKnife ) )
return;
rg_switch_weapon( pPlayer, pKnife );
ExecuteHam( Ham_Weapon_PrimaryAttack, pKnife );
new Float: flAnimTime = get_member( pKnife, m_Weapon_flNextPrimaryAttack );
#if defined CUSTOM_MODEL
set_entvar( pPlayer, var_viewmodel, MODEL );
UTIL_SendWeaponAnim( pPlayer, ANIM );
flAnimTime = ANIM_DURATION;
#endif
SetThink( pActiveItem, "CWeapon__Think" );
set_entvar( pActiveItem, var_nextthink, get_gametime( ) + flAnimTime );
}
public CWeapon__Think( const pActiveItem )
{
rg_switch_weapon( get_entvar( pActiveItem, var_owner ), pActiveItem );
SetThink( pActiveItem, "" );
}
stock UTIL_SendWeaponAnim( const pPlayer, const iAnim )
{
set_entvar( pPlayer, var_weaponanim, iAnim );
message_begin( MSG_ONE, SVC_WEAPONANIM, .player = pPlayer );
write_byte( iAnim );
write_byte( 0 );
message_end( );
}