Contextual Music System

This is something I threw together last night (which means it not really polished, but it’s functional) for some extra enjoyment with my Cannons addon. Basically, it’s a system that plays calm music when not much is going on, and starts battle music when you fire your gun (clientside), or any other serverside events that are set to run the command “cl_music_startbattle” or “cl_music_startcalm” on players. For example, I set my cannon to start the battle music on any players within 1000 units when it shot.

Place the script in your base Lua folder. Next, go into your sounds folder and create a folder called “battle” and a folder called “calm.” Now you have to get the music you want to use. For example, I used the overworld and battle music from Morrowind. Put your MP3 music in the respective folders, and name the files “battle1,” “battle2,” “battle3,” etc. (replacing “battle” with “calm” when adding calm files, obviously). Now you’re ready to go.

Once in game, just type ‘lua_openscript_cl cl_music.lua’ in your console, and your music will begin to play. Now you can let it be, and the music will switch when needed.

If you want to change the volume of the music, use the command ‘cl_music_volume percent

Report any bugs or whatever (there are a few, like battle music playing when switching from a lethal weapon). I can’t promise I’ll fix any though.

If you want to edit it, re-release it, or do whatever, feel free.

Awesome as usual. Great job.


So it’s kind of like the way the music work in Total Annihilation? Sounds nice! I’m downloading this. :smiley:

Sweet-cakes! got my download mudkip

integrate with a zombie survival mod (redead, zombie survival etc.) and add sounds from painkiller, BOOM

…That sounds like an AWESOME idea.

I was planning to make this and now I don’t have to do it anymore. Back on topic, this is awesome and made of win.

Hmm it doesn’t work for me, it says it’s playing the music in the console, but I can’t hear anything :s

As per usual, I wub you elijah!

So It’s like in oblivion where if a enemy attacks it changes to battle music?


You need to put your own music in “Battle” and “Calm” folders in the sound directory of gmod, and name them appropriately. Example: Battle1, Battle 2, etc go in the “Battle” folder. Calm1, Calm2, Calm3, go in the calm folder.

Yeah that’s what I did. Is the case of the names of the folders important?

Is the script in the LUA folder, and NOT the autorun folder?

Are you doing “LUA_openscript_cl cl_music.lua” in console?

How do I find sounds to dl to put into the “Calm” and “Battle” folders???

If you have either The Elder Scrolls 3 or 4, their music works great with this.

Basically, anything that has any kind of cinematic value will work. I was thinking about putting together a little “pack” with some public domain music.

Some of Jeremy Soule’s Total Annihilation soundtrack works quite well, I notice.

So, how does the music change exactly? Kind of like PSO? Where you have a lot of enemies and the battle music plays, as soon as they are dead, it plays the clam music?

Well, in the base I provided it only switches when you fire your weapon (since that is the only sensible clientside hook I could find), and switches when you stop firing for a while. If someone wanted to, they could easily add serverside things that would trigger a player’s music (there are concommands for it). I’ve been thinking about making up a simple script for servers to use that would add toggleable triggers in the form of an admin menu tab. If anyone would like something like that, speak up.