Day of Defeat Plugins Community
This site is an archive — everything is readable and downloadable, nothing can be posted. Admin
Archive › Old Forum Threads › Help › Tutorials › How to Block Sounds
2 posts, 2 people · 1,265 views Thread Rating: ★★★★★
closedHow to Block Sounds
Started by Wilson [29th ID] on 10-03-2006, 01:13 AM
Wilson [29th ID]
started this thread
Posts: 623
Threads: 57
Joined: Oct 2005
10-03-2006, 01:13 AM #1

This tutorial shows you how to block sounds in the game that players hear. Note that it's not client-side - it's when you're standing next to another player and you'd normally hear a sound, ie. him throwing a grenade or jumping. That's the kind of sound it blocks, also known as an "emitted sound"rnrnThis tutorial uses fakemeta, an alternative to the engine module.rnrn-----------------------------------------rnrnFirstly, we have to establish our global variable of the string of the sound we'd like to block. You can turn this into a multi-dimensional array if you'd like to block several sounds (but you will obviously have to loop through it - more info at the bottom of the tutorial)rnrn

rn#include <amxmodx>rn#include <amxmisc>rn#include <fakemeta> // Must include this for the "hook" functionrnrn// Global Variablesrnrnnew g_soundlist[] = "items/flashlight1.wav"rnrn
rnrnNow we're going to initialise our plugin. This will provide the fakemeta "hook" that catches when the game tries to "emit a sound" so we can do what we want to it before it happens on the client's end.rnrn
public plugin_init() {rn	register_forward(FM_EmitSound, "block_sound")rn}
rnrnNow the actual sound blocking. We're basically catching every single sound that the game emits and testing if it's the sound we want to block. If it is, stop sending that sound emission to the client. Otherwise, continue what you were doing - your papers are in order citizen.rnrn
public block_sound(entity, channel, const sound[]) {rnrn	// Use equali to check strings against each other because rn	// they are technically arraysrnrn	if ( equali(sound, g_soundlist) )rn		return FMRES_SUPERCEDErn	elsern		return FMRES_IGNOREDrn}
rnrnSo the overall code looks like thisrnrn
#include <amxmodx>rn#include <amxmisc>rn#include <fakemeta>rnrn// Global Variablesrnrnnew g_soundlist[] = "items/flashlight1.wav"rnrnpublic plugin_init() {rn	register_forward(FM_EmitSound, "block_sound")rn}rnrnpublic block_sound(entity, channel, const sound[]) {rn	rn	if ( equali(sound, g_soundlist) )rn		return FMRES_SUPERCEDErn	elsern		return FMRES_IGNOREDrn}
rnrnLooks pretty simple right? Let's say you wanted to block multiple sounds this time. Take a look at how a multi-dimensional array is created in the global variable and how we loop through the array in the block_sound function to test every line of the array against the sound being emitted.rnrn
#include <amxmodx>rn#include <amxmisc>rn#include <fakemeta>rnrn// Global Variablesrnnew g_soundlist[2][64] = rn{rn	"items/weaponpickup.wav",rn	"items/flashlight1.wav"rn}rnrnpublic plugin_init() {rn	register_forward(FM_EmitSound, "block_sound")rn}rnrnpublic block_sound(entity, channel, const sound[]) {rnrn	// Get the size of the array so you know how manyrn	// times to loop through itrn	new g_listsize = sizeof g_soundlistrn	for(new i; i<g_listsize; i++)rn	{rn		// Checks each line of the array against the sound emittedrn		if( equali(sound, g_soundlist[i]) )rn			return FMRES_SUPERCEDErn	}rn	// In this case, "else" isn't needed because if it were anythingrn	// other than "else," it would have already been handled in thern	// loop by exiting the function with FMRES_SUPERCEDErn	return FMRES_IGNOREDrn}
rnrnNotice the use of FMRES_SUPERCEDE and FMRES_IGNORED.rnFMRES_SUPERCEDE basically says stop doing what you were doing to the client. If you wanted to "replace" the blocked sound, you'd do it right before the FMRES_SUPERCEDE line.rnrnFMRES_IGNORED is saying to ignore the hook and keep going with what you were doing, Mr. Emitted-Sound.

=|[76AD]|= TatsuSaisei
posted here
Posts: 794
Threads: 54
Joined: May 2005
10-03-2006, 09:00 AM #2

nice tut !! Perfect amount of info with a touch of humor. TY

Archive › Old Forum Threads › Help › Tutorials › How to Block Sounds
DoD Plugins Archive · Repository · Old Forum Threads · Maps · Admin · built 14 Sep 2026 00:34 UTC