Playing a sound for the killer

I’m trying to make a script that will play a sound for and only for the person that kills someone, if you know how to do this / have an example then i’d appreciate info, i can’t find anything on the wiki

Use this: http://wiki.garrysmod.com/?title=Gamemode.PlayerDeath

In conjunction with:


player:SendLua( "surface.PlaySound( \"soundfile.wav\" )" )

actually, I want something a bit different, and I know this won’t work but i’m just giving an example, can any kind sir or madame help me?

[lua]function playerDies( victim, weapon, killer )

killer:DoSound()

end

hook.Add( “PlayerDeath”, “playerDeathTest”, playerDies )

local function DoSound( ply, snd, num )
if ValidEntity(ply) then
ply:EmitSound("", 100, 100)
end
end
end[/lua]

[Lua]function playerDies( victim, weapon, killer )

victim:EmitSound("vo/npc/male01/pain0" .. tostring(math.random(7,9)) .. ".wav", 100,100)

killer:EmitSound("vo

pc\male01\yeah02.wav", 100,100)

end

hook.Add( “PlayerDeath”, “playerDeathTest”, playerDies )[/LUA]

Something like that?

Thanks, it works, but the ‘yeah’ sound plays even if the player kills himself. Is there any check for it to see if it was killed by another player?

[LUA]function playerDies( victim, weapon, killer )

victim:EmitSound("vo/npc/male01/pain0" .. tostring(math.random(7,9)) .. ".wav", 100,100)

    if killer != victim then

        killer:EmitSound("vo

pc\male01\yeah02.wav", 100,100)

    end

end

hook.Add( “PlayerDeath”, “playerDeathTest”, playerDies )[/LUA]

That might work, didn’t test though.

Nope, that just seems to screw up the gamemode, I added it and it broke, took it out and it works.

He’s making a gamemode, why are you suggest he uses a hook?