How do detect multiple kills

Im trying to make a script where if a player gets # kills a sound plays it seems to be fairly simple but I just don’t know how to detect multi kills


if SERVER then 
	ply:Kill() then 
	sound.Play( "sound.wav", vPos )

Add 1 to a player’s kills with the PlayerDeath hook and reset on respawn.

sooo



if SERVER then 
	ply:Kill(1) then 
	sound.Play( "sound.wav", vPos )
end

and I dont need to have it reset I will shorten the sound file…

[LUA]hook.Add(“PlayerDeath”, “PlayKillSound”, function( ply, inflictor, attacker ) // Create a hook that is called when a player dies
local killsNeeded = 5 // The amount of kills needed for the sound to play
local soundPath = “path/to/sound.wav” // The path to the sound effect you want to play, relative to the sounds folder
if attacker:IsPlayer() && attacker:Frags() == killsNeeded then // Check that the killer is a player and has the amount of kills needed
attacker:EmitSound( soundPath ) // If so, make the player emit the sound. There are other ways of doing this, but this is simple and good enough.
end
end)[/LUA]

This must be in a serverside file in order for the hook to be called correctly.

For future reference, check out the Official Wiki and the Old Wiki to see what functions and hooks are available.

Thanks you finally someone that gives actual help and Ive been looking for awhile for that wiki thanks!

[editline]28th September 2013[/editline]

Not working I changed the path and kills but its not working…


hook.Add("PlayerDeath", "PlayKillSound", function( ply, inflictor, attacker ) // Create a hook that is called when a player dies
	local killsNeeded = 2 // The amount of kills needed for the sound to play
	local soundPath = "ohkillem.mp3" // The path to the sound effect you want to play, relative to the sounds folder
	if attacker:IsPlayer() && attacker:Frags() == killsNeeded then // Check that the killer is a player and has the amount of kills needed
		attacker:EmitSound( soundPath ) // If so, make the player emit the sound. There are other ways of doing this, but this is simple and good enough.
	end
end)

A better way would probably be to reset the kills ( in a row ) variable for the victim, and increment them for the attacker. That way, you could set up a system based on the number of kills they have.

It’s done the same way in the PlayerDeath hook, but you just attach the vars by:

[lua]ply._KillsInARow = 0;
attacker._KillsInARow = ( !attacker._KillsInARow ) and 1 or attacker._KillsInARow + 1;[/lua]

So, reset the victim to 0.

For incrementing, all it’s saying is assign the variable _KillsInARow to attacker, but first check to see if the variable is not assigned, if it isn’t then set it to 1, or set it to the variable + 1.

Then, after that, you can do your logic ( It could be done differently, and more dynamically but for the purpose of this example… ).

[lua]if ( attacker._KillsInARow == 3 ) then
// Play sound for 3 kills.
elseif ( attacker._KillsInARow == 5 ) then
// Play sound for 5 kills.
elseif ( attacker._KillsInARow == 10 ) then
// Play sound for 10 kills.
elseif ( attacker._KillsInARow == 15 ) then
// Play sound for 15 kills.
elseif ( attacker._KillsInARow == 20 ) then
// Play sound for 20 kills.
elseif ( attacker._KillsInARow == 30 ) then
// Play sound for 30 kills.
end[/lua]

As commented, the path is relative to the sounds folder. Take out the garrysmod/sound/ part.

Ok I did take out the gmod/sound but its still not working no errors though.