Play a sound when player kills another player

Right, I’m a total noob at LUA so could someone create a very quick addon. Just need a sound to be played when a player kills another player. If someone could do that it would be awesome, thanks :slight_smile:

“I don’t want to even try so can u pls do all of the work for me so i can make my shitty server even shittier k thanks”

People here aren’t going to spoon-feed you because you won’t learn anything from it, however we will guide you in the right direction

What you’re asking for is very simple - all you need to do is detect when a player dies and then play a sound, you can easily put this together by browsing the gmod wiki for five minutes

Use this as a starting point:

Serverside or clientside?

[editline]18th July 2015[/editline]

Big server guy have here only will help his other big server friends :slight_smile:

You could modify the code on the gmod website you know that Niandralades posted (NOTE SERVERSIDE NOT CLIENTSIDE)

function GM:PlayerDeath( victim, inflictor, attacker )
	if ( victim == attacker ) then
		PrintMessage( HUD_PRINTTALK, victim:Name() .. " committed suicide." )
                Surface.PlaySound ("buttons/button1.wav")
		PrintMessage( HUD_PRINTTALK, victim:Name() .. " was killed by " .. attacker:Name() .. "." )
                 Surface.PlaySound ("buttons/button16.wav")

GM functions are never clientside if it was then if you died and nobody would see.

Use the playerdeath hook


Do you even facepunch? He’s making a correct point, you don’t just go on and ask for (side-note: an extremely simple) code.
He’s not saying “Help me code”, “Let me know how to make”, he is LITTERALY saying “Give me this code plz k thx”

blatantly untrue

go browse the gmod wiki

there are serverside, shared, and clientside gamemode functions

[editline]18th July 2015[/editline]

i don’t even run a server anymore lol

Detect when a player dies, then check if the attacker is also a player and make sure the attacker is not equal to the victim (suicide). Then if that is the case, play your sound. Now it’s up to you to code that. Hint: It can be done in 5 lines easily.

Well the actual hook is but I ment when it is like function GM:PlayerDeath() end The actual function is called in the serverside class.