2016-12-02 18:45:59 +00:00
|
|
|
/*
|
2018-06-14 10:05:23 +00:00
|
|
|
Copyright 2016-2018 Marco "eukara" Hladik
|
|
|
|
|
|
|
|
MIT LICENSE
|
2016-12-02 18:45:59 +00:00
|
|
|
|
2018-06-14 10:05:23 +00:00
|
|
|
Permission is hereby granted, free of charge, to any person
|
|
|
|
obtaining a copy of this software and associated documentation
|
|
|
|
files (the "Software"), to deal in the Software without
|
|
|
|
restriction, including without limitation the rights to use,
|
|
|
|
copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
sell copies of the Software, and to permit persons to whom the
|
|
|
|
Software is furnished to do so, subject to the following conditions:
|
2016-12-02 18:45:59 +00:00
|
|
|
|
2018-06-14 10:05:23 +00:00
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
2016-12-02 18:45:59 +00:00
|
|
|
|
2018-06-14 10:05:23 +00:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE.
|
2016-12-02 18:45:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Footsteps_Update
|
|
|
|
|
2017-01-10 18:24:45 +00:00
|
|
|
Run every frame for each player, plays material based footsteps
|
2016-12-02 18:45:59 +00:00
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Footsteps_Update( void ) {
|
|
|
|
float fForce;
|
2017-01-07 16:29:27 +00:00
|
|
|
float fDelay;
|
2016-12-02 18:45:59 +00:00
|
|
|
vector vStep;
|
2017-01-03 22:25:27 +00:00
|
|
|
string sStepSound = "";
|
2016-12-02 18:45:59 +00:00
|
|
|
|
|
|
|
if ( ( self.movetype == MOVETYPE_WALK ) && ( self.flags & FL_ONGROUND ) ) {
|
2017-01-14 15:00:31 +00:00
|
|
|
if ( ( self.velocity_x == 0 && self.velocity_y == 0 ) || self.fStepTime > time ) {
|
2016-12-02 18:45:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-17 21:20:51 +00:00
|
|
|
if ( vlen( self.velocity ) < 150 ) {
|
2017-11-13 00:43:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-02 18:45:59 +00:00
|
|
|
vStep_x = fabs( self.velocity_x );
|
|
|
|
vStep_y = fabs( self.velocity_y );
|
|
|
|
|
|
|
|
fForce = ( vStep_x + vStep_y );
|
2017-11-13 00:43:16 +00:00
|
|
|
fDelay = clamp( 0.1, 1 / ( fForce / 90 ), 1 );
|
2016-12-02 18:45:59 +00:00
|
|
|
|
|
|
|
traceline( self.origin + self.view_ofs, self.origin + '0 0 -48', FALSE, self );
|
2017-01-03 22:25:27 +00:00
|
|
|
|
|
|
|
string sTexture = getsurfacetexture( trace_ent, getsurfacenearpoint( trace_ent, trace_endpos ) );
|
|
|
|
|
|
|
|
switch( (float)hash_get( hashMaterials, sTexture ) ) {
|
|
|
|
case 'M':
|
|
|
|
sStepSound = sprintf( "player/pl_metal%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
sStepSound = sprintf( "player/pl_duct%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
sStepSound = sprintf( "player/pl_dirt%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
sStepSound = sprintf( "player/pl_slosh%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
sStepSound = sprintf( "player/pl_tile%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
sStepSound = sprintf( "player/pl_grate%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
sStepSound = sprintf( "player/pl_step%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
sStepSound = sprintf( "player/pl_step%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 'Y':
|
|
|
|
sStepSound = sprintf( "player/pl_step%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
sStepSound = sprintf( "player/pl_snow%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sStepSound = sprintf( "player/pl_step%d.wav", floor( ( random() * 4 ) + 1 ) );
|
|
|
|
break;
|
|
|
|
}
|
2016-12-02 18:45:59 +00:00
|
|
|
|
2017-01-03 22:25:27 +00:00
|
|
|
sound( self, CHAN_BODY, sStepSound, 0.5, ATTN_IDLE );
|
2017-01-14 15:00:31 +00:00
|
|
|
self.fStepTime = time + fDelay;
|
2016-12-02 18:45:59 +00:00
|
|
|
}
|
|
|
|
}
|