by Freemanoid » Thu Jun 26, 2008 6:03 pm
I see tutorial in QuakeDev, by DarkSnow.
Maby this help you :
Difficulity: Easy/Human readable
For: DarkPlaces (Quake1)
Alright, after a long conversation with LordHavoc the pieces of the puzzle finaly came together. About 5 minutes ago i tweaked around the last parts of the code and as by a miracle it worked superb
The following code is qc only, for darkplaces engine. If you want this in your own engine then you will have to copy various stuff from darkplaces to make it work.
When you walk around, you will hear a generic footstep sound, until you walk on metal - and *poff* - you will her footsteps on metal insted of generic, without using triggers in the map. It checks what texture the player is standing on basicly, and if it is (for this snippet) the wizmetal texture (normal skill bridge map "start") the sound will be walk/metal1*4 instead of generic.
So if anyone havent gotten this to work yet, but want it - here it is
player.qc
add the following code before void player_run
Code:
void(entity e) walksound ={
local float surfnum, r;
local string s;
makevectors(e.v_angle);
surfnum = getsurfacenearpoint(world, e.origin - '0 0 24');
if (surfnum >= 0)
{
s = getsurfacetexture(world, surfnum);
if (s == "wizmet1_2")
{
bprint("play metal\n");
r = rint(random() * 3);
if (r == 0)
sound (e, CHAN_AUTO, "walk/metal1.wav", 0.5, ATTN_NORM);
else if (r == 1)
sound (e, CHAN_AUTO, "walk/metal2.wav", 0.5, ATTN_NORM);
else if (r == 2)
sound (e, CHAN_AUTO, "walk/metal3.wav", 0.5, ATTN_NORM);
else
sound (e, CHAN_AUTO, "walk/metal4.wav", 0.5, ATTN_NORM);
}
else
{
bprint("play generic\n");
r = rint(random() * 4);
if (r == 0)
sound (e, CHAN_AUTO, "walk/generic1.wav", 0.5, ATTN_NORM);
else if (r == 1)
sound (e, CHAN_AUTO, "walk/generic2.wav", 0.5, ATTN_NORM);
else if (r == 2)
sound (e, CHAN_AUTO, "walk/generic3.wav", 0.5, ATTN_NORM);
else if (r == 3)
sound (e, CHAN_AUTO, "walk/generic4.wav", 0.5, ATTN_NORM);
else
sound (e, CHAN_AUTO, "walk/generic5.wav", 0.5, ATTN_NORM);
}
}
};
This is the interesting part all in all. First the code "contacts" the game engine and recive the name of the texture the player is standing on. If that texture is named "wizmet1_2" it will play one of the metal sounds, else it will play one of the generic sounds.
in void player_run find
Code:
void() player_run =[ $rockrun1, player_run ]
{
and add the following code directly after it
Code:
if (self.walkframe == 1 || self.walkframe == 4 )
if (checkbottom(self) == TRUE)
if (self.waterlevel == 0)
walksound (self);
world.qc
find
Code:
precache_sound ("misc/water1.wav"); // swimming
precache_sound ("misc/water2.wav"); // swimming
and add after that
Code:
precache_sound ("walk/generic1.wav");
precache_sound ("walk/generic2.wav");
precache_sound ("walk/generic3.wav");
precache_sound ("walk/generic4.wav");
precache_sound ("walk/generic5.wav");
precache_sound ("walk/metal1.wav");
precache_sound ("walk/metal2.wav");
precache_sound ("walk/metal3.wav");
precache_sound ("walk/metal4.wav");
defs.qc
in bottom of defs.qc add
Code:
//DP_QC_GETSURFACE
//idea: LordHavoc
//darkplaces implementation: LordHavoc
//builtin definitions:
float(entity e, float s) getsurfacenumpoints = #434;
vector(entity e, float s, float n) getsurfacepoint = #435;
vector(entity e, float s) getsurfacenormal = #436;
string(entity e, float s) getsurfacetexture = #437;
float(entity e, vector p) getsurfacenearpoint = #438;
vector(entity e, float s, vector p) getsurfaceclippedpoint = #439;
//description:
//functions to query surface information.
(or use dpmods own extensions qc file)
The final thing,
you have to create a new folder - \modname\sound\walk
and add the sound files there. (sound files from half-life - copyright)
There is room for improvements
Credits
LordHavoc :: Engine and the extensions
Ze0 :: Footsteps Tutorial on Inside3D
MauveBib :: Mentioned the extention
Me :: Experimenting and writing about it
^O,..,o^