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

[Obsolete] [ALL] Read Game Sounds (v1.1, 2013-11-19)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-05-2013 , 03:20   [Obsolete] [ALL] Read Game Sounds (v1.1, 2013-11-19)
Reply With Quote #1

As of SourceMod 1.6.1, this extension is obsolete. Use SDKTools instead.

2013-11-19: Fixed a memory leak, added AMBuild packaging system. CS:GO, Blade Symphony, Insurgency, and DOTA2 versions have been rebuilt against the new SDKs, although note that the latter 3 may need separate recompiling as they were built against SourceMod 1.5 despite being games that require SourceMod 1.6.

2013-10-10 (u3): Added new stock: EmitAmbientGameSound to readgamesounds.inc

2013-10-09: Make sure to grab the updated readgamesounds.inc from this post.[/SIZE] It fixes a bug in the EmitGameSoundToAll stock. You will need to recompile it against the new version.

Read Game Sounds is an extension that provides 1 native and 3 stocks that plugins can use.

The native is
Code:
native bool:GetGameSoundParams(const String:gameSound[], &channel, &soundLevel, &Float:volume, &pitch, String:sample[], maxlength, entity=SOUND_FROM_PLAYER);
This native takes the name of a sound listed in one the game_sound text files for a game and puts the channel, sound level, volume, pitch, and one of its sample names in the variables provided. It also returns true or false based on whether it was successful or not.

For TF2, you could call this with something like "Announcer.SD_Rocket_PreLaunch" as the game sound to retrieve one of the Announcer's Special Delivery map start lines... randomly, because it has a rndwave section.

This native does not precache the sound it returns.

The 3 stocks are:

Code:
stock bool:EmitGameSound(const clients[],
                numClients,
                const String:gameSound[],
                entity = SOUND_FROM_PLAYER,
                flags = SND_NOFLAGS,
                speakerentity = -1,
                const Float:origin[3] = NULL_VECTOR,
                const Float:dir[3] = NULL_VECTOR,
                bool:updatePos = true,
                Float:soundtime = 0.0)

stock bool:EmitGameSoundToClient(client,
                const String:gameSound[],
                entity = SOUND_FROM_PLAYER,
                flags = SND_NOFLAGS,
                speakerentity = -1,
                const Float:origin[3] = NULL_VECTOR,
                const Float:dir[3] = NULL_VECTOR,
                bool:updatePos = true,
                Float:soundtime = 0.0)

stock bool:EmitGameSoundToAll(const String:gameSound[],
                entity = SOUND_FROM_PLAYER,
                flags = SND_NOFLAGS,
                speakerentity = -1,
                const Float:origin[3] = NULL_VECTOR,
                const Float:dir[3] = NULL_VECTOR,
                bool:updatePos = true,
                Float:soundtime = 0.0)
These are similar to the existing EmitSound, EmitSoundToClient, and EmitSoundToAll calls, but they take a gameSound and retrieve the parameters mentioned in the native above.

Note that these function DO precache the sample and are recommended instead of calling GetGameSoundParams directly.

I've compiled this extension for every game under the sun and tested it a bit in TF2. The compile size is about the same for every game except CS:GO on Linux... not sure why, but it's nearly 10 times the size of the others.

For those of you who are developers, this extension just wraps the Source SDK's ISoundEmitterSystemBase's GetSoundIndex and GetSoundParametersEx functions.
Attached Files
File Type: inc readgamesounds.inc (3.3 KB, 262 views)
File Type: sp Get Plugin or Get Source (test_readgamesounds.sp - 358 views - 3.0 KB)
File Type: smx test_readgamesounds.smx (5.5 KB, 358 views)
File Type: zip readgamesounds-windows.zip (607.7 KB, 280 views)
File Type: gz readgamesounds-linux.tar.gz (264.2 KB, 261 views)
File Type: zip readgamesounds-src.zip (47.4 KB, 195 views)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 07-31-2014 at 15:14. Reason: Added new stock: EmitAmbientGameSound
Powerlord is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-05-2013 , 04:40   Re: [ALL] Read Game Sounds
Reply With Quote #2

uuh.. nice

also in-game

*edit
soundscape not relative
Attached Thumbnails
Click image for larger version

Name:	playgamesound.jpg
Views:	1846
Size:	95.7 KB
ID:	126474   Click image for larger version

Name:	playsoundscape.jpg
Views:	345
Size:	76.8 KB
ID:	126475  
__________________
Do not Private Message @me

Last edited by Bacardi; 10-05-2013 at 04:51.
Bacardi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-05-2013 , 14:18   Re: [ALL] Read Game Sounds
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
uuh.. nice

also in-game

*edit
soundscape not relative
You're aware that, like EmitSound, this extension can emit sounds from entities and not just from a player (which is essentially what playgamesound does)? In fact, EmitGameSound calls EmitSound after fetching the parameters and precaching the sound.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-05-2013 at 14:20.
Powerlord is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-05-2013 , 16:24   Re: [ALL] Read Game Sounds
Reply With Quote #4

yea, I was thinking where to look those game sounds entries ^^ without looking game_sounds.txt

Last edited by Bacardi; 10-05-2013 at 16:24.
Bacardi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-06-2013 , 13:17   Re: [ALL] Read Game Sounds
Reply With Quote #5

