Not sure what your intentions are or if this is what you're looking for but I figured I would take a stab at it without using prethink (which may be the best way). Are you trying to hook every time a player lands or only if he lands hard and takes damage? If the first, then my code will work 95% of the time. The only downfall is I am able to avoid the sound if I'm standing on a ledge and press a move button only briefly resulting in the player falling off and landing. If you are only looking to hook when falling from a distance and where damage is taken then you can do this easily by hooking FM_EmitSound.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <engine>
new const Version[] = "0.1";
new const g_szLandSound[] = "player/sprayer.wav";
const BUTTONS = ( IN_FORWARD | IN_BACK | IN_MOVELEFT | IN_MOVERIGHT | IN_JUMP );
new g_OffGround , g_LandEntity , g_iMaxPlayers;
public plugin_init()
{
register_plugin( "Hook Landing" , Version , "bugsy" );
register_forward( FM_CmdStart , "fw_FMCmdStart" );
g_iMaxPlayers = get_maxplayers();
}
public fw_FMCmdStart( id , uc_handle , seed )
{
if ( ( get_uc( uc_handle , UC_Buttons ) | pev( id , pev_oldbuttons ) ) & BUTTONS )
{
if ( !( pev( id , pev_flags ) & FL_ONGROUND ) )
{
g_OffGround |= ( 1 << ( id & 31 ) );
if ( !g_LandEntity )
CreateLandEntity();
entity_set_float( g_LandEntity , EV_FL_nextthink , get_gametime() + 0.01 );
}
}
}
public LandEntityThink( iEntity )
{
for ( new id = 1 ; id <= g_iMaxPlayers ; id++ )
{
if ( g_OffGround & ( 1 << ( id & 31 ) ) )
{
if ( pev( id , pev_flags ) & FL_ONGROUND )
{
emit_sound( id , CHAN_BODY , g_szLandSound , VOL_NORM , ATTN_NORM , 0 , PITCH_NORM );
g_OffGround &= ~( 1 << ( id & 31 ) );
if ( !g_OffGround )
break;
}
}
}
if ( g_OffGround )
entity_set_float( g_LandEntity , EV_FL_nextthink , get_gametime() + 0.01 );
}
CreateLandEntity()
{
g_LandEntity = create_entity( "info_target" );
entity_set_string( g_LandEntity , EV_SZ_classname , "land_entity" );
register_think( "land_entity" , "LandEntityThink" );
}
__________________