music_track

From Valve Developer Community
Jump to navigation Jump to search
Ambient generic.png

music_track is a point available in Black Mesa Black Mesa. This entity allows you to play music and control it dynamically, without the need to create lots of scripts. The best example of using this entity is the beginning of chapter Surface Tension. When player triggering the trigger - the first music track starts, which is looped (it loops itself, without help from other entities), when the soldiers leaves the ambush - the next track starts, which is also looped. When the fight with the helicopter ends, the last, final track starts, which is not looped. Before this system implementation, music was launching via ambient_generic, which just playing the full version of the music from beginning to end, which made certain parts of the music inappropriate for situations, or even ended when the helicopter didn't even arrive.

All code for original music tracks from Black Mesa Black Mesa placed in game_sounds_music.txt and game_sounds_xen_music.txt, both placed in scripts folder.

Todo: Learn how this entity interacts with sound files and their code. Answer the following questions:
    • Why Next input works only if used combination of certain tracks ?
    • Why Fade input works only with certain tracks ?
Black Mesa Level Creation

Soundscript

This is example of sound script to make your music properly working with this entity.

"MusicTrackName"
{
    "channel"       "CHAN_STATIC" //Channels are used to categorize sounds in a way that NPCs, and game logic in general, can understand. In case of music_track, use only CHAN_STATIC.
    "volume"        "1.0" //A number between 0 and 1.
    "pitch"         "100" //Any number between 0 and 255, where 100 is the sound's original pitch and 255 is very high.
    "soundlevel"    "SNDLVL_NONE" //The sound's attenuation; how fast it drops away. In case of music_track, use only SNDLVL_NONE.
    "bpm"           "31.7756" // fill me in
    "signature"     "1" // fill me in
    "fadetime"      "2" //Fade time. Input Fade doesn't work without this.
    "wave"          "#music/MyCoolMusiс.wav" //Filename and path to it. Usually all music is placed in music folder.
}

Looping

To make your music endless looping, you'll need to add in your .wav file "loop point". Check out this guide.

Keyvalues

Name (targetname) <string>[ Edit ]
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

Sound Name (track_script_sound) <sound>
Name of the GameSound entry for the music to play.
Icon-Important.pngImportant:This doesn't work if you specify sound with path (music\bms - st1-part2.wav for example), instead, sound name from the code of the file must be used (music.st.1-part2 in case of the example). It can't use .wav file paths directly because it need the metadata fields (bpm, signature, fade time) above for the system to work properly.
Next Track (next_track_entity) <targetname>
Name of the next music_track entity to play when Next input is called.

Inputs

Play <void>
Starts the music track.
Note.pngNote:It cannot be refired while music is playing. Quote from [Code] your-name-here about this: "Doubtful. We ran into a significant number of bugs trying to get this system working. You can only move forward in the playlist (from what I remember)".
Stop <void> Obsolete
Deprecated.
Stops the music track.
Fade <floatRedirectInput/float>
Fades the music track out over the given number of seconds.
Next <floatRedirectInput/float>
Plays the next track when the BPM lines up.

Outputs