You probably came across valve developers wiki's page "Server plugins" that contains very outdated information, and actually not compatible with CSGO servers (you can't even compile their own Sample). Although there is a SDK for CSGO, it's also outdated and totally undocumented. Luckily there is a third party SDK that works wonderfully and has much more functionality and is pretty much the only way to create native plugins, and you should use this SDK. This guide is based for Windows platforms, and just to get you started.
Alliedmodders Metamod:Source and their SDK
Alliedmodders is the team responsible for making it possible to create addons and plugins for pretty much all half life based engines (source engine, orangebox, goldsource...). Their SDK is complete and compile-able. Although you can compile your own addon on this SDK I very much suggest that you should not do this. You should build addons upon their Metamod, this is a plugin/hooking mechanism between your plugin and the server.
The reason why you should do this is that when your non Metamod addon runs alongside another addon, conflicts will arise during events and firing events. Most (I'd say all) server plugins are build upon Metamod, which makes sure that events that are called are routed correctly between the plugins, which eliminate conflicts. Also Metamod brings much functionality with it to easy your life.
Other tools from Alliedmodders
Whilst you can create native C++ based plugins on Metamod, there is another way to create plugins. By using Alliedmodders SourceMod, which is a addon build upon Metamod that is very powerful. You code in a compiled language, that's written in Sourcepawn. It's very easy to start coding with, and building plugins on. It also has a big community and a lot of examples. If you need more functionality in it you will still need to write an extension in c++, but build under Sourcemod.
Note that this article is not about writing extension on Sourcemod, but writing plugins on Metamod, if you wish to have more documentation on writing extensions on Sourcemod go here1.
Setting up the environment
This guide is meant to work on Visual Studio Express 2013.
You will need to download the following (or git), and the latest versions of the source files.
- Visual Studio Express 20132 It's free to use
- Metamod:Source3 source files
- HL2SDK for CSGO4 source files
Extract the source files to a location, the structure doesn't matter as we will use system variables.
Setup the following system variables, to do this press the start button, right click on "Computer" -> left click "Properties" -> On the left side click on "Advanced system settings" -> click on the tab "Advanced" -> The button "Environment variables".
Add under USER variables the following
|Variable Name||> Value|
|HL2SDKCSGO||> Full path to hl2sdk-csgo folder|
|MMSOURCE19||> Full path to metamod-source-master folder|
For example on my computer;
Opening and compiling the example plugin
Go to the folder where you placed metamod source files, go to 'sample_mm', 'msvc10' and open up the 'sample_mm.sln' (Microsoft Visual Studio Solution).
You'll get a security warning at first, just click "Ok", after it will ask to upgrade the compiler and libraries also click "Ok", they still work.
Don't build the example just yet since the solution is configured for the Alien Swarm SDK, in order to change this right click in the "Solutions Explorer" window on "Solution 'sample_mm' (1 project)", click on "Properties", in the left box click on "Configuration Properties" and change in the table the configuration for sample_mm to "Debug - CSGO", press ok and close the window.
Now build the sample by either pressing "Build" "Build Solution" or by pressing F7. You'll get some linking errors but the build should be successful!
It's also recommended to use this solution as your building point for your project as it's completely configured correctly.