Code:
#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
const m_pPlayer = 41;
const m_fInReload = 54;
const m_fInSpecialReload = 55;
const m_flTimeWeaponIdle = 48;
public plugin_init( )
{
// 2 = CSW_SHIELD = UNDEFINED | PUT SHOTGUNS HERE TO SKIP IN LOOP AND REGISTER MANUALLY
new const NO_RELOAD = ( 1 << 2 ) | ( 1 << CSW_KNIFE ) | ( 1 << CSW_C4 ) | ( 1 << CSW_M3 ) |
( 1 << CSW_XM1014 ) | ( 1 << CSW_HEGRENADE ) | ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE );
new szWeaponName[ 20 ];
for( new i = CSW_P228; i <= CSW_P90; i++ )
{
// If its no-reload weapon or shotgun skip it
if( NO_RELOAD & ( 1 << i ) )
{
continue;
}
// Get weapon name
get_weaponname( i, szWeaponName, 19 );
// Register forward
RegisterHam( Ham_Weapon_Reload, szWeaponName, "FwdHamWeaponReload", 1 );
}
// Register shotguns, we need different function for additional checks
RegisterHam( Ham_Weapon_Reload, "weapon_m3", "FwdHamShotgunReload", 1 );
RegisterHam( Ham_Weapon_Reload, "weapon_xm1014", "FwdHamShotgunReload", 1 );
}
public FwdHamWeaponReload( const iWeapon )
{
// m_fInReload is set to TRUE in DefaultReload( )
// We are only checking if this offset is set to true because
// Ham_Weapon_Reload is being called as long as player holds the reload key
// But its only called once if weapon is being reloaded, and doesnt call more while its reloading
if( get_pdata_int( iWeapon, m_fInReload, 4 ) )
{
// Weapon has started reload
// To check if its reload by player or auto (0 ammo) you can do this:
// Check !( get_user_button( id ) & IN_BUTTON )
// Or check if clip ammo equals to 0
}
}
public FwdHamShotgunReload( const iWeapon )
{
// in Reload( ) there is switch of this offset
// On case 0 it is being set to 1 and some weapon idle/nextattacks are being set to 0.55
// case 1: bullet input animation
// case 2: adding bullet to clip itself
// this case 1-2-1 is being looped while the shotgun is reloading
if( get_pdata_int( iWeapon, m_fInSpecialReload, 4 ) != 1 )
{
return;
}
// If you will remove the check below, you will be able to hook when engine
// sets animation (M3_INSERT) bullet
// The first set of m_fInSpecialReload to 1. m_flTimeWeaponIdle remains 0.55 set from Reload( )
new Float:flTimeWeaponIdle = get_pdata_float( iWeapon, m_flTimeWeaponIdle, 4 );
if( flTimeWeaponIdle != 0.55 )
{
return;
}
// Shotgun has started reload
}