Raised This Month: $32 Target: $400
 8% 

How to Block Sounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 10-03-2006 , 00:09   How to Block Sounds
Reply With Quote #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 using a radio command, turning on his flashlight, or picking up a weapon. That's the kind of sound it blocks, also known as an "emitted sound"

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:
#include <amxmodx> #include <amxmisc> #include <fakemeta> // Must include this for the "hook" function // Global Variables new g_soundlist[] = "items/flashlight1.wav"

Now 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.

Code:
public plugin_init() {     register_forward(FM_EmitSound, "block_sound") }

Now 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.

Code:
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:
#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 }

Looks 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.

Code:
#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 }

Notice the use of FMRES_SUPERCEDE and 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.
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-03-2006 , 12:32   Re: How to Block Sounds
Reply With Quote #2

Did you compile this code? The reason why I ask this is because this code:

Code:
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 }

should give you an error, telling you that the function must return a value (even though, you return a value in all the if statements and if they fail you return no matter way (FMRES_IGNORED). From what I've been told, pawn doesn't check/optimize for this.

edit
Apparently all it does is issue a warning, but compiles anyway. I did a quick compile on the web compiler.

Quote:
Originally Posted by compiler
Welcome to the AMX Mod X 1.75-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

/home/groups/amxmodx/tmp3/textC7Ifh4.sma(13) : warning 209: function "block_sound" should return a value
Header size: 148 bytes
Code size: 116 bytes
Data size: 36 bytes
Stack/heap size: 16384 bytes; estimated max. usage=13 cells (52 bytes)
Total requirements: 16684 bytes

1 Warning.
Done.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred

Last edited by Zenith77; 10-03-2006 at 12:35.
Zenith77 is offline
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 10-03-2006 , 13:03   Re: How to Block Sounds
Reply With Quote #3

Very cool! +karma
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))
TheNewt is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 10-03-2006 , 13:22   Re: How to Block Sounds
Reply With Quote #4

Zenith, you're right - I originally had it without the word "else" but I thought it would be too confusing for newbies.
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-03-2006 , 16:46   Re: How to Block Sounds
Reply With Quote #5

This really doesn't cover a lot of stuff. Not everything is passed through EmitSound.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 10-03-2006 , 16:50   Re: How to Block Sounds
Reply With Quote #6

ok
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-03-2006 , 16:51   Re: How to Block Sounds
Reply With Quote #7

Quote:
Originally Posted by Wilson [29th ID] View Post
ok
That's probably the best response to one of my comments I've ever seen. No, I'm not being sarcastic.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-03-2006 , 18:16   Re: How to Block Sounds
Reply With Quote #8

You don't want to confuse newbs but yet you use this:

Code:
new g_listsize = sizeof g_soundlist

I gurantee that the will have no clue what it does in the first place or how it works. Just thought I point that out. I'm also not even certain this will work the way you want it to work. It won't return 2 (2 cells, size of first deminision), it will most likely take into calculation the second deminion, making the actual size d1 * d2.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred

Last edited by Zenith77; 10-03-2006 at 18:20.
Zenith77 is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-03-2006 , 18:35   Re: How to Block Sounds
Reply With Quote #9

Quote:
Originally Posted by Zenith77 View Post
You don't want to confuse newbs but yet you use this:

Code:
new g_listsize = sizeof g_soundlist


I gurantee that the will have no clue what it does in the first place or how it works. Just thought I point that out. I'm also not even certain this will work the way you want it to work. It won't return 2 (2 cells, size of first deminision), it will most likely take into calculation the second deminion, making the actual size d1 * d2.
Yes it will. You [Wilson] also don't seem to understand that sizeof returns (or rather is replaced by) the exact number of cells in an array. What does this mean...? Well, basically, it's at risk of a buffer overflow. It should be "sizeof g_soundlist - 1", and even then it will still have problems due to what Zenith said.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 10-04-2006 , 00:09   Re: How to Block Sounds
Reply With Quote #10

sizeof soundlist returns 2
sizeof soundlist[] would return the next dimension.

it works. it doesn't overflow.

jesus posting a tutorial here is hectic as hell. the tutorial teaches people how to block emitted sounds. and it does block emitted sounds.

stop replying and discussing it. if the mods disapprove of the tutorial then delete the thread. but it seems that everyone wants to point out any possible future maybe warning of an error just to show that they can find them. good for you. this tutorial works.

[/thread]
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode