AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   [L4D/2] Play sound on Survivor death (https://forums.alliedmods.net/showthread.php?t=133084)

eargosedown 07-21-2010 17:50

[L4D/2] Play sound on Survivor death
 
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! :D

dirka_dirka 07-21-2010 20:49

Re: [L4D/2] Play sound on Survivor death
 
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()

honorcode23 07-23-2010 22:50

Re: [L4D/2] Play sound on Survivor death
 
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 :)

Searcher64 07-24-2010 13:44

Re: [L4D/2] Play sound on Survivor death
 
In case anyone did not notice, this is the plugins ideas/requests section, not the scripting

dirka_dirka 07-24-2010 14:53

Re: [L4D/2] Play sound on Survivor death
 
Quote:

Originally Posted by Searcher64 (Post 1250260)
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 (Post 1247194)
or explain how one would go about coding one

is why he got my response.

eargosedown 07-25-2010 03:58

Re: [L4D/2] Play sound on Survivor death
 
Thanks for taking the time guys! Huge help! :D

I'm simply triggering player death music for all survivors in campaign mode =]


All times are GMT -4. The time now is 03:42.

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