Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/sites/a/ on line 20
Wavelength | Your Game Editing Resource | Dynamic NPC Stepping Sound
Welcome, Guest! Login | Register

Dynamic NPC Stepping Sound [Print this Article]
Posted by: ts2do
Date posted: Jan 31 2005
User Rating: N/A
Number of views: 8447
Number of comments: 0
Description: Replace default set of NPC stepping sounds with the set from the texture they're walking on.
First of all, open up monsters.cpp and add the following code before line 2623:
void CBaseMonster :: HandleAnimEvent( MonsterEvent_t *pEvent )
Much of the code below is just copied and revised from player movement code
some of it was from ricochet sound code
fvol is the volume of the step
 CODE (C++) 
extern "C" char PM_FindTextureType(char *name);
void NPC_Step(CBaseMonster *pMonster)
    char chTextureType;
    float fvol;
    char szbuffer[64];
    const char *pTextureName;
    TraceResult ptr;
    float fattn = ATTN_NORM;

    UTIL_TraceLine(pMonster->pev->origin + Vector(0, 0, 8), pMonster->pev->origin - Vector(0, 0, 16),dont_ignore_monsters,ENT(pMonster->pev),&ptr);
    CBaseEntity *pEntity = CBaseEntity::Instance(ptr.pHit);

    chTextureType = 0;
        pTextureName = TRACE_TEXTURE( ENT(pEntity->pev), pMonster->pev->origin + Vector(0, 0, 8), pMonster->pev->origin - Vector(0, 0, 16) );
        pTextureName = TRACE_TEXTURE( ENT(0), pMonster->pev->origin + Vector(0, 0, 8), pMonster->pev->origin - Vector(0, 0, 16) );
    if ( pTextureName )
        // strip leading '-0' or '+0~' or '{' or '!'
        if (*pTextureName == '-' || *pTextureName == '+')
            pTextureName += 2;

        if (*pTextureName == '{' || *pTextureName == '!' || *pTextureName == '~' || *pTextureName == ' ')
        // '}}'
        strcpy(szbuffer, pTextureName);
        szbuffer[CBTEXTURENAMEMAX - 1] = 0;

        // get texture type
        chTextureType = PM_FindTextureType((char *)pTextureName);

    //---- custom code -----

Here's volume choice --- this includes customized NPC volumes:
 CODE (C++) 
else if(FClassnameIs(pMonster,"monster_zombie"))
        case ACT_WALK:
        case ACT_RUN:
        case ACT_DANCE://this would be any other animation that could call the npc step to play
else fvol = (pMonster->m_Activity ==ACT_WALK)?0.3: 0.5;

the above line which is the walk detection that changes the volume is used so the players can differentiate between the two

Here's the sound choice:
 CODE (C++) 
char plSound[32];
        case CHAR_TEX_METAL:
            plSound = "zombie/zo_metal1.wav";
               An example override sound
               of course if you wanted only SOME of them to be overriden, you must copy the cases from the switch below to it
               if you left it how it is now, itd only make step sounds for metal
               of course you could always put an if into the default switch way down there so it overrides ONLY chosen ones

    switch (chTextureType)
    case CHAR_TEX_METAL:
        switch(RANDOM_LONG(0, 3))
            case 0: plSound = "player/pl_metal1.wav";
            //all the way to pl_metal4
    default://leave default so plSound will never be a blank string
    //concrete is taken care of anyway if left out >>>case CHAR_TEX_CONCRETE:
        switch(RANDOM_LONG(0, 3))
            case 0: plSound = "player/pl_step1.wav";
            //all the way to pl_step4

Basically using the setup I made in the above switch, you can make a case for each below. You can use any wav u want AS LONG AS IT'S PRECACHED. These are listed with what would go in the case then the wav:
each wav take player/THISSPOT(1 to 4).wav in the name






Use UTIL_EmitAmbientSound to emit the sound plSound from ENT(0) and with volume fvol so it wont take up the monster's channel and itll be the chosen volume

If you want to make a new script for your custom models, this is what you would do
Now, open up scriptevent.h and add the following before line 29: #endif
This can be ANY number other than script numbers that are already taken:
 CODE (C++) 
#define SCRIPT_EVENT_STEP 2000

Now go back to monsters.cpp and add the following case in the select in the HandleAnimEvent on line 2623
This is our custom step event, which you will need to add event 2000 into frames of your custom:
 CODE (C++) 

If you want to change it so old models use the dynamic sounds:
Change the whole block from case SCRIPT_EVENT_SOUND: to break; to:

Check if the wav of the event is the step sound, if it is, override it with our new code, else just play it
 CODE (C++) 
case SCRIPT_EVENT_SOUND:            // Play a named wave file
    if(FStrEq(pEvent->options,"common/npc_step1.wav"))//||etc all the way to "npc_step4")
    else EMIT_SOUND( edict(), CHAN_BODY, pEvent->options, 1.0, ATTN_IDLE );

If you want to have hgrunts have their own step sound, you gotta add the event in to the model
To make the steps even more 1337, you can go so far as making 2 events, one for left, and one for right (this'd depend on the model calling them correctly)

Rate This Article
This article has not yet been rated.

You have to register to rate this article.
User Comments

No User Comments

You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 05 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005

Latest Comments
knock knock
General | News
By: MIFUNE | Dec 31 2017
knock knock
General | News
By: omega | Dec 22 2016
knock knock
General | News
By: MIFUNE | Oct 10 2015
New HL HUD Message System
Half-Life | Coding | Shared Tutorials
By: chbrules | Dec 31 2011
knock knock
General | News
By: Whistler | Nov 05 2011
Particle Engine tutorial part 4
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 18 2010
Particle Engine tutorial part 2
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
Particle Engine tutorial part 3
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
Game Movement Series #2: Analog Jumping and Floating
Half-Life 2 | Coding | Shared Tutorials
By: mars3554 | Oct 26 2009
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Deadpool | Aug 02 2009

Site Info
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (4 guests)
About - Credits - Contact Us

Wavelength version:
Valid XHTML 1.0! Valid CSS!