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

[L4D/2] Play sound on Survivor death


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eargosedown
Member
Join Date: Jan 2010
Old 07-21-2010 , 17:50   [L4D/2] Play sound on Survivor death
Reply With Quote #1

I'm looking to run a plugin that will send a sound to all active players when a survivor dies. If anyone could either make one or explain how one would go about coding one, it'd be most appreciated!
eargosedown is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 07-21-2010 , 20:49   Re: [L4D/2] Play sound on Survivor death
Reply With Quote #2

create a plugin..
in OnPluginStart()
make a hook for player_death
in "player_death"
get the id of the client who dies and check to make sure it is a player (1 <= client <= MaxClients)
then check that it is a survivor (GetClientTeam(client) == 2)
if you get errors about the client, also check before the team: IsClientInGame(client)
if so EmitSound(...)

you will most likely have to precache the soundfile in OnMapStart()
dirka_dirka is offline
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 07-23-2010 , 22:50   Re: [L4D/2] Play sound on Survivor death
Reply With Quote #3

Uhm, being a little more specific, read this :P...

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

//Define the desired soundfile to play relative to the sounds folder. (This means not to include the sound/ when specifing the file)
#define RANDOM_STRING "music/example.wav"

/*
    plugin info
*/

//When the plugin loads
public OnPluginStart()
{
    
HookEvent("player_death"OnPlayerDeath); //Hook the event when a player dies
}

//When the map loads
public OnMapStart()
{
    
PrecacheSound(RANDOM_STRING); //Precache the sound, if you don't to that the engine won't recognize and won't be played.
}

public 
OnPlayerDeath(Handle:eventString:event_name[], bool:dontBroadcast//The event as a function
{
    new 
client GetClientOfUserId(GetEventInt(event"userid")); //New client index got from the user id who died.
    
new attacker GetClientOfUserId(GetEventInt(event"attacker")); //New client index got from the userid who killed.
    
if(client //Make sure the client is higher than zero, 0 means it isnt valid or is world (server)
    
&& IsValidEntity(client//Make sure the client is a valid entity
    
&& IsClientInGame(client//Make sure the player is ingame
    
&& !IsFakeClient(client//Addtionally, if you dont want it to fire on fake clients (bots), add this line
    
)
    {
        
//If the client passes the filters avobe, procced to emit the sound for all clients
        
        //If you want to emit a sound to everybody on their own position, do:
        
EmitSoundToAll(RANDOM_STRING);
        
        
//If you want to emit a sound to everybody, from the client's position, do:
        
EmitSoundToAll(RANDOM_STRINGclient);
        
        
//If you want to emit a sound to the attacker, do:
        
        //As above, check the attacker is valid. But you MUST add the filter to consider human players only.
        
if(attacker 0
        
&& IsValidEntity(attacker)
        && 
IsClientInGame(attacker)
        && !
IsFakeClient(attacker)
        )
        {
            
EmitSoundToClient(attackerRANDOM_STRING);
        }
    }

Hope it helps :)
honorcode23 is offline
Searcher64
Senior Member
Join Date: Apr 2010
Old 07-24-2010 , 13:44   Re: [L4D/2] Play sound on Survivor death
Reply With Quote #4

In case anyone did not notice, this is the plugins ideas/requests section, not the scripting
Searcher64 is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 07-24-2010 , 14:53   Re: [L4D/2] Play sound on Survivor death
Reply With Quote #5

Quote:
Originally Posted by Searcher64 View Post
In case anyone did not notice, this is the plugins ideas/requests section, not the scripting
he REQUESTED and he RECEIVED.. oh and:
Quote:
Originally Posted by eargosedown View Post
or explain how one would go about coding one
is why he got my response.
dirka_dirka is offline
eargosedown
Member
Join Date: Jan 2010
Old 07-25-2010 , 03:58   Re: [L4D/2] Play sound on Survivor death
Reply With Quote #6

Thanks for taking the time guys! Huge help!

I'm simply triggering player death music for all survivors in campaign mode =]
eargosedown 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 16:49.


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