---------------------------------------------------------------------------------
purpose: adds footstep sounds to local gameplay.
---------------------------------------------------------------------------------
future expansion: different sounds for different surfaces and different speeds.
---------------------------------------------------------------------------------
First thing we need to do is precache the sound effects internally in the engine.
Open up cl_tent.c
near the top of the file look for the other sound effects precaches
and add these under sfx_t *cl_sfx_r_exp3,
Code: Select all
sfx_t *cl_sfx_step1;
sfx_t *cl_sfx_step2;
sfx_t *cl_sfx_step3;
sfx_t *cl_sfx_step4;
and add these precaches to be initialized.
Code: Select all
cl_sfx_step1 = S_PrecacheSound ("misc/step1.wav");
cl_sfx_step2 = S_PrecacheSound ("misc/step2.wav");
cl_sfx_step3 = S_PrecacheSound ("misc/step3.wav");
cl_sfx_step4 = S_PrecacheSound ("misc/step4.wav");
okay now open up cl_main.c
near the top around all the other cvar_t definitions add,
Code: Select all
cvar_t cl_footsteps = {"cl_footsteps", "0", true};
Code: Select all
Cvar_RegisterVariable (&cl_footsteps);
Code: Select all
void CL_Footsteps(entity_t *ent, int frame)
{
extern sfx_t *cl_sfx_step1;
extern sfx_t *cl_sfx_step2;
extern sfx_t *cl_sfx_step3;
extern sfx_t *cl_sfx_step4;
if (ent->steptime > cl.time)//Timer to sync with player animations
return;
if (ent != &cl_entities[cl.viewentity])//check if it's our player
return; //only play our OWN footsteps! no multiplayer hax!
if (TruePointContents(ent->origin) != CONTENTS_EMPTY)// if in water etc.. no sound
return;
if (frame == 2 || frame == 5 || frame == 7 || frame == 10)//check for run frames
{
vec3_t dest, forward, right,up;
trace_t trace;
float f;
int i,e;
entity_t *p;
AngleVectors (ent->angles, forward, right, up);
VectorMA (ent->origin, -32, up, dest);//trace down
memset (&trace, 0, sizeof(trace_t));
trace.fraction = 1;
SV_RecursiveHullCheck(cl.worldmodel->hulls, 0, 0, 1, ent->origin, dest, &trace);
if (trace.fraction == 1) //if we didnt hit anything solid dont make a sound
{
ent->steptime = cl.time + 0.1;//since the player model animates at 10 frames per sec, no need to come back here until time + 1/10...
return;
}
f = (rand()%4)+1;
e = (int)cl.viewentity;//emit the sound at our location
if (f == 1)
S_StartSound(e, 0, cl_sfx_step1, ent->origin, 0.40f, 1.0f);
else if (f == 2)
S_StartSound(e, 0, cl_sfx_step2, ent->origin, 0.40f, 1.0f);
else if (f == 3)
S_StartSound(e, 0, cl_sfx_step3, ent->origin, 0.40f, 1.0f);
else
S_StartSound(e, 0, cl_sfx_step4, ent->origin, 0.40f, 1.0f);
ent->steptime = cl.time + 0.3;
}
}
Code: Select all
if (cl_footsteps.value)
CL_Footsteps(ent,ent->frame);
to the end, like this
Code: Select all
double steptime;
} entity_t;