Resource icon

VSoundscaper 1.0

  • Hey you! Yes, you! Add images to your downloads, it's free! Use the orange "Manage Download Image" button in the top right.

VSoundscaper 1.0

VScript based mp3 looper

Introduction
This is a little script I put together in order to solve my age old annoyance of mp3 files not being loopable in source.

The specific use case for this script is when using music in areas. Currently, if you want a room to have a certain music track, and to have it loop, it must be a .wav file. However, a .wav file is 10x larger than an mp3, so if you have a lot of music in your map this adds up fast to make bloated and oversized map files.

The basic process of how this works is that by re-emitting a sound to players every few frames with a "change volume" flag, we can loop the sound properly, while also keeping the soundscape behavior of maintaining a sound if tabbed out. Previously, if you played an mp3 with an ambient_generic for instance, then tabbed out and back into the game, the sound would stop playing. Now, while it does restart, it will still play properly.

Usage:
Before setting up anything in hammer, download the file and place the vsoundscaper folder into scripts/vscripts
The file soundscape_config.nut contains your configuration data. The variable "playlists" is a table which allows you to configure playlists. Each playlist is structured as follows:

playlist_name = [
["path/to/song1.mp3",song1_duration_float],
["path/to/song2.mp3",song2_duration_float]
]

For example, I could have a playlist which just plays one song like this:
disco = [
["mysongs/disco_inferno.mp3",195.63]
]


If multiple songs are in the playlist, one will be picked randomly. It's set up to have a timer such that everyone should be on the same song at once, and after the time limit, a new song will be picked (randomly if more than one)
The script will automatically precache the songs, so you don't need to do it elsewhere.

Set up a logic_script to load the script.

In hammer, you will set up a trigger_multiple, retrigger delay 0, with the following outputs:
OnStartTouch | <logic_script name> | RunScriptCode | AddPlayerToSoundscape('playlist_name',activator)
OnEndTouch | <logic_script name> | RunScriptCode | RemovePlayerFromSoundscape('playlist_name',activator)

Make sure to use backticks for quotes around the playlist name, as quotes will crash the map. tf2maps does not appear to be playing nice and allowing me to place them in text.

When a player enters the trigger, any previous playlist they were in will fade out, then the new playlist will fade in.
License
Free to use and modify.
Author
no username
Downloads
87
Views
284
First release
Last update
Category
VScript