Raised This Month: $51 Target: $400
 12% 

[TF2]How to make a sound play when player died?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vladimirdog2021
Junior Member
Join Date: Sep 2022
Location: Romania
Old 04-08-2023 , 10:52   [TF2]How to make a sound play when player died?
Reply With Quote #1

I need help making a SourceMod plugin for when a player dies, a sound clip plays.

Every time I try to make one, I cannot code in everything to make the sound play.

Is there a way to make a sound play when a player dies?
__________________
vladimirdog2021 is offline
TotalChaos SourcePawner
Senior Member
Join Date: Feb 2023
Location: IN PINEAPPLE, UNDER SEA
Old 04-08-2023 , 13:35   Re: [TF2]How to make a sound play when player died?
Reply With Quote #2

1. I'm pretty sure this should be in the "Scripting" section, not the "General" section.
2. https://wiki.alliedmods.net/Team_For...s#player_death
TotalChaos SourcePawner is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 04-08-2023 , 15:36   Re: [TF2]How to make a sound play when player died?
Reply With Quote #3

When any player dies? Or just when a specific player dies?
PC Gamer is offline
vladimirdog2021
Junior Member
Join Date: Sep 2022
Location: Romania
Old 04-08-2023 , 17:08   Re: [TF2]How to make a sound play when player died?
Reply With Quote #4

Quote:
Originally Posted by PC Gamer View Post
When any player dies? Or just when a specific player dies?
The answer's yes, fortunately.
Is there a way to make a sound play when a player died in Team Fortress 2?
__________________
vladimirdog2021 is offline
TotalChaos SourcePawner
Senior Member
Join Date: Feb 2023
Location: IN PINEAPPLE, UNDER SEA
Old 04-08-2023 , 17:24   Re: [TF2]How to make a sound play when player died?
Reply With Quote #5

Code:
public OnPluginStart()
{
	AddFileToDownloadsTable("sound/deathsound/deathsound.mp3"); //Add custom sound to downloads table.
	PrecacheSound("*/deathsound/deathsound.mp3", true); //Precache it.
	PrefetchSound("*/deathsound/deathsound.mp3"); //Then finally prefetch it. Whatever that means.

	HookEvent("player_death", Event_PlayerDeath); //When you die, the plugin gets told and will do something when it finds out.
}

public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) //Do something when you die.
{
	int client = event.GetInt("userid"); //Get the client who died.
	ClientCommand( client, "play */deathsound/deathsound.mp3" ); //Play the sound via the "play" command to the victim.
	EmitSoundToClient(client, "*/deathsound/deathsound.mp3"); //Play the sound via EmitSoundToClient to the victim.
}
NOTE: This is untested, but this should be a good start.
NOTE 2:
I've had issues with the various EmitSounds before, ranging from not playing at all to not playing to everybody to playing to everybody.
It's kinda random, and I don't fully understand it.

Last edited by TotalChaos SourcePawner; 04-08-2023 at 17:28.
TotalChaos SourcePawner is offline
vladimirdog2021
Junior Member
Join Date: Sep 2022
Location: Romania
Old 04-08-2023 , 17:25   Re: [TF2]How to make a sound play when player died?
Reply With Quote #6

Good list. Thank you for posting.
__________________
vladimirdog2021 is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 04-10-2023 , 00:25   Re: [TF2]How to make a sound play when player died?
Reply With Quote #7

Quote:
Originally Posted by vladimirdog2021 View Post
The answer's yes, fortunately.
Is there a way to make a sound play when a player died in Team Fortress 2?
Do you want the sound to only play to the player that died and everyone near them? Or do you want every player to hear it?

This will play a gamesound to the player when he dies. I play the sound twice which makes the volume louder. I added a check to ensure that the sound is only played to human players, not bots.

PHP Code:
#include <tf2_stocks>

#pragma semicolon 1
#pragma newdecls required

#define DEATH    "/misc/taps_02.wav"

public Plugin myinfo =
{
    
name "[TF2] Play Sound on Death",
    
author "vladimirdog2021",
    
description "Play a sound when player dies",
    
version "1.0",
    
url ""
}

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

public 
void OnMapStart()
{
    
PrecacheSound(DEATH);
}

public 
void Event_Death(Handle hEventchar[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(hEvent"userid"));
    
    if(!
IsFakeClient(client))
    {
        
EmitSoundToClient(clientDEATH);
        
EmitSoundToClient(clientDEATH);
    }


Last edited by PC Gamer; 04-10-2023 at 01:20.
PC Gamer is offline
vladimirdog2021
Junior Member
Join Date: Sep 2022
Location: Romania
Old 04-10-2023 , 04:30   Re: [TF2]How to make a sound play when player died?
Reply With Quote #8

That.

And the sound should only play when you or your teammates die in Team Fortress 2 and not the enemy players.
__________________
vladimirdog2021 is offline
vladimirdog2021
Junior Member
Join Date: Sep 2022
Location: Romania
Old 04-15-2023 , 07:45   Re: [TF2]How to make a sound play when player died?
Reply With Quote #9

Does the plugin play the sound if it's enabled?
__________________
vladimirdog2021 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 17:41.


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