AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Play my sound of death (https://forums.alliedmods.net/showthread.php?t=346256)

Drimacus 02-17-2024 16:33

Play my sound of death
 
Hello!
Please help me play my sounds of death. I can block the standard death sounds (they are not heard and the message public Action:DeathSound appears in the chat).

Public Event_PlayerDeath does not work. I know that the delusional way, but there are no other options.
PHP Code:

#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#pragma semicolon 1

#define MAX_PATH_LENGTH 128

...

public 
OnPluginStart()
{
    
AddNormalSoundHook(DeathSound);
    
HookEvent("player_death"Event_PlayerDeath);
}

...

public 
Action:DeathSound(clients[64], &numClientsString:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
{
    if(
StrContains(sample"death"false) != -1)
    {
        
PrintToChatAll("\x04public Action:DeathSound");
        return 
Plugin_Handled;
    }
    return 
Plugin_Continue;
}

public 
Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    
decl String:path[MAX_PATH_LENGTH];
    
    
PrintToChatAll("\x04public Event_PlayerDeath");
    
    
Format(pathsizeof(path), "death%d.mp3"GetRandomInt(15));
    
EmitSoundToAll(path);



Bacardi 02-18-2024 01:24

Re: Play my sound of death
 
https://sm.alliedmods.net/new-api/ha.../PrecacheSound

Also, look other plugins source code. For examples.

Drimacus 02-18-2024 02:20

Re: Play my sound of death
 
There is a sound pre-sharpening.
PHP Code:

public OnMapStart()
{
    
decl String:file[MAX_PATH_LENGTH];
    
// Precache
    
for (new 1<= 5i++)
    {
        
Format(filesizeof(file), "death%d.mp3"i);
        
PrecacheSound(filetrue);
    }



Drimacus 02-18-2024 05:49

Re: Play my sound of death
 
That's how it works.
PHP Code:

public Action:DeathSound(clients[64], &numClientsString:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
{
    if (
StrContains(sample"death"false) != -1)
    {
        
decl String:file[MAX_PATH_LENGTH];
        
Format(filesizeof(file), "death%d.wav"GetRandomInt(15));
        
EmitSoundToAll(file);

        return 
Plugin_Handled;
    }

    return 
Plugin_Continue;


Can you tell me how to get a specific player in "public Action:DeathSound" to play a sound for him?
PHP Code:

new client GetClientOfUserId(GetEventInt(event"userid")); 

doesn't work because of missing event.

Bacardi 02-18-2024 06:19

Re: Play my sound of death
 
Usually there is "userid" in player_death.
Would help if you tell us, what is a game?

There are many many hl2 games and have own differences.

Drimacus 02-18-2024 09:02

Re: Play my sound of death
 
Game Counter-Strike: Source.

Bacardi 02-18-2024 10:20

Re: Play my sound of death
 
Ok.
Not sure why you not get it work, I have not seen your whole plugin.

I can't help much for now, I do other things.

Anyway, have you try similiar plugins ?
https://www.sourcemod.net/plugins.ph...Sound&search=1

Drimacus 02-19-2024 02:15

Re: Play my sound of death
 
Solved.
PHP Code:

public OnPluginStart()
{
    
AddNormalSoundHook(DeathSound);
}

public 
Action:DeathSound(clients[64], &numClientsString:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
{
    if (
StrContains(sample"kevlar"false) != -1)
    {
        
FormatEx(samplesizeof(sample), "hitkill/hit%d.wav"GetRandomInt(1GetConVarInt(cvarHitSoundsCount)));
        return 
Plugin_Changed;
    }
    if (
StrContains(sample"death"false) != -1)
    {
        
FormatEx(samplesizeof(sample), "hitkill/death%d.wav"GetRandomInt(1GetConVarInt(cvarDeathSoundsCount)));
        return 
Plugin_Changed;
    }
    if (
StrContains(sample"headshot"false) != -1)
    {
        
FormatEx(samplesizeof(sample), "hitkill/headshot%d.wav"GetRandomInt(1GetConVarInt(cvarHeadshotSoundsCount)));
        return 
Plugin_Changed;
    }

    return 
Plugin_Continue;




All times are GMT -4. The time now is 13:25.

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