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:event, String: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 > 0 //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_STRING, client);
//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(attacker, RANDOM_STRING);
}
}
}
Hope it helps :)