Creating a dynamic music system in your main menu for your source engine mod

Nbc66
5 min readApr 4, 2021

--

Many players who play source engine mods usually complain about a quiet menu, after you either get back from a match to the main menu or the music stops playing after the startup song is over.

Well, that time is over, as I will show you today how you can easily make a system for yourself for the music to not stop playing in the main menu, this is something similar to what Team Fortress 2 classic does.

UPDATE: Made it possible to play menu music inside of background maps now. 15. April 2021.

What You Need

Please note that you will need to understand at least the basics of C++ for this to work properly

To start we will need to download The source code for SourceSDK2013. we can get that of off-Valve’s official GitHub repository located here.

The next step is to get an IDE also know as an Integrated Developer environment, This tool is used by programmers to help them in their daily needs like showing you errors in the code or showing you how to access something from the project without needing to do it manually.

please note that the 2013 SDK can only be compiled using Visual Studio 2013

You can download Visual Studio 2013 here.

For the next step, you need to get the following code to help you easily put this into your mod. the code needed for the music system to work can be found here

code for the music system

ok now that we got that we can continue to the next step

Implementing the code

the next step is for us to now implement the code I have provided you into your mod. First off you need to add in the code you downloaded to your project.

Source uses what's called VPC(Valve Project Creator) to help developers easily work on their projects without needing to share a .sln file with them

we need to go to our sourceSDK2013 source code folder we just downloaded

it should look something like this

Folder of Source SDK 2013 after downloading it from GitHub

now go to

sp/src/game/client/hl2

and add in the music_system.cpp and .h files to the folder

now go and find client_episodic.vpc inside of the client folder in the source code

and underneath

$folder "HL2 DLL"
{

add in the following lines

$File "hl2\music_system.cpp"
$File "hl2\music_system.h"

and that should be it for the setup part

now go back and edit the creategameprojects.bat inside of the src folder

remove this line /hl2

save it and run the .bat file

it should now create a .sln file called game.sln

ok now comes the interesting part.

PROGRAMMING!

ok now that we have opened up the .sln file it should open up visual studio 2013 and it should look something like this

This is Visual Studio 2019 but it will look the same on vs2013

ok, now we need to go to the top left and first off. Set the game to be built in release instead of debug like this

ok, not that we have done that go to the solution explorer on the right of your screen and search for cdll_client_int.cpp .

Open up the file, and add in the following line above #include “cbase.h”

#include "music_system.h"

ok now we gotta scroll down to “IGameSystem *SoundEmitterSystem();

and right above it add the following line

CPFMainMenuMusic MenuMusic;

ok now that we have done that, press ctrl+f and search for “CHLClient::Init”

it should bring you down here

now scroll down to the end of the function and right above the “return true” add the following line

MenuMusic.Init();

ok, now the last thing we have to add-in

Press ctrl+f and search for “CHLClient::HudUpdate

it should bring you down here

ok now scroll down to “C_BaseTempEntity::CheckDynamicTempEnts();

and below it add in the following line

MenuMusic.OnTick();

and that's it you are done

now we have to compile the code press F7 and the code should start compiling now.

The last step

for the last step, we now have to add the compiled binaries to our mods folder

go back to the sp folder and inside of game/mod_episodic/bin you should see the following files

Now copy over those files to your mods bin folder.

Now we have to go to our mod folder and inside of the sound folder, make a folder named ui and inside of the ui folder make a folder named music

it should look like this sound/ui/music

now inside the music folder add in any .mp3 file you want to play in the main menu and just name it gamestartup1.mp3 for more files name them also gamestartup#.mp3 the # should be replaced by a number it's best you put them in sequential order like 1.2.3.4.5

you are done!

now open up your mod in steam and listen to the great songs you put in

here is a small video to showcase how the music system works

hope you enjoyed this small tutorial.

Thank you for reading

-Nbc66

--

--

Nbc66
Nbc66

Written by Nbc66

0 Followers

A guy who is trying to get into video game development

No responses yet