Raised This Month: $32 Target: $400
 8% 

Solved [CSGO] Help correctly calling EmitAmbientSoundAny()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Austin
Senior Member
Join Date: Oct 2005
Old 10-06-2021 , 15:59   [CSGO] Help correctly calling EmitAmbientSoundAny()
Reply With Quote #1

CSGO will play a death sound for about 1 in 50 deaths.
I wrote a plugin to play these same sounds more often and it is working,
but the sounds are not played exactly the same as CSGO plays them.

If the victim is far away it still sounds like it is close and since I am the only player on the server right now I am not sure everyone hears the sound.

Can someone show me the correct function and parms to use so the victim’s sound
1) originates from the victim
2) all players hear the sound
3) the sound is location specific to each player’s position
4) the sound volume is location specific to each player’s position.

PHP Code:
public void OnPluginStart()
{
    
HookEvent("player_death",        Event_PlayerDeath,        EventHookMode_Post);
    
AddNormalSoundHook(SoundHook2);
}

public 
Action:SoundHook2(clients[64], &numClientsString:sound[PLATFORM_MAX_PATH], &client, &channel, &Float:volume, &level, &pitch, &flags)
{
    if(
StrContains(sound"death") > -1)
        
PrintToServer("Sound=%s Channel=%d Volume=%f Level=%f Pitch=%f Flags=%d"soundchannelvolumelevelpitchflags);
    return 
Plugin_Continue;
}

public 
OnMapStart()
{
    
PrecacheSound("player/death1.wav"true);
}

public 
Action Event_PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
int attacker GetClientOfUserId(event.GetInt("attacker"));
    
int victim   GetClientOfUserId(event.GetInt("userid"));

    new 
Float:attackerLocation[3];
    new 
Float:victimLocation[3];

    
GetClientAbsOrigin(attackerattackerLocation);
    
GetClientAbsOrigin(victim,   victimLocation);

    
// this compiles but doesn't generate any sound
    
EmitAmbientSoundAny("player/death1.wav"victimLocation,    victim);

    
// this works but doesn't seem to have location and distance information
    
EmitSoundToAll("player/death1.wav"attacker);

    return 
Plugin_Continue;


Last edited by Austin; 10-07-2021 at 03:29.
Austin is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-06-2021 , 16:11   Re: [CSGO] Help correctly calling EmitAmbientSoundAny()
Reply With Quote #2

You can try using SoundHook to find the correct parameters.
(Output the values to the chat)
__________________
Marttt is online now
Austin
Senior Member
Join Date: Oct 2005
Old 10-06-2021 , 17:26   Re: [CSGO] Help correctly calling EmitAmbientSoundAny()
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
You can try using SoundHook to find the correct parameters.
(Output the values to the chat)
Very good to know about sound hooking, thanks!

I added a sound hook to print out the exact same death sounds I am using but
1) I still don’t know what sound function to call
Or
2) what parms to use

I updated my original post with the sound hook added and here is the output.

Sound=~player/death1.wav Channel=2 Volume=0.699707 Level=0.000000 Pitch=0.000000 Flags=1024
Sound=~player/death5.wav Channel=2 Volume=0.699707 Level=0.000000 Pitch=0.000000 Flags=1024
Sound=~player/death5.wav Channel=2 Volume=0.699707 Level=0.000000 Pitch=0.000000 Flags=1024
Sound=~player/death3.wav Channel=2 Volume=0.699707 Level=0.000000 Pitch=0.000000 Flags=1024
Sound=~player/death6.wav Channel=2 Volume=0.699707 Level=0.000000 Pitch=0.000000 Flags=1024
Sound=~player/death1.wav Channel=2 Volume=0.699707 Level=0.000000 Pitch=0.000000 Flags=1024
Sound=~player/death2.wav Channel=2 Volume=0.699707 Level=0.000000 Pitch=0.000000 Flags=1024
Sound=~player/death4.wav Channel=2 Volume=0.699707 Level=0.000000 Pitch=0.000000 Flags=1024
Sound=~player/death6.wav Channel=2 Volume=0.699707 Level=0.000000 Pitch=0.000000 Flags=1024


And for the sound hooking I disabled my sound generation while testing...

