Added sound effects module, moved all moaning, groaning, and death sounds to zombie sounds sub-module, and made a basic sound API.
This commit is contained in:
69
src/zr/soundeffects/soundeffects.inc
Normal file
69
src/zr/soundeffects/soundeffects.inc
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* ============================================================================
|
||||
*
|
||||
* Zombie:Reloaded
|
||||
*
|
||||
* File: soundeffects.inc
|
||||
* Description: Basic sound-management API.
|
||||
*
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Maximum sound path length.
|
||||
*/
|
||||
#define SOUND_MAX_PATH 128
|
||||
|
||||
/**
|
||||
* Ambient sound channel.
|
||||
*/
|
||||
#define SOUND_AMBIENT_CHANNEL 8
|
||||
|
||||
#include "zr/soundeffects/zombiesounds"
|
||||
|
||||
/**
|
||||
* Emits an ambient sound
|
||||
*/
|
||||
SEffectsEmitAmbientSound(const String:sound[], Float:soundvolume = 1.0)
|
||||
{
|
||||
// Precache sound before playing.
|
||||
PrecacheSound(sound);
|
||||
|
||||
// Emit ambient sound.
|
||||
EmitSoundToAll(sound, SOUND_FROM_PLAYER, SOUND_AMBIENT_CHANNEL, _, _, soundvolume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop an ambient sound
|
||||
*/
|
||||
SEffectsStopAmbientSound(const String:sound[])
|
||||
{
|
||||
// x = client index.
|
||||
for (new x = 1; x <= MaxClients; x++)
|
||||
{
|
||||
// If client isn't in-game, then stop.
|
||||
if (!IsClientInGame(x))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Stop ambient sound.
|
||||
StopSound(x, SOUND_AMBIENT_CHANNEL, sound);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a sound from a client.
|
||||
*
|
||||
* @param client The client index.
|
||||
* @param sound The sound file relative to the sound/ directory.
|
||||
* @param level The attenuation of the sound.
|
||||
*/
|
||||
SEffectsEmitSoundFromClient(client, const String:sound[], level = SNDLEVEL_NORMAL)
|
||||
{
|
||||
// Precache sound before playing.
|
||||
PrecacheSound(sound);
|
||||
|
||||
// Emit sound from client.
|
||||
EmitSoundToAll(sound, client, _, level);
|
||||
}
|
265
src/zr/soundeffects/zombiesounds.inc
Normal file
265
src/zr/soundeffects/zombiesounds.inc
Normal file
@ -0,0 +1,265 @@
|
||||
/*
|
||||
* ============================================================================
|
||||
*
|
||||
* Zombie:Reloaded
|
||||
*
|
||||
* File: zombiesounds.inc
|
||||
* Description: Zombie sound effects.
|
||||
*
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* @section Defines for min/max moaning sound file index.
|
||||
*/
|
||||
#define SOUND_MOAN_PATH "npc/zombie/zombie_voice_idle%d.wav" // %d is sound file index
|
||||
#define SOUND_MOAN_MIN 1
|
||||
#define SOUND_MOAN_MAX 14
|
||||
/**
|
||||
* @endsection
|
||||
*/
|
||||
|
||||
/**
|
||||
* @section Defines for min/max groan sound file index.
|
||||
*/
|
||||
#define SOUND_GROAN_PATH "npc/zombie/zombie_pain%d.wav" // %d is sound file index
|
||||
#define SOUND_GROAN_MIN 1
|
||||
#define SOUND_GROAN_MAX 6
|
||||
/**
|
||||
* @endsection
|
||||
*/
|
||||
|
||||
/**
|
||||
* @section Defines for min/max death sound file index.
|
||||
*/
|
||||
#define SOUND_DEATH_PATH "npc/zombie/zombie_die%d.wav" // %d is sound file index
|
||||
#define SOUND_DEATH_MIN 1
|
||||
#define SOUND_DEATH_MAX 3
|
||||
/**
|
||||
* @endsection
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zombie sound types
|
||||
*/
|
||||
enum ZombieSounds
|
||||
{
|
||||
Moan, /** Zombie's moan periodically */
|
||||
Groan, /** When zombie is hurt */
|
||||
Death, /** When a zombie is killed */
|
||||
}
|
||||
|
||||
/**
|
||||
* Array for storing zombie moaning timer handles per client.
|
||||
*/
|
||||
new Handle:tSEffectsMoan[MAXPLAYERS + 1];
|
||||
|
||||
/**
|
||||
* Client is joining the server.
|
||||
*
|
||||
* @param client The client index.
|
||||
*/
|
||||
ZombieSoundsClientInit(client)
|
||||
{
|
||||
// Reset timer handle.
|
||||
tSEffectsMoan[client] = INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Client is spawning into the game.
|
||||
*
|
||||
* @param client The client index.
|
||||
*/
|
||||
ZombieSoundsOnClientSpawn(client)
|
||||
{
|
||||
// If timer is running, kill it.
|
||||
if (tSEffectsMoan[client] != INVALID_HANDLE)
|
||||
{
|
||||
KillTimer(tSEffectsMoan[client]);
|
||||
}
|
||||
|
||||
// Reset timer handle.
|
||||
tSEffectsMoan[client] = INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Client has been killed.
|
||||
*
|
||||
* @param client The client index.
|
||||
*/
|
||||
ZombieSoundsOnClientDeath(client)
|
||||
{
|
||||
// If timer is running, kill it.
|
||||
if (tSEffectsMoan[client] != INVALID_HANDLE)
|
||||
{
|
||||
KillTimer(tSEffectsMoan[client]);
|
||||
}
|
||||
|
||||
// Reset timer handle.
|
||||
tSEffectsMoan[client] = INVALID_HANDLE;
|
||||
|
||||
// If player isn't a zombie, then stop.
|
||||
if (!IsPlayerZombie(client))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If death sound cvar is disabled, then stop.
|
||||
new bool:death = GetConVarBool(gCvars[CVAR_SOUNDEFFECTS_DEATH]);
|
||||
if (!death)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get random death sound.
|
||||
decl String:sound[SOUND_MAX_PATH];
|
||||
ZombieSoundsGetRandomSound(sound, Death);
|
||||
|
||||
SEffectsEmitSoundFromClient(client, sound);
|
||||
}
|
||||
|
||||
/**
|
||||
* Client has been hurt.
|
||||
*
|
||||
* @param client The client index.
|
||||
*/
|
||||
ZombieSoundsOnClientHurt(client)
|
||||
{
|
||||
// If player isn't a zombie, then stop.
|
||||
if (!IsPlayerZombie(client))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get groan factor, if 0, then stop.
|
||||
new groan = GetConVarInt(gCvars[CVAR_SOUNDEFFECTS_GROAN]);
|
||||
if (!groan)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 1 in 'groan' chance of groaning.
|
||||
if (GetRandomInt(1, groan) == 1)
|
||||
{
|
||||
// Get random groan sound.
|
||||
decl String:sound[SOUND_MAX_PATH];
|
||||
ZombieSoundsGetRandomSound(sound, Groan);
|
||||
|
||||
SEffectsEmitSoundFromClient(client, sound);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Client has been infected.
|
||||
*
|
||||
* @param client The client index.
|
||||
*/
|
||||
ZombieSoundsOnClientInfected(client)
|
||||
{
|
||||
// If interval is set to 0, then stop.
|
||||
new Float:interval = GetConVarFloat(gCvars[CVAR_SOUNDEFFECTS_MOAN]);
|
||||
if (!interval)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If timer is currently running, kill it.
|
||||
if (tSEffectsMoan[client] != INVALID_HANDLE)
|
||||
{
|
||||
KillTimer(tSEffectsMoan[client]);
|
||||
}
|
||||
|
||||
// Start repeating timer.
|
||||
tSEffectsMoan[client] = CreateTimer(interval, ZombieSoundsMoanTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a random zombie sound from hl2 folder.
|
||||
*
|
||||
* @param sound The randomly picked moan sound.
|
||||
* @return True if sound was successfully picked, false otherwise.
|
||||
*/
|
||||
bool:ZombieSoundsGetRandomSound(String:sound[], ZombieSounds:soundtype)
|
||||
{
|
||||
new soundmin;
|
||||
new soundmax;
|
||||
decl String:soundpath[SOUND_MAX_PATH];
|
||||
|
||||
switch(soundtype)
|
||||
{
|
||||
// Find moan sound.
|
||||
case Moan:
|
||||
{
|
||||
// Copy min and max
|
||||
soundmin = SOUND_MOAN_MIN;
|
||||
soundmax = SOUND_MOAN_MAX;
|
||||
|
||||
// Copy path
|
||||
strcopy(soundpath, sizeof(soundpath), SOUND_MOAN_PATH);
|
||||
}
|
||||
// Find groan sound. (zombie shot)
|
||||
case Groan:
|
||||
{
|
||||
// Copy min and max
|
||||
soundmin = SOUND_GROAN_MIN;
|
||||
soundmax = SOUND_GROAN_MAX;
|
||||
|
||||
// Copy path
|
||||
strcopy(soundpath, sizeof(soundpath), SOUND_GROAN_PATH);
|
||||
}
|
||||
// Find death sound.
|
||||
case Death:
|
||||
{
|
||||
// Copy min and max
|
||||
soundmin = SOUND_DEATH_MIN;
|
||||
soundmax = SOUND_DEATH_MAX;
|
||||
|
||||
// Copy path
|
||||
strcopy(soundpath, sizeof(soundpath), SOUND_DEATH_PATH);
|
||||
}
|
||||
// Invalid case given.
|
||||
default:
|
||||
{
|
||||
// No handled case was given.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Pick a random integer between min and max sound file index.
|
||||
new randsound = GetRandomInt(soundmin, soundmax);
|
||||
|
||||
// Format random index into sound path.
|
||||
Format(sound, SOUND_MAX_PATH, soundpath, randsound);
|
||||
|
||||
// Found sound.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Timer callback, repeats a moaning sound on zombies.
|
||||
*
|
||||
* @param timer The timer handle.
|
||||
* @param client The client index.
|
||||
*/
|
||||
public Action:ZombieSoundsMoanTimer(Handle:timer, any:client)
|
||||
{
|
||||
// If client isn't in-game or client is no longer a zombie, then stop.
|
||||
if (!IsClientInGame(client) || !IsPlayerZombie(client))
|
||||
{
|
||||
// Reset timer handle.
|
||||
tSEffectsMoan[client] = INVALID_HANDLE;
|
||||
|
||||
// Stop timer.
|
||||
return Plugin_Stop;
|
||||
}
|
||||
|
||||
// Get random moan sound.
|
||||
decl String:sound[SOUND_MAX_PATH];
|
||||
ZombieSoundsGetRandomSound(sound, Moan);
|
||||
|
||||
// Emit sound from client.
|
||||
SEffectsEmitSoundFromClient(client, sound, SNDLEVEL_SCREAMING);
|
||||
|
||||
// Allow timer to continue.
|
||||
return Plugin_Continue;
|
||||
}
|
Reference in New Issue
Block a user