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

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-16-2014 , 17:31   EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-19)
Reply With Quote #1

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.
Attached Files
File Type: inc emitsoundany.inc (6.0 KB, 6352 views)
__________________
Am I back? Well, we'll see.

Last edited by Powerlord; 07-08-2018 at 17:27.
Powerlord is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-17-2014 , 02:54   Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible)
Reply With Quote #2

Ok.
Just thinking maybe it no harm add that sound char *
for everygame :/
Bacardi is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 03-17-2014 , 08:54   Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible)
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
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 ;)
__________________
Peace-Maker is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-17-2014 , 09:41   Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible)
Reply With Quote #4

Quote:
Originally Posted by Peace-Maker View Post
Also you never set g_bCheckedEngine to true ;)
Whoops, you're right. I'll fix it in a minute.
__________________
Am I back? Well, we'll see.

Last edited by Powerlord; 03-17-2014 at 09:43.
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-19-2014 , 10:50   Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible)
Reply With Quote #5

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)
__________________
Am I back? Well, we'll see.

Last edited by Powerlord; 03-19-2014 at 14:04.
Powerlord is offline
Bittersweet
Veteran Member
Join Date: May 2012
Old 03-19-2014 , 13:33   Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
Reply With Quote #6

Very handy, they should roll it in.
__________________
Thank you in advance for your help

My plugins:
[CS:S] BOT Swat | [ANY] CVAR Randomizer | [CS:S] SM CS:S Tag Beta | [CS:S] Bot2Player
Awesome & Crucial plugins by other people:
[CS:S/CS:GO] GunGame | [UMC3] Ultimate Mapchooser | [ANY] Server Crontab | [ANY] SM ForceCamera
Bittersweet is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-20-2014 , 14:58   Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
Reply With Quote #7

Quote:
Originally Posted by Bittersweet View Post
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.
__________________
Am I back? Well, we'll see.

Last edited by Powerlord; 03-20-2014 at 14:59.
Powerlord is offline
Jargon
SourceMod Donor
Join Date: Jun 2012
Location: Sydney, Australia
Old 03-25-2014 , 18:07   Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
Reply With Quote #8

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?
Jargon is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-25-2014 , 18:19   Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
Reply With Quote #9

Quote:
Originally Posted by Jargon View Post
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.
__________________
Am I back? Well, we'll see.
Powerlord is offline
Jargon
SourceMod Donor
Join Date: Jun 2012
Location: Sydney, Australia
Old 03-25-2014 , 18:26   Re: EmitSoundAny - Cross-game sound emitting (aka CS:GO compatible) (1.0.2, 2014-03-1
Reply With Quote #10

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.
Jargon is offline
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 23:08.


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