Garry's Mod Wiki

Entity:EmitSound

  Entity:EmitSound( string soundName, number soundLevel = 75, number pitchPercent = 100, number volume = 1, number channel = CHAN_AUTO, CHAN_WEAPON for weapons, number soundFlags = 0, number dsp = 1, CRecipientFilter filter = nil )

Description

Plays a sound on an entity. See also EmitSound if you wish to play sounds without an entity.

If run clientside, the sound will only be heard locally.
If used on a player or NPC character with the mouth rigged, the character will "lip-sync" if the sound file contains lipsync data. See this page for more information.

When using this function with weapons, use the Weapon itself as the entity, not its owner!
Due to engine quirks, sound scripts can't have their soundlevel, pitch, volume, or channel changed when played from an entity—the sound script parameters will override whatever you pass to this function.

You can do one of these instead:

  • Use sound.GetProperties to select a sound from the script, and play the sound file directly.
  • For single-use sounds, you can pass the SND_CHANGE_VOL or SND_CHANGE_PITCH sound flags. However, this will change the volume or pitch of the sound if it's already playing, instead of starting the sound over or playing another instance.
  • Use EmitSound with the entity parameter set to the Entity:EntIndex of the entity you want to play the sound on.
This does not respond to SuppressHostEvents.

Issue Tracker: 2651

Arguments

1 string soundName
The name of the sound to be played.

This should either be a sound script name (sound.Add) or a file path relative to the sound/ folder. (so don't include sound/, and make note that it's not sounds when moving the sound file itself)

The string cannot have whitespace at the start or end. You can remove this with string.Trim.
2 number soundLevel = 75
A modifier for the distance this sound will reach, acceptable range is 0 to 511. 100 means no adjustment to the level. See SNDLVL enum
3 number pitchPercent = 100
The pitch applied to the sound. The acceptable range is from 0 to 255. 100 means the pitch is not changed.
4 number volume = 1
The volume, from 0 to 1.
5 number channel = CHAN_AUTO, CHAN_WEAPON for weapons
The sound channel, see CHAN enum.
6 number soundFlags = 0
The flags of the sound, see SND enum
7 number dsp = 1
The DSP preset for this sound. List of DSP presets
8 CRecipientFilter filter = nil
If set serverside, the sound will only be networked to the clients in the filter.

Example

Plays sound from the first player on the server.

Entity(1):EmitSound( "garrysmod/save_load1.wav", 75, 100, 1, CHAN_AUTO ) -- Same as below Entity(1):EmitSound( "garrysmod/save_load1.wav" ) -- You can remove the arguments that have default values. Entity(1):EmitSound( "Weapon_AR2.Single" )