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
| | 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; if(pEntity) pTextureName = TRACE_TEXTURE( ENT(pEntity->pev), pMonster->pev->origin + Vector(0, 0, 8), pMonster->pev->origin - Vector(0, 0, 16) ); else pTextureName = TRACE_TEXTURE( ENT(0), pMonster->pev->origin + Vector(0, 0, 8), pMonster->pev->origin - Vector(0, 0, 16) ); if ( pTextureName ) { if (*pTextureName == '-' || *pTextureName == '+') pTextureName += 2;
if (*pTextureName == '{' || *pTextureName == '!' || *pTextureName == '~' || *pTextureName == ' ') pTextureName++; strcpy(szbuffer, pTextureName); szbuffer[CBTEXTURENAMEMAX - 1] = 0;
chTextureType = PM_FindTextureType((char *)pTextureName); }
|
Here's volume choice --- this includes customized NPC volumes:
| | if(FClassnameIs(pMonster,"monster_scientist"))fvol=0.5; else if(FClassnameIs(pMonster,"monster_zombie")) { switch(pMonster->m_Activity) { case ACT_WALK: fvol=0.8; break; case ACT_RUN: fvol=1.0; break; case ACT_DANCE: fvol=0.3; break; } } 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:
| | char plSound[32]; if(FClassnameIs(pMonster,"monster_zombie")) { switch(chTextureType) { case CHAR_TEX_METAL: plSound = "zombie/zo_metal1.wav"; } } else { switch (chTextureType) { case CHAR_TEX_METAL: switch(RANDOM_LONG(0, 3)) { case 0: plSound = "player/pl_metal1.wav"; } break; default: switch(RANDOM_LONG(0, 3)) { case 0: plSound = "player/pl_step1.wav"; } break; } } |
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
CHAR_TEX_DIRT pl_dirt
CHAR_TEX_VENT pl_duct
CHAR_TEX_GRATE pl_grate
CHAR_TEX_TILE pl_tile
CHAR_TEX_SLOSH pl_slosh
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:
| | #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:
| | case SCRIPT_EVENT_STEP:
NPC_Step(this);
break; |
|
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
| | case SCRIPT_EVENT_SOUND: if(FStrEq(pEvent->options,"common/npc_step1.wav")) NPC_Step(this);
else EMIT_SOUND( edict(), CHAN_BODY, pEvent->options, 1.0, ATTN_IDLE );
break; |
|
Finally: If you want to have hgrunts have their own step sound, you gotta add the event in to the model AND 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) |