Entity/EmitSound

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Changed up the wording to more closely represent the old wiki's page. I'm assuming much hasn't changed regarding this function.)
 
(20 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=EmitSound
+
|Description=Plays a sound on an entity. If run clientside, the sound will only be heard locally.
|Parent=Entity
+
 
|Description=Plays a sound on an entity.
+
If used on a player or NPC character with the mouth rigged, the character will "lip-sync". This does not work with all sound files.
 +
 
 +
It is recommended to use sound scripts ( see {{LibraryFunction|sound|Add}} ) over direct file paths. This will allow you to use {{ClassFunction|Entity|StopSound}} to stop the played sound scripts.
 +
 
 +
{{Note|When using this function with weapons, use the {{Type|Weapon}} itself as the entity, not its owner!}}
 +
 
 +
{{Warning|Do not use this for looping sounds with a filepath: see {{ClassFunction|Entity|StopSound}} for more details.}}
 +
 
 +
{{Bug|Issue=2651|This does not respond to {{GlobalFunction|SuppressHostEvents}}.}}
 
|Realm=Shared
 
|Realm=Shared
 
|IsClass=Yes
 
|IsClass=Yes
Line 10: Line 18:
 
|name=soundName
 
|name=soundName
 
|desc=The name of the sound to be played.
 
|desc=The name of the sound to be played.
 +
{{Warning|The string will cannot have whitespace at the start or end. You can remove this with {{LibraryFunction|string|Trim}}.}}
 
}}
 
}}
 
{{Arg
 
{{Arg
 
|type=number
 
|type=number
 
|name=soundLevel
 
|name=soundLevel
|desc=A modifier for the distance this sound will reach, acceptable range is 0 to 511. 100 means no adjustment to the level.
+
|desc=A modifier for the distance this sound will reach, acceptable range is 0 to 511. 100 means no adjustment to the level. See {{Enum|SNDLVL}}
 +
 
 +
Will not work if a [https://developer.valvesoftware.com/wiki/Soundscripts sound script] is used.
 +
|default=75
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 20: Line 32:
 
|name=pitchPercent
 
|name=pitchPercent
 
|desc=The pitch applied to the sound. The acceptable range is from 0 to 255. 100 means the pitch is not changed.
 
|desc=The pitch applied to the sound. The acceptable range is from 0 to 255. 100 means the pitch is not changed.
 +
|default=100
 +
}}
 +
{{Arg
 +
|type=number
 +
|name=volume
 +
|desc=The volume, from 0 to 1.
 +
|default=1
 +
}}
 +
{{Arg
 +
|type=number
 +
|name=channel
 +
|desc=The sound channel, see {{Enum|CHAN}}.
 +
 +
Will not work if a [https://developer.valvesoftware.com/wiki/Soundscripts sound script] is used.
 +
|default=CHAN_AUTO, CHAN_WEAPON for weapons
 +
}}
 +
{{Example
 +
|Description=Plays sound from the first player on the server.
 +
|Code=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" )
 
}}
 
}}

Latest revision as of 18:29, 19 December 2019

 Entity:EmitSound( )

Contents

Description

Plays a sound on 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". This does not work with all sound files.

It is recommended to use sound scripts ( see sound.Add ) over direct file paths. This will allow you to use Entity:StopSound to stop the played sound scripts.

NOTE

When using this function with weapons, use the Weapon itself as the entity, not its owner!

WARNING

Do not use this for looping sounds with a filepath: see Entity:StopSound for more details.

BUG

This does not respond to SuppressHostEvents.

Issue Tracker: #2651

Arguments

string soundName

The name of the sound to be played.

WARNING

The string will cannot have whitespace at the start or end. You can remove this with string.Trim.

Arguments

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_ Enums

Will not work if a sound script is used.

Arguments

number pitchPercent=100

The pitch applied to the sound. The acceptable range is from 0 to 255. 100 means the pitch is not changed.

Arguments

number volume=1

The volume, from 0 to 1.

Arguments

number channel=CHAN_AUTO, CHAN_WEAPON for weapons

The sound channel, see CHAN_ Enums.

Will not work if a sound script is used.

Examples

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" )


Personal tools
Navigation