AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-19) (https://forums.alliedmods.net/showthread.php?t=237045)

Powerlord 03-16-2014 16:31

EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-19)
 
6 Attachment(s)
As of a 2018 CS:GO update, this include is no longer necessary

Warning: This only works for MP3s

Version: 1.0.3

Changelog
  • 1.0.3
    • Added StopSoundAny.
    • Fix incorrect variable name in EmitAmbientSoundAny
  • 1.0.2
    • Added include guard in case your code attempts to include it twice.
    • Adds second argument to PrecacheSoundAny.
    • Adds #include <sdktool> in case you include it before including sdktools.
  • 1.0.1
    • Fixed the engine check being done every call instead of just the first.
  • 1.0.0
    • Initial release based on the CS:GO Quirks page (both psychonic's and my work on it)

What is EmitSoundAny

So, what's the point of this?

Well, it's to provide a simple include that plugins can use to have CS:GO and DOTA2 compatible sound playing. If you have read the CS:GO Quirks page, you know that CS:GO doesn't work with PrecacheSound and EmitSound without having to go through some tricks.

So... I wrote this include, which neatly wraps the game detection and precaches/emits appropriately.

The wrappers it includes are:

Code:

stock bool:PrecacheSoundAny(const String:szPath[], bool:preload=false)

stock EmitSoundAny(const clients[],
                numClients,
                const String:sample[],
                entity = SOUND_FROM_PLAYER,
                channel = SNDCHAN_AUTO,
                level = SNDLEVEL_NORMAL,
                flags = SND_NOFLAGS,
                Float:volume = SNDVOL_NORMAL,
                pitch = SNDPITCH_NORMAL,
                speakerentity = -1,
                const Float:origin[3] = NULL_VECTOR,
                const Float:dir[3] = NULL_VECTOR,
                bool:updatePos = true,
                Float:soundtime = 0.0)

stock EmitSoundToClientAny(client,
                const String:sample[],
                entity = SOUND_FROM_PLAYER,
                channel = SNDCHAN_AUTO,
                level = SNDLEVEL_NORMAL,
                flags = SND_NOFLAGS,
                Float:volume = SNDVOL_NORMAL,
                pitch = SNDPITCH_NORMAL,
                speakerentity = -1,
                const Float:origin[3] = NULL_VECTOR,
                const Float:dir[3] = NULL_VECTOR,
                bool:updatePos = true,
                Float:soundtime = 0.0)

stock EmitSoundToAllAny(const String:sample[],
                entity = SOUND_FROM_PLAYER,
                channel = SNDCHAN_AUTO,
                level = SNDLEVEL_NORMAL,
                flags = SND_NOFLAGS,
                Float:volume = SNDVOL_NORMAL,
                pitch = SNDPITCH_NORMAL,
                speakerentity = -1,
                const Float:origin[3] = NULL_VECTOR,
                const Float:dir[3] = NULL_VECTOR,
                bool:updatePos = true,
                Float:soundtime = 0.0)

stock EmitAmbientSoundAny(const String:sample[],
                        const Float:pos[3],
                        entity = SOUND_FROM_WORLD,
                        level = SNDLEVEL_NORMAL,
                        flags = SND_NOFLAGS,
                        Float:vol = SNDVOL_NORMAL,
                        pitch = SNDPITCH_NORMAL,
                        Float:delay = 0.0)

stock StopSoundAny(entity, channel, const String:name[])

(Note that EmitSoundAny is missing its any:.. because SourcePawn doesn't have any way to process those outside of VFormat, which is inappropriate for this)

Usage of this is the same as playing sounds in most game using SourceMod:

PHP Code:

public OnMapStart()
{
    
AddFileToDownloadsTable("sound/sourcemod/mymod/bacon.mp3");
    
PrecacheSoundAny("sourcemod/mymod/bacon.mp3");
}

// In response to something
    
EmitSoundToAllAny("sourcemod/mymod/bacon.mp3"); 

Edit: Minor update to make the variables static.

Edit 2: Edit to make g_bCheckedEngine actually save its value to stop GetEngineVersion from being called every time.

Bacardi 03-17-2014 01:54

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible)
 
Ok.
Just thinking maybe it no harm add that sound char *
for everygame :/

Peace-Maker 03-17-2014 07:54

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible)
 
Quote:

Originally Posted by Bacardi (Post 2112521)
Ok.
Just thinking maybe it no harm add that sound char *
for everygame :/

I thought you weren't able to specify the sounds location when streaming it from disk with *. You would lose that possibility when using * for every other game.

Also you never set g_bCheckedEngine to true ;)

Powerlord 03-17-2014 08:41

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible)
 
Quote:

Originally Posted by Peace-Maker (Post 2112567)
Also you never set g_bCheckedEngine to true ;)

Whoops, you're right. I'll fix it in a minute.

Powerlord 03-19-2014 09:50

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible)
 
I uploaded version 1.0.2, which includes these fixes:
  • Adds an include guard so things don't blow up if you try to include it twice. (I ran into this while working with UMC).
  • Adds an #include <sdktools> so that it can be placed before #include <sdktools> in your own code (which works because sdktools also has an include guard)
  • Adds the preload argument to PrecacheSoundAny (which is passed to PrecacheSound for supported games)

Bittersweet 03-19-2014 12:33

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Very handy, they should roll it in.

Powerlord 03-20-2014 13:58

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by Bittersweet (Post 2113481)
Very handy, they should roll it in.

If they were going to roll it in, they could have just updated PrecacheSound and EmitSound* directly, but it's too late to do that now because it'll break code that depends on the code on the CS:GO Quirks page.

Jargon 03-25-2014 17:07

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
I changed a round sounds plugin to use this and now the sound has gone from being normal levels (using the CS:GO Quirks workaround) to being so quiet it can barely be heard. Do you have any idea why this could be?

Powerlord 03-25-2014 17:19

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
Quote:

Originally Posted by Jargon (Post 2115893)
I changed a round sounds plugin to use this and now the sound has gone from being normal levels (using the CS:GO Quirks workaround) to being so quiet it can barely be heard. Do you have any idea why this could be?

Which CS:GO Quirks workaround were you using? If it was the music/ folder one, the volumes would be different as files being played from the music folder have their volume controlled by the client's music volume control.

Jargon 03-25-2014 17:26

Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
 
No just the fakeprecache sound method with the * before the filename. I may have foolishly saved over the changed version I made but I'll try to replicate it.

Just to be sure, even though my sounds aren't in the music folder I tried adjusting the music volume which made no difference, and tried to change the SNDLEVEL in the include which also didn't increase it at all.


All times are GMT -4. The time now is 20:40.

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