Garry's Mod Wiki

Revision Difference

GM:EntityEmitSound#511354

<function name="EntityEmitSound" parent="GM" type="hook"> <ishook>yes</ishook> <description> Called whenever a sound has been played. This will not be called clientside if the server played the sound without the client also calling <page>Entity:EmitSound</page>. <bug issue="1021">This is not called for scripted sequences.</bug> </description> <realm>Shared</realm> <predicted>No</predicted> <args> <arg name="data" type="table">Information about the played sound. Changes done to this table can be applied by returning true from this hook.&#xA;&#xA;See &lt;page&gt;EmitSoundInfo&lt;/page&gt;.</arg> </args> <rets> <ret name="" type="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.</ret> </rets> </function> <example> <description>Slows down all sounds to reflect <page>game.SetTimeScale</page>.</description> <code> 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 &amp;&amp; GetConVarNumber( "sv_cheats" ) &amp;gt;= 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 &amp;&amp; engine.GetDemoPlaybackTimeScale() != 1 ) then t.Pitch = math.Clamp( t.Pitch * engine.GetDemoPlaybackTimeScale(), 0, 255 ) return true end end ) </code> </example>