GM:EntityEmitSound

From Garry's Mod
Jump to: navigation, search
 GM:EntityEmitSound( )

Contents

Description

Called whenever a sound has been played.

Arguments

table data

Information about the played sound. Changes done to this table can be applied by returning true from this hook.
See EmitSoundInfo structure.

Returns

boolean

Return true to apply all changes done to the data table.
Return false to prevent the sound from playing.
Return nil or nothing to play the sound without altering it.

Examples

Example

Slows down all sounds to reflect game.SetTimeScale.

hook.Add( "EntityEmitSound", "TimeWarpSounds", function( t )
	
	local p = t.Pitch
	
	if ( game.GetTimeScale() != 1 ) then
		p = p * game.GetTimeScale()
	end
	
	if ( GetConVarNumber( "host_timescale" ) != 1 && GetConVarNumber( "sv_cheats" ) >= 1 ) then
		p = p * GetConVarNumber( "host_timescale" )
	end
	
	if ( p != t.Pitch ) then
		t.Pitch = math.Clamp( p, 0, 255 )
		return true
	end
	
	if ( CLIENT && engine.GetDemoPlaybackTimeScale() != 1 ) then
		t.Pitch = math.Clamp( t.Pitch * engine.GetDemoPlaybackTimeScale(), 0, 255 )
		return true
	end
	
end )


Personal tools
Navigation