Raised This Month: $51 Target: $400
 12% 

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


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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, 11045 views)
__________________
Not currently working on SourceMod plugin development.

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



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 04:30.


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