Team Fortress 2/Scripting/Script Functions/EmitSoundEx: Difference between revisions
< Team Fortress 2 | Scripting | Script Functions
		
		
		
		Jump to navigation
		Jump to search
		|  (Move PVS note into description) |  (Document special channels using Gmod wiki and code comments) | ||
| Line 26: | Line 26: | ||
| | <code>int</code> | | <code>int</code> | ||
| | 0 | | 0 | ||
| | Channel ID on which to play the sound.  | | Channel ID on which to play the sound. Channel values below have special behavior, all other channels behave normally. List of special channels: | ||
| {| class="standard-table" style="width:100%" | |||
| ! Name | |||
| ! Value | |||
| ! Description | |||
| |- | |||
| | <code>CHAN_REPLACE</code> | |||
| | <code>-1</code> | |||
| | Used by console commands | |||
| |- | |||
| | <code>CHAN_AUTO</code> | |||
| | <code>0</code> | |||
| | Automatic channel {{clarify}} | |||
| |- | |||
| | <code>CHAN_WEAPON</code> | |||
| | <code>1</code> | |||
| | Weapon sounds | |||
| |- | |||
| | <code>CHAN_VOICE</code> | |||
| | <code>2</code> | |||
| | Character voices | |||
| |- | |||
| | <code>CHAN_ITEM</code> | |||
| | <code>3</code> | |||
| | Items {{clarify}} | |||
| |- | |||
| | <code>CHAN_BODY</code> | |||
| | <code>4</code> | |||
| | Impacts, ragdolls and footsteps | |||
| |- | |||
| | <code>CHAN_STREAM</code> | |||
| | <code>5</code> | |||
| | "Stream from static or dynamic area" {{clarify}} | |||
| |- | |||
| | <code>CHAN_STATIC</code> | |||
| | <code>6</code> | |||
| | Constant or background sounds. Valve recommends this to be used for looping ambient sounds, uninterrupted looping sounds or "one-shot" sounds | |||
| {{note|Allows multiple of the same sounds to play without cutting out}} | |||
| {{confirm|Code comments imply that this channel continues to work outside of the sound radius}} | |||
| |- | |||
| | <code>CHAN_VOICE2</code> | |||
| | <code>7</code> | |||
| | {{tf2|2}} Announcer | |||
| |- | |||
| | <code>CHAN_VOICE_BASE</code> | |||
| | <code>8 - 107</code> | |||
| | Allocated for player voice chat (100 channels) | |||
| {{note|Allows multiple of the same sounds to play without cutting out}} | |||
| |} | |||
| |- | |- | ||
| | <code>volume</code> | | <code>volume</code> | ||
Revision as of 17:28, 28 August 2023
Function Description
void EmitSoundEx(table parameters)
Flexible way of playing sounds. All parameters except sound_name are optional. Sounds can be played in raw or soundscript form, and filtered to everyone, on a per-team or per-player basis. Volume, pitch, channel and attenuation level can be controlled, and the sound can play from a fixed position or relative to an entity. It is also possible to stop or adjust sounds already playing on the entity using special flags such as SND_CHANGE_VOL or SND_CHANGE_PITCH.
 Note:If the sound is playing while a player is outside of the sound's PAS/PVS/attenuation, and then enters its visiblity, the player will not hear the sound. This may be a problem for looping sounds or sounds with long durations, in which case the following workarounds can be used:
Note:If the sound is playing while a player is outside of the sound's PAS/PVS/attenuation, and then enters its visiblity, the player will not hear the sound. This may be a problem for looping sounds or sounds with long durations, in which case the following workarounds can be used:
- Use the RECIPIENT_FILTER_GLOBAL/RECIPIENT_FILTER_TEAMfilter. The sound will still "play" outside of the range, but at no volume.
- Play the sound to the player individually using RECIPIENT_FILTER_SINGLE_PLAYERwhen they enter a given area, e.g. via a trigger.
- Create a soundscape which automatically deals with this on a per-player basis
Parameters
| Name | Type | Default | Description | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| sound_name | string | Name of sound. Can be raw filename or soundscript.  Note:Soundscripts override the channel,volumeandpitchparameters. Use raw filenames if this is not desirable. | ||||||||||||||||||||||||||||||||||||||||
| channel | int | 0 | Channel ID on which to play the sound. Channel values below have special behavior, all other channels behave normally. List of special channels: 
 | |||||||||||||||||||||||||||||||||||||||
| volume | float | 1.0 | Volume of sound, in normalized 0 - 1 range.  Tip:Sounds may be hard to hear even at full volume. Naming custom sounds according to the soundmixer can be used to make them naturally louder. | |||||||||||||||||||||||||||||||||||||||
| sound_level | int | 0 | Sound attenuation in decibels. See this page for real world equivalents. If the sound has non-zero attenuation, it will play from the entity's origin if present, otherwise it uses theoriginparameter. | |||||||||||||||||||||||||||||||||||||||
| flags | int | 0 | Special sound flags. List of flags available: 
 | |||||||||||||||||||||||||||||||||||||||
| pitch | int | 100 | Pitch of the sound. | |||||||||||||||||||||||||||||||||||||||
| special_dsp | int | 0 | DSP effect to use on this sound. | |||||||||||||||||||||||||||||||||||||||
| origin | Vector | 0 0 0 | Overwrites sound origin if specified. | |||||||||||||||||||||||||||||||||||||||
| delay | float | Delay before playing sound. Template:ModernNote | ||||||||||||||||||||||||||||||||||||||||
| sound_time | float | Absolute time to delay sound until, NOT the duration. Overrides delayif specified. Template:ModernNote | ||||||||||||||||||||||||||||||||||||||||
| entity | handle | null | Optional (player) entity to filter sounds to. All filters can use this except RECIPIENT_FILTER_GLOBALandRECIPIENT_FILTER_TEAM. E.g.RECIPIENT_FILTER_SINGLE_PLAYERwill play sounds only to the specified player here. | |||||||||||||||||||||||||||||||||||||||
| speaker_entity | handle | null | Entity which will *speak* the sound. This is not the sound as the actual owner of the sound, see above. | |||||||||||||||||||||||||||||||||||||||
| filter_type | int | 0 | Specifies what entities can hear this entity. See Constants.EScriptRecipientFilter. | |||||||||||||||||||||||||||||||||||||||
| filter_param | int | -1 | Specifies an extra option to the filter. Currently only used by RECIPIENT_FILTER_TEAM, which uses this to specify which team to play to. | 
Flags
It may be useful to define these flags for extra readability.
::SND_NOFLAGS <- 0
::SND_CHANGE_VOL <- 1
::SND_CHANGE_PITCH <- 2
::SND_STOP <- 4
::SND_SPAWNING <- 8
::SND_DELAY <- 16
::SND_STOP_LOOPING <- 32
::SND_SPEAKER <- 64
::SND_SHOULDPAUSE <- 128
::SND_IGNORE_PHONEMES <- 256
::SND_IGNORE_NAME <- 512
::SND_DO_NOT_OVERWRITE_EXISTING_ON_CHANNEL <- 1024
Example Usage
// sounds should be precached once before use
PrecacheScriptSound("Game.Domination");
// play the sound to everyone around yourself
EmitSoundEx({
	sound_name = "Game.Domination",
	origin = GetListenServerHost().GetCenter(),
	filter = Constants.EScriptRecipientFilter.RECIPIENT_FILTER_GLOBAL
});
 Confirm:
 Confirm: