Raised This Month: $ Target: $400
 0% 

EmitSoundToClient are not working sometimes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
renancavalieri
AlliedModders Donor
Join Date: Feb 2015
Old 02-17-2015 , 09:37   EmitSoundToClient are not working sometimes
Reply With Quote #1

Hello, i trying to play a "MvM Sound" each time the round start on my server, but sometimes i can't heard that.

PHP Code:
#include <sourcemod>
#include <sdktools>

#define SOUND_MVM       "music/mvm_start_wave.wav"

public OnPluginStart()
{
    
HookEvent("teamplay_round_start"playSound_MvM);
}

public 
OnMapStart()
{
    
PrecacheSound(SOUND_MVM);
}

public 
Action:playSound_MvM(Handle:event, const String:name[], bool:dontBroadcast){
    for(new 
i=1i<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && IsPlayerAlive(i))
        {
            
EmitSoundToClient(i,SOUND_MVM);
        }
        
    }
    return 
Plugin_Handled

Client is on the game (TRUE) and is alive (TRUE) and round has started, but sometimes sound fails (not for all).

When i reload the plugin, it works again, but when clients disconnect or connect, fails sometimes.

What happened?
renancavalieri is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-17-2015 , 09:58   Re: EmitSoundToClient are not working sometimes
Reply With Quote #2

Out of curiosity, does it exhibit these problems if you use EmitSoundToAll instead?

Incidentally, I wrote a plugin that did something like this for April Fools one year, I should dig around an see if I still have it.

Edit: I don't have said plugin any more, at least not on this computer or in any of my regular GitHub repos.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 02-17-2015 at 11:20.
Powerlord is offline
renancavalieri
AlliedModders Donor
Join Date: Feb 2015
Old 02-19-2015 , 06:37   Re: EmitSoundToClient are not working sometimes
Reply With Quote #3

Thanks for the reply Powerlord.

I used "EmitSoundToAll", it works but create a huge spam, the sound was emited from every player on the server lol.

Edit: I used EmitSoundToAll in another plugin to create "say sounds", it works fine, the main problem is emit for each client without causing spam.

Last edited by renancavalieri; 02-19-2015 at 06:51.
renancavalieri is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-19-2015 , 09:33   Re: EmitSoundToClient are not working sometimes
Reply With Quote #4

As long as the entity argument is SOUND_FROM_PLAYER and has no position, it should just emit from the player themselves. Not sure why it would do something differently.

Anyway, if it's working with EmitSoundToAll and not EmitSoundToClient, it sounds like it doesn't like something that's being done.

Does this still happen if you do something like this?

PHP Code:
public Action:playSound_MvM(Handle:event, const String:name[], bool:dontBroadcast){
    new 
clients[MaxClients];
    new 
count 0;
    for(new 
i=1i<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && IsPlayerAlive(i))
        {
            
clients[count] = i;
            
count++;
        }
        
    }
    
EmitSound(clientscountSOUND_MVM);
    return 
Plugin_Handled;

Granted, the only different between this and EmitSoundToAll is that it won't emit to dead players.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
renancavalieri
AlliedModders Donor
Join Date: Feb 2015
Old 02-19-2015 , 13:28   Re: EmitSoundToClient are not working sometimes
Reply With Quote #5

This is new for me, i never understood the "EmitSound" functions, hehe. I'll try.

Thanks Again Powerlord.
renancavalieri is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-19-2015 , 13:58   Re: EmitSoundToClient are not working sometimes
Reply With Quote #6

Quote:
Originally Posted by renancavalieri View Post
This is new for me, i never understood the "EmitSound" functions, hehe. I'll try.

Thanks Again Powerlord.
EmitSoundToAll and EmitSoundToClient are both stocks that act as wrappers for EmitSound.

EmitAmbientSound is its own thing for emitting a sound in the environment itself, usually from a fixed position.

OK, so those are the basic sound commands.

However, there are two more advanced sound commands present: PrecacheScriptSound and GetGameSoundParams.

These functions deal with the game's game_sounds files.

As a quick example for TF2:

PHP Code:
new channel;
new 
soundLevel;
new 
Float:volume;
new 
pitch;
new 
String:sample[PLATFORM_MAX_PATH];

GetGameSoundParams("Game.Overtime"channelsoundLevelvolumepitchsamplesizeof(sample)); 
would leave you with:
  • channel = 7 (the VOICE2 / Announcer channel in TF2)
  • soundLevel = 140
  • volume = 1.0
  • pitch = PITCH_NORM (I forgot what value this is)
  • and sample = one of these values (at random):
    • "vo/announcer_overtime.wav"
    • "vo/announcer_overtime2.wav"
    • "vo/announcer_overtime3.wav"
    • "vo/announcer_overtime4.wav"

Of course, it's a lot of work to do that, so I could just do EmitGameSoundToAll("Game.Overtime"); instead. That's because EmitGameSound* is a wrapper around GetGameSoundParams and EmitSound.

PrecacheScriptSound is to make sure all the sounds for GetGameSoundParams are precached. It shouldn't be necessary as the game usually does this up front. It may have more of a use in the future.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
renancavalieri
AlliedModders Donor
Join Date: Feb 2015
Old 03-01-2015 , 20:28   Re: EmitSoundToClient are not working sometimes
Reply With Quote #7

Powerlord, you solved my problem, thanks!
renancavalieri is offline
Reply



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 14:08.


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