Code:
#include <amxmodx>
#include <fakemeta>
#include <fun>
#define PLUGIN "CSGOM: Step Sound"
#define VERSION "1.0"
#define AUTHOR "EFFEX"
#define STEP_DELAY 0.3
#define MIN_SPEED 150
new Float:g_fNextStep[33]
new const g_szStepSounds[][] =
{
"csgom/player/pl_gravel1.wav",
"csgom/player/pl_gravel2.wav",
"csgom/player/pl_gravel3.wav",
"csgom/player/pl_gravel4.wav"
}
new const g_szWoodSounds[][] =
{
"csgom/player/pl_wood1.wav",
"csgom/player/pl_wood2.wav",
"csgom/player/pl_wood3.wav",
"csgom/player/pl_wood4.wav"
}
new const g_szTileSounds[][] =
{
"csgom/player/pl_tile1.wav",
"csgom/player/pl_tile2.wav",
"csgom/player/pl_tile3.wav",
"csgom/player/pl_tile4.wav"
}
new const g_szMetalSounds[][] =
{
"csgom/player/pl_metal1.wav",
"csgom/player/pl_metal2.wav",
"csgom/player/pl_metal3.wav",
"csgom/player/pl_metal4.wav"
}
new const g_szDirtSounds[][] =
{
"csgom/player/pl_dirt1.wav",
"csgom/player/pl_dirt2.wav",
"csgom/player/pl_dirt3.wav",
"csgom/player/pl_dirt4.wav"
}
new const g_szSnowSounds[][] =
{
"csgom/player/pl_snow1.wav",
"csgom/player/pl_snow2.wav",
"csgom/player/pl_snow3.wav",
"csgom/player/pl_snow4.wav"
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
}
public plugin_precache()
{
for(new i; i < sizeof g_szStepSounds ; i++)
precache_sound(g_szStepSounds[i])
for(new i; i < sizeof g_szWoodSounds ; i++)
precache_sound(g_szWoodSounds[i])
for(new i; i < sizeof g_szTileSounds ; i++)
precache_sound(g_szTileSounds[i])
for(new i; i < sizeof g_szMetalSounds ; i++)
precache_sound(g_szMetalSounds[i])
for(new i; i < sizeof g_szDirtSounds ; i++)
precache_sound(g_szDirtSounds[i])
for(new i; i < sizeof g_szSnowSounds ; i++)
precache_sound(g_szSnowSounds[i])
}
public client_PreThink(id)
{
if (!(pev(id, pev_flags) & FL_ONGROUND))
return PLUGIN_HANDLED
static Float:start[3]
pev(id, pev_origin, start)
static Float:dest[3]
dest[0] = start[0]
dest[1] = start[1]
dest[2] = -8191.0
new tr
engfunc(EngFunc_TraceLine, start, dest, 0, id, tr)
static texent
texent = get_tr2(tr, TR_pHit)
if (texent == -1)
texent = 0
else if (is_user_alive(texent))
return PLUGIN_HANDLED
static texname[16]
engfunc(EngFunc_TraceTexture, texent, start, dest, texname, 15)
static textype[2], szSound[64]
textype[0] = dllfunc(DLLFunc_PM_FindTextureType, texname)
switch(textype[0])
{
case 'M', 'V': // - metal
{
copy(szSound, charsmax(szSound), g_szMetalSounds[random_num(0, sizeof g_szMetalSounds - 1)])
}
case 'D': // - dirt
{
copy(szSound, charsmax(szSound), g_szDirtSounds[random_num(0, sizeof g_szDirtSounds - 1)])
}
case 'T': // - tile
{
copy(szSound, charsmax(szSound), g_szTileSounds[random_num(0, sizeof g_szTileSounds - 1)])
}
case 'W': // - wood
{
copy(szSound, charsmax(szSound), g_szWoodSounds[random_num(0, sizeof g_szWoodSounds - 1)])
}
case 'N': // - snow
{
copy(szSound, charsmax(szSound), g_szSnowSounds[random_num(0, sizeof g_szSnowSounds - 1)])
}
case 'C', 'X':
{
copy(szSound, charsmax(szSound), g_szStepSounds[random_num(0, sizeof g_szStepSounds - 1)])
}
}
if(szSound[0])
{
set_pev(id, pev_flTimeStepSound, 999)
}
if(g_fNextStep[id] < get_gametime())
{
if((fm_get_ent_speed(id) > MIN_SPEED) && (pev(id, pev_flags) & FL_ONGROUND))
{
emit_sound(id, CHAN_BODY, szSound, VOL_NORM, ATTN_STATIC, 0, PITCH_NORM)
g_fNextStep[id] = get_gametime() + STEP_DELAY
}
}
return PLUGIN_HANDLED
}
Float:fm_get_ent_speed(id)
{
if(!pev_valid(id))
return 0.0
static Float:vVelocity[3]
pev(id, pev_velocity, vVelocity)
vVelocity[2] = 0.0
return vector_length(vVelocity)
}