Here we take a look at setting up and configuring Visual Studio 2013 alongside the Half-Life SDK for programming. We also show how to build, and run the Game in Debug mode. We also touch lightly on some coding by showing how to output a HUD message when the player jumps
Windows, Half-Life SDK, Microsoft Visual Studio [2010, 2012, 2013 +], Steam, Half-Life
Learn how to setup Visual Studio to work with GoldSrc
Install Visual Studio (2010, 2012, 2013 or 2015) ( you are required to create a free account )
Note: The Half-Life SDK available on Github was built using Visual Studio 2010 so it will run out of the box with that version. Newer versions require that the Solutions be converted to work with these newer versions of the IDE. The IDE will tell you when it performs this conversion.
Download the Half-Life SDK from Valve’s Github repository, You can place and extract the downloaded ZIP anywhere you like.
Note: For those using Visual Studio 2015 changes to the C Library have caused many warnings in Valves Half-Life SDK. Community member Malortie has created a fork which compiles for Visual Studio 2015. I would suggest using it until Valve makes changes to support Visual Studio 2015 in the official repository.
Mine is located here:
Opening the Project and Configuring
–windowed –debug –dev
Build the Project
Failed to Initialize authentication interface. Exiting…
So let’s do something to the code:
Let’s add a message for when the player jumps.
To do this locate player.cpp inside hldll > Source Files > dlls in Visual Studio
Ctrl – F to Find the word “Jump”
Locate the following:
case PLAYER_JUMP: m_IdealActivity = ACT_HOP; break;
Let’s append a line that outputs a custom message when the player jumps in-game
case PLAYER_JUMP: UTIL_ClientPrintAll(HUD_PRINTNOTIFY, UTIL_VarArgs("Hello Half-Life")); // Message m_IdealActivity = ACT_HOP; break;
Save the changes and build hldll, Then enter the game and jump. You should see in the top left hand corner the message “Hello Half-Life”
Post Build Notes
If you want to print to the console and not the console & HUD as described above use the following commands
For printing to the server (hldll) console this is:
ALERT( at_console, "Hello Half-Life\n" );
The \n is important because it adds a line break so that the next call to this method doesn’t simply stick text to the end of your statement but rather creates its own newline.
The equivalent in the client (hl_cdll) is:
gEngfuncs.Con_Printf( "Hello Half-Life\n" );
The Server (aka hldll) contains all the code that is common between all players, These include AI, Monsters, Items, Weapons, gamerules, entities, etc..
The Client (aka hl_cdll) contains all the code that is specific to each player, Things such as the HUD, events system, input processing, VGUI (MOTD, TFC team/class selection, command menu) as well as some items for rendering.
You can learn more about this kind of game architecture here.
Build your binaries in release mode when you are making a final binary to distribute to friends or the community. To do this simply right click on the project, select Properties -> Configuration Manager (Top Right). In the window that appears select Release from the Top-Left drop down box. This sets the active configuration to Release as opposed to Debug which is the default setting. Close the window and compile the project again.
This will create a Release folder next to your Debug folder in the solution (code) directory. If you set your settings to affect all configurations as described earlier the newly compiled dll will have copied to the correct mod folder.
When compared to the Debug binaries the Release binaries are typically smaller in size and contain optimizations to improve performance at runtime.
I want to extend my thanks to Shepard62700FR who provided some very helpful advice which I added to the tutorial.
I want to thank Malortie for his Visual Studio 2015 compatible version of the Half-Life SDK which I am sure many of you will find useful.
And finally I want to thank you the reader who took the time to read this, I hope this short tutorial helps you in some small way. If you find any issues or if you know of anything this tutorial should include please feel free to send an E-Mail onto me concerning it.
The support thread for this tutorial can be found over at the forums.
Copyright © 2020 www.sourcemodding.com
All trademarks are property of their respective owners in the US and other countries.
Sourcemodding is in no way affiliated with the Valve Corporation. This is a non-profit community driven website using content from Valve and the Community.
All files are provided as is and are simply mirrors of files that can easily be found elsewhere online.
If you dispute anything on the website or want something removed please get in touch.