AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   [Obsolete] [ALL] Read Game Sounds (v1.1, 2013-11-19) (https://forums.alliedmods.net/showthread.php?t=227648)

Powerlord 10-05-2013 03:20

[Obsolete] [ALL] Read Game Sounds (v1.1, 2013-11-19)
 
12 Attachment(s)
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.

Bacardi 10-05-2013 04:40

Re: [ALL] Read Game Sounds
 
2 Attachment(s)
uuh.. nice

also in-game
https://forums.alliedmods.net/attach...1&d=1380962402
*edit
soundscape not relative

Powerlord 10-05-2013 14:18

Re: [ALL] Read Game Sounds
 
Quote:

Originally Posted by Bacardi (Post 2045286)
uuh.. nice

also in-game
https://forums.alliedmods.net/attach...1&d=1380962402
*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.

Bacardi 10-05-2013 16:24

Re: [ALL] Read Game Sounds
 
yea, I was thinking where to look those game sounds entries ^^ without looking game_sounds.txt

Powerlord 10-06-2013 13:17

Re: [ALL] Read Game Sounds
 
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.

Powerlord 10-07-2013 11:24

Re: [ALL] Read Game Sounds
 
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.

KyleS 10-09-2013 14:52

Re: [ALL] Read Game Sounds
 
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 :o

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 ;)

Powerlord 10-09-2013 16:47

Re: [ALL] Read Game Sounds
 
4 Attachment(s)
Quote:

Originally Posted by KyleS (Post 2047071)
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 :o

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 (Post 2047071)
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.

Powerlord 10-09-2013 17:58

Re: [ALL] Read Game Sounds (v1.0 u1, 2013-10-09)
 
1 Attachment(s)
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.

Powerlord 10-10-2013 10:00

Re: [ALL] Read Game Sounds (v1.0 u2, 2013-10-09)
 
1 Attachment(s)
Turns out an EmitAmbientGameSound stock would be useful after all, so I added it.


All times are GMT -4. The time now is 22:53.

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