Skip to content

Commit

Permalink
Add player death soundscript
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Jan 12, 2025
1 parent 2903d12 commit da5dd7f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 68 deletions.
1 change: 1 addition & 0 deletions dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ class CSound;
#include "basemonster.h"

const char *ButtonSound( int sound ); // get string of button sound number
CBaseEntity* GetExtraSpeakerForEntity(CBaseEntity* pTargetEntity);

//
// Weapons
Expand Down
5 changes: 2 additions & 3 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,8 @@ void ClientPrecache( void )
// player pain sounds
//PRECACHE_SOUND( "player/pl_pain2.wav" );
//PRECACHE_SOUND( "player/pl_pain4.wav" );
PRECACHE_SOUND( "player/pl_pain5.wav" );
PRECACHE_SOUND( "player/pl_pain6.wav" );
PRECACHE_SOUND( "player/pl_pain7.wav" );
pWorld->RegisterAndPrecacheSoundScript(Player::deathSoundScript);
pWorld->RegisterAndPrecacheSoundScript(Player::deathUnderwaterSoundScript);

PRECACHE_MODEL( "models/player.mdl" );

Expand Down
12 changes: 12 additions & 0 deletions dlls/common_soundscripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,16 @@ const NamedSoundScript nvgOffSoundScript = {
"Player.NVGOff"
};

const NamedSoundScript deathSoundScript = {
CHAN_VOICE,
{},
"Player.Death"
};

const NamedSoundScript deathUnderwaterSoundScript = {
CHAN_VOICE,
{},
"Player.DeathUnderwater"
};

}
2 changes: 2 additions & 0 deletions dlls/common_soundscripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ extern const NamedSoundScript flashlightOnSoundScript;
extern const NamedSoundScript flashlightOffSoundScript;
extern const NamedSoundScript nvgOnSoundScript;
extern const NamedSoundScript nvgOffSoundScript;
extern const NamedSoundScript deathSoundScript;
extern const NamedSoundScript deathUnderwaterSoundScript;
}

#endif
51 changes: 20 additions & 31 deletions dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,7 @@ LINK_ENTITY_TO_CLASS( player, CBasePlayer )

void CBasePlayer::Pain( void )
{
float flRndSound;//sound randomizer

flRndSound = RANDOM_FLOAT( 0.0f, 1.0f );

if( flRndSound <= 0.33f )
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain5.wav", 1, ATTN_NORM );
else if( flRndSound <= 0.66f )
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain6.wav", 1, ATTN_NORM );
else
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain7.wav", 1, ATTN_NORM );
// not used
}

Vector VecVelocityForDamage( float flDamage )
Expand Down Expand Up @@ -450,31 +441,29 @@ int TrainSpeed( int iSpeed, int iMax )

void CBasePlayer::DeathSound( void )
{
// water death sounds
/*
if( pev->waterlevel == 3 )
const SoundScript* deathSoundScript = GetSoundScript(Player::deathSoundScript);
if (pev->waterlevel == WL_Eyes)
{
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/h2odeath.wav", 1, ATTN_NONE );
return;
const SoundScript* deathUnderwaterSoundScript = GetSoundScript(Player::deathUnderwaterSoundScript);
if (deathUnderwaterSoundScript)
{
deathSoundScript = deathUnderwaterSoundScript;
}
}
*/

// temporarily using pain sounds for death sounds
switch( RANDOM_LONG( 1, 5 ) )
if (deathSoundScript && !deathSoundScript->waves.empty())
{
case 1:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain5.wav", 1, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain6.wav", 1, ATTN_NORM );
break;
case 3:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain7.wav", 1, ATTN_NORM );
break;
EmitSoundScript(deathSoundScript);
CBaseEntity* myExtraSpeaker = GetExtraSpeakerForEntity(this);
if (myExtraSpeaker)
{
EMIT_GROUPNAME_SUIT(myExtraSpeaker->edict(), "HEV_DEAD");
}
}
else
{
// play one of the suit death alarms
EMIT_GROUPNAME_SUIT( ENT( pev ), "HEV_DEAD" );
}

// play one of the suit death alarms
EMIT_GROUPNAME_SUIT( ENT( pev ), "HEV_DEAD" );
}