Last edited by Austin; 10-06-2021 at 17:29.
Austin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-06-2021 , 18:10   Re: [CSGO] Help correctly calling EmitAmbientSoundAny()
Reply With Quote #4

What I tested, CS:GO use so called CHAR_HRTF '~' on death sounds.
This turn sound file to work... "Head Related Transfer Function, spatialization for non-owners", and it somehow suck.
Even soundlevel is over 300 but it won't work right like "older" HL2 games.

Here sample plugin to stop game own ~player/death sound.
On next frame Emitsound to all )player/death (I think you not need add char prefix at all).

https://sm.alliedmods.net/new-api/sdktools_sound/__raw
level = you can set range how far sound would hear
volume = use 1.0, if too loud in close range, set volume lower and increase level range. 511 is max level.

something
__________________
Do not Private Message @me
Bacardi is offline
Austin
Senior Member
Join Date: Oct 2005
Old 10-07-2021 , 03:28   Re: [CSGO] Help correctly calling EmitAmbientSoundAny()
Reply With Quote #5

I tried everything and a lot more and still no joy…
I then decided to do a search for sound plugins,
which I did before and spent a lot of time on it with no joy.
https://www.sourcemod.net/plugins.ph...tion=&search=1

But THIS time after a lot of looking through plugin source I found this one.
https://forums.alliedmods.net/showthread.php?p=926914

And it had this cvar with an interesting comment.
PHP Code:
g_emit CreateConVar("sm_deathsound_emit""1"
   
"1 - Emits a sound at the position of the dead player\n0 - Plays the sound directly to the players"_true0.0true1.0); 
It plays the sound like csgo with direction and distance information!
(Thanks Keksmampfer)
!!!

My finished plugin is a bit more complicated and plays different sounds for normal, knife,
headshot, grenade, and fire grenade kill and uses all of the death sounds from the
vpk files and it cycles through them to give a sort of randomness to the sounds.

Here is the working simplest example on how to get the sound I was looking for.
PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#pragma semicolon 1

public void OnPluginStart()
{
    
HookEvent("player_death"Event_PlayerDeathEventHookMode_Post);
}

public 
OnMapStart()
{
    
PrecacheSound("player/death1.wav"true);
}

public 
Action Event_PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
int victim GetClientOfUserId(event.GetInt("userid"));
    new 
Float:victimLocation[3];
    
GetClientAbsOrigin(victimvictimLocation);

    
//  play the death sound to all alive humans with distance and direction information
    
for (int client 1client <= MaxClientsclient++)
        if (
IsClientInGame(client) && !IsFakeClient(client) && IsPlayerAlive(client))
            
EmitSoundToClient(client,"player/death1.wav",SOUND_FROM_WORLDSNDCHAN_AUTO,SNDLEVEL_NORMALSND_NOFLAGSSNDVOL_NORMALSNDPITCH_NORMAL, -1victimLocation);
    return 
Plugin_Continue;

Again, as always thanks guys for all the help.
I am still learning about many things in Sourcemod and I have been learning alot from everyone....

Last edited by Austin; 10-07-2021 at 03:33.
Austin is offline
Austin
Senior Member
Join Date: Oct 2005
Old 10-07-2021 , 04:44   Re: [CSGO] Help correctly calling EmitAmbientSoundAny()
Reply With Quote #6

In case anyone wants to see the final plugin.
There are 4 cvars with values of 1 to 10
to set the chance of that death sound playing.
Default values are 10 = always play

sm_headshotSound
sm_grenadeSound
sm_knifeSound
sm_anySound

And I can upload inc files but the compile fails.
I had to stuff the sounds from the inc file into the sp file to properly upload it.

Does the web complier not support inc files?
Attached Files
File Type: sp Get Plugin or Get Source (ABS_CSGO_DeathSounds.sp - 66 views - 8.4 KB)

Last edited by Austin; 10-07-2021 at 04:50.
Austin is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-07-2021 , 11:36   Re: [CSGO] Help correctly calling EmitAmbientSoundAny()
Reply With Quote #7

Web compiler doesn't support inc files at the moment.
Usually, people upload the .inc file aswell.
__________________
Marttt is online now
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 20:40.


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