View Single Post
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