// override takehealth
Expand Down
67 changes: 33 additions & 34 deletions dlls/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,7 @@ class CExtraSpeaker : public CPointEntity
}
if (!pOwner)
{
ALERT(at_console, "Removing %s because the owner has expired\n", STRING(pev->classname));
ALERT(at_console, "Removing '%s' because the owner has expired\n", STRING(pev->classname));
UTIL_Remove(this);
return;
}
Expand All @@ -2169,6 +2169,37 @@ class CExtraSpeaker : public CPointEntity

LINK_ENTITY_TO_CLASS( extra_speaker, CExtraSpeaker )

CBaseEntity* GetExtraSpeakerForEntity(CBaseEntity* pTargetEntity)
{
CBaseEntity* pEntity = nullptr;
while((pEntity = UTIL_FindEntityByClassname(pEntity, "extra_speaker")) != nullptr)
{
if (pTargetEntity->edict() == pEntity->pev->owner)
{
return pEntity;
}
}

if (!pEntity) {
pEntity = CBaseEntity::CreateNoSpawn("extra_speaker", pTargetEntity->pev->origin, pTargetEntity->pev->angles);

if (pEntity) {
ALERT(at_console, "Created '%s' for '%s'\n", STRING(pEntity->pev->classname), STRING(pTargetEntity->pev->classname));
pEntity->pev->movetype = MOVETYPE_FOLLOW;
pEntity->pev->aiment = pTargetEntity->edict();
pEntity->pev->owner = pTargetEntity->edict();
pEntity->m_EFlags |= EFLAG_PREVENT_ORIGIN_UNSETTING;
DispatchSpawn(pEntity->edict());
SET_MODEL(pEntity->edict(), "sprites/iunknown.spr");
pEntity->pev->rendermode = kRenderTransAlpha;
pEntity->pev->renderamt = 0;
pEntity->pev->nextthink = gpGlobals->time + 1.0f;
}
}

return pEntity;
}

class CAmbientExtraSpeaker : public CAmbientGeneric
{
public:
Expand All @@ -2177,7 +2208,6 @@ class CAmbientExtraSpeaker : public CAmbientGeneric

protected:
CBaseEntity* GetTargetEntity(CBaseEntity* pActivator);
CBaseEntity* GetSpeakerEntity(CBaseEntity* pTargetEntity);
};

LINK_ENTITY_TO_CLASS( ambient_extraspeaker, CAmbientExtraSpeaker )
Expand All @@ -2188,7 +2218,7 @@ CBaseEntity* CAmbientExtraSpeaker::GetEntityToPlayFrom(CBaseEntity *pActivator)
if (!pTargetEntity)
return nullptr;

CBaseEntity* pSpeakerEntity = GetSpeakerEntity(pTargetEntity);
CBaseEntity* pSpeakerEntity = GetExtraSpeakerForEntity(pTargetEntity);
if (pSpeakerEntity)
{
pSpeakerEntity->pev->movetype = MOVETYPE_FOLLOW;
Expand All @@ -2210,34 +2240,3 @@ CBaseEntity* CAmbientExtraSpeaker::GetTargetEntity(CBaseEntity *pActivator)
}
return pTargetEntity;
}

CBaseEntity* CAmbientExtraSpeaker::GetSpeakerEntity(CBaseEntity *pTargetEntity)
{
CBaseEntity* pEntity = nullptr;
while((pEntity = UTIL_FindEntityByClassname(pEntity, "extra_speaker")) != nullptr)
{
if (pTargetEntity->edict() == pEntity->pev->owner)
{
return pEntity;
}
}

if (!pEntity) {
pEntity = CBaseEntity::CreateNoSpawn("extra_speaker", pTargetEntity->pev->origin, pTargetEntity->pev->angles);

if (pEntity) {
ALERT(at_console, "Created %s for %s\n", STRING(pEntity->pev->classname), STRING(pTargetEntity->pev->classname));
pEntity->pev->movetype = MOVETYPE_FOLLOW;
pEntity->pev->aiment = pTargetEntity->edict();
pEntity->pev->owner = pTargetEntity->edict();
pEntity->m_EFlags |= EFLAG_PREVENT_ORIGIN_UNSETTING;
DispatchSpawn(pEntity->edict());
SET_MODEL(pEntity->edict(), "sprites/iunknown.spr");
pEntity->pev->rendermode = kRenderTransAlpha;
pEntity->pev->renderamt = 0;
pEntity->pev->nextthink = gpGlobals->time + 1.0f;
}
}

return pEntity;
}

0 comments on commit da5dd7f

Please sign in to comment.