Garry's Mod Wiki

GM:PlayerDeathSound

  boolean GM:PlayerDeathSound( Player ply )

Description

Returns whether or not the default death sound should be muted.

Arguments

1 Player ply
The player

Returns

1 boolean
Mute death sound

Example

Plays a new sound for the player's demise.

hook.Add( "PlayerDeathSound", "CustomPlayerDeath", function( ply ) ply:EmitSound( "beams/beamstart5.wav", SNDLVL_NORM, math.random( 70, 126 ) ) -- plays the sound with normal sound levels, and a random pitch between 70 and 126 return true -- we don't want the default sound! end )

Example

Picks from a list of sounds and plays a certain one depending on the network variable applied to Player 1. Otherwise, it will play a fallback sound along with the original sound.

local p1 = Entity( 1 ) -- returns player 1 local sndtbl = { "beams/beamstart5", "plats/bigstop1", "friends/message", "ambient/alarms/warningbell1", "vo/ravenholm/madlaugh03" } -- random selection of sounds for our purpose p1:SetNWInt( "DSound", math.random( 1, #sndtbl ) ) -- pick a random number from 1 to the maximum amount of entries our table has hook.Add( "PlayerDeathSound", "SelectedSound", function( ply ) local snd = sndtbl[ p1:GetNWInt( "DSound", 1 ) ] if TypeID(snd) == TYPE_STRING then ply:EmitSound( snd .. ".wav" ) return true else -- fallback behavior print( "Sound does not exist in table, error!" ) ply:EmitSound( "common/bugreporter_failed.wav" ) return false -- let's make it clear that we do actually have a problem when it doesn't mute the original sound end end )