menu_foot
potm_left potm_top
Soul Keep
potm_btm
potm_right
head_right
QuakeDev Forums -> Engines -> Quake1 Engine/QC -> Tutorials -> Topic: DarkPlaces | QC | Footsteps by DarkSnow « previous next »
Pages: [1] Print
Author Topic: DarkPlaces | QC | Footsteps by DarkSnow  (Read 5625 times)
DarkSnow
Poster

Posts: 464


*sniff sniff*


DarkPlaces | QC | Footsteps by DarkSnow
« on: April 14, 2005, 01:56:40 AM »

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 Cheesy

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 Smiley

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 Smiley

Credits
LordHavoc :: Engine and the extensions
Ze0 :: Footsteps Tutorial on Inside3D
MauveBib :: Mentioned the extention
Me :: Experimenting and writing about it
« Last Edit: August 20, 2005, 01:38:08 AM by Echon » Logged

- Quake is good for the brain.
Justin Thyme
Poster

Posts: 872



Re: DarkPlaces | QC | Footsteps
« Reply #1 on: April 14, 2005, 02:53:11 PM »

Very neat!  I need to get more work done on adding more DP extensions.
Logged

----------------------------------------
Justin Thyme
http://tremor.quakedev.com
DarkSnow
Poster

Posts: 464


*sniff sniff*


Re: DarkPlaces | QC | Footsteps
« Reply #2 on: April 14, 2005, 03:04:39 PM »

Very neat!  I need to get more work done on adding more DP extensions.

Yeah, Tei on QSG forum wanted this stuff in to sound when shooting at walls and that it would be cooler.. So i posted that tutor over at QSG with a video aswell

video

Its not amazing but i think these stuff elevates the feeling of playing a game Smiley
Logged

- Quake is good for the brain.
fleshhold
Poster

Posts: 31



Re: DarkPlaces | QC | Footsteps
« Reply #3 on: July 18, 2005, 08:27:25 PM »

A good idea if you are creating a TC:

Establish a texture naming convention beforehand. For example decide to put an 'M' at the beginning of every texture that should sound like metal, 'W' for wood-sounding textures, 'P' for squishy poop, etc.

So you have such things as:
Mmetal1_1
Mwizmetal
Mmoremetal
Wfloorpanels
Wwoodendoor
Pcowpie
Psewage1

etc., then you can use such code to check:

s = getsurfacetexture (world, surfnum);
s = substring (s, 0, 1);
if (s == "M")
{
// play metal sounds
}
else if (s == "W")
{
// play wood sounds
}
else if (s == "P")
{
// play poop sounds
}
else
{
// play generic sounds
}
Logged
DarkSnow
Poster

Posts: 464


*sniff sniff*


Re: DarkPlaces | QC | Footsteps
« Reply #4 on: July 26, 2005, 01:53:25 AM »

Yea, the idea have been mentioned before. But its realy the bsp that needs some adjustment instead "we" concluded, so you should not even have to get the texture name but a set flag for the surface instead. Offcorse, this i wrote is the easiest way to get it done quick Wink
Logged

- Quake is good for the brain.
Pages: [1] Print 
QuakeDev Forums -> Engines -> Quake1 Engine/QC -> Tutorials -> Topic: DarkPlaces | QC | Footsteps by DarkSnow « previous next »
Jump to:  
Powered by SMF 1.1.8 | SMF © 2006-2008, Simple Machines LLC
Page created in 0.237 seconds with 31 queries.