This tutorial uses fakemeta, an alternative to the engine module.
-----------------------------------------
Firstly, 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)
Code: Select all
#include <amxmodx>
#include <amxmisc>
#include <fakemeta> // Must include this for the "hook" function
// Global Variables
new g_soundlist[] = "items/flashlight1.wav"Code: Select all
public plugin_init() {
register_forward(FM_EmitSound, "block_sound")
}public block_sound(entity, channel, const sound[]) {
// Use equali to check strings against each other because
// they are technically arrays
if ( equali(sound, g_soundlist) )
return FMRES_SUPERCEDE
else
return FMRES_IGNORED
}
So the overall code looks like this
Code: Select all
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
// Global Variables
new g_soundlist[] = "items/flashlight1.wav"
public plugin_init() {
register_forward(FM_EmitSound, "block_sound")
}
public block_sound(entity, channel, const sound[]) {
if ( equali(sound, g_soundlist) )
return FMRES_SUPERCEDE
else
return FMRES_IGNORED
}Code: Select all
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
// Global Variables
new g_soundlist[2][64] =
{
"items/weaponpickup.wav",
"items/flashlight1.wav"
}
public plugin_init() {
register_forward(FM_EmitSound, "block_sound")
}
public block_sound(entity, channel, const sound[]) {
// Get the size of the array so you know how many
// times to loop through it
new g_listsize = sizeof g_soundlist
for(new i; i<g_listsize; i++)
{
// Checks each line of the array against the sound emitted
if( equali(sound, g_soundlist[i]) )
return FMRES_SUPERCEDE
}
// In this case, "else" isn't needed because if it were anything
// other than "else," it would have already been handled in the
// loop by exiting the function with FMRES_SUPERCEDE
return FMRES_IGNORED
}
FMRES_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.
FMRES_IGNORED is saying to ignore the hook and keep going with what you were doing, Mr. Emitted-Sound.
