View Single Post
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-16-2014 , 16: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, 7166 views)
__________________
Am I back? Well, we'll see.

Last edited by Powerlord; 07-08-2018 at 16:27.
Powerlord is offline