Once this is tested a bit more, I may try submitting it on the SourceMod BugTracker for inclusion as part of sdktools (sdktools_sound for the stocks). We'll see.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-07-2013 , 11:24   Re: [ALL] Read Game Sounds
Reply With Quote #6

I've considered adding a EmitAmbientGameSound stock, but I don't think any games store ambient sounds in their game_sounds, although I could be wrong.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-07-2013 at 11:24.
Powerlord is offline
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 10-09-2013 , 14:52   Re: [ALL] Read Game Sounds
Reply With Quote #7

PHP Code:
public Action:Cmd_GameSoundAll(clientargs)
{
    if (
client == 0)
    {
        
ReplyToCommand(client"%t""Command is in-game only");
        return 
Plugin_Handled;
    }
    
    if (
args == 0)
    {
        
ReplyToCommand(client"Must specify a sound name");
        return 
Plugin_Handled;
    }
    
    new 
String:gameSound[PLATFORM_MAX_PATH];
    
GetCmdArg(1gameSoundsizeof(gameSound));
    
    
EmitGameSoundToAll(gameSound);
    return 
Plugin_Handled;

You don't need to check client == 0 here

You may also want to TrimString, StripQuotes, then TrimString again.

PHP Code:
stock bool:EmitGameSoundToAll(const String:gameSound[],
                
entity SOUND_FROM_PLAYER,
                
flags SND_NOFLAGS,
                
speakerentity = -1,
                const 
Float:origin[3] = NULL_VECTOR,
                const 
Float:dir[3] = NULL_VECTOR,
                
bool:updatePos true,
                
Float:soundtime 0.0)
{
    new 
clients[MaxClients];
    new 
total 0;
    
    for (new 
i=1i<=MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
clients[total++] = i;
        }
        
        if (!
total)
        {
            return;
        }
        
        
EmitGameSound(clientstotalgameSoundentityflags,
            
speakerentityorigindirupdatePossoundtime);
    }

This seems horribly broken as that EmitGameSound will emit to existing clients (and not if the first client isn't ingame). You'll end up with something like the last TF2 update with the Demoman ;)

Last edited by KyleS; 10-09-2013 at 14:58.
KyleS is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-09-2013 , 16:47   Re: [ALL] Read Game Sounds
Reply With Quote #8

Quote:
Originally Posted by KyleS View Post
PHP Code:
public Action:Cmd_GameSoundAll(clientargs)
{
    if (
client == 0)
    {
        
ReplyToCommand(client"%t""Command is in-game only");
        return 
Plugin_Handled;
    }
    
    if (
args == 0)
    {
        
ReplyToCommand(client"Must specify a sound name");
        return 
Plugin_Handled;
    }
    
    new 
String:gameSound[PLATFORM_MAX_PATH];
    
GetCmdArg(1gameSoundsizeof(gameSound));
    
    
EmitGameSoundToAll(gameSound);
    return 
Plugin_Handled;

You don't need to check client == 0 here

You may also want to TrimString, StripQuotes, then TrimString again.
Actually, I thought I'd removed the client 0 check there... but it's a test plugin, so no real biggy there. Real world use case would be to pass a sound you have either hard-coded or in a configuration file.

Quote:
Originally Posted by KyleS View Post
PHP Code:
stock bool:EmitGameSoundToAll(const String:gameSound[],
                
entity SOUND_FROM_PLAYER,
                
flags SND_NOFLAGS,
                
speakerentity = -1,
                const 
Float:origin[3] = NULL_VECTOR,
                const 
Float:dir[3] = NULL_VECTOR,
                
bool:updatePos true,
                
Float:soundtime 0.0)
{
    new 
clients[MaxClients];
    new 
total 0;
    
    for (new 
i=1i<=MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
clients[total++] = i;
        }
        
        if (!
total)
        {
            return;
        }
        
        
EmitGameSound(clientstotalgameSoundentityflags,
            
speakerentityorigindirupdatePossoundtime);
    }

This seems horribly broken as that EmitGameSound will emit to existing clients (and not if the first client isn't ingame). You'll end up with something like the last TF2 update with the Demoman ;)
Whoops, I see what you mean. That second to last } should have been before the if !total.

I should have just copied EmitSoundToAll and changed it instead of retyping it.

Luckily, being a stock, it doesn't required an extension recompile, only a recompile of the plugin that uses it.
Attached Files
File Type: inc readgamesounds.inc (2.4 KB, 309 views)
File Type: sp Get Plugin or Get Source (test_readgamesounds.sp - 319 views - 2.2 KB)
File Type: smx test_readgamesounds.smx (4.8 KB, 319 views)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-09-2013 at 17:02.
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-09-2013 , 17:58   Re: [ALL] Read Game Sounds (v1.0 u1, 2013-10-09)
Reply With Quote #9

Actually, I have another stocks update. All the stocks should now return a boolean... their signatures were booleans before, but they didn't actually return anything.

Additionally, the EmitSound stock now returns false if the extension isn't loaded. Which means the other two do as well, since they return the value of EmitGameSound.
Attached Files
File Type: inc readgamesounds.inc (2.5 KB, 206 views)
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-10-2013 , 10:00   Re: [ALL] Read Game Sounds (v1.0 u2, 2013-10-09)
Reply With Quote #10

Turns out an EmitAmbientGameSound stock would be useful after all, so I added it.
Attached Files
File Type: inc readgamesounds.inc (3.3 KB, 321 views)
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 09:01.


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