Left 4 Dead Plugins: Difference between revisions
m (Added a <br> to the end of step 2 in section 4) |
mNo edit summary |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
In this tutorial you will learn how to compile [[Server Plugins]] for | {{LanguageBar|title = ''Left 4 Dead'' Plugins}} | ||
If you don't have a compiler installed you can [http://www.microsoft.com/express/download/ download Visual C++ Express 2008] for free from Microsoft. | {{Update|Needs to be updated for newer versions of Visual Studio (if possible). Confirm if {{l4dtools|1}} or {{l4d2tools|1}} ships with file required to create server plugins.}} | ||
{{l4ds topicons}} | |||
{{l4ds}} In this tutorial you will learn how to compile [[Server Plugins]] for the {{l4ds|3}}. This tutorial assumes you are well acquainted with both C++ and your chosen compiler; however, if you have ever compiled a program before you should be able to follow the tutorial step-by-step no problem.<br> | |||
If you don't have a compiler installed, you can [http://www.microsoft.com/express/download/ download Visual C++ Express 2008] for free from Microsoft. | |||
== Creating Your Project == | == Creating Your Project == | ||
Line 13: | Line 16: | ||
== Getting the Left 4 Dead SDK == | == Getting the Left 4 Dead SDK == | ||
[[ | [[File:Left 4 Dead Plugin Project Folder.png|thumb|The Left4Dead SDK.]] | ||
# You'll want to download the [http://hg.alliedmods.net/hl2sdks/hl2sdk-l4d/archive/tip.zip reserve-engineered Left 4 Dead SDK] from AlliedModders, as Valve has not released a new SDK to create Left 4 Dead Plugins.<br> | |||
# Open the folder containing your new project. It usually looks like: <code>C:\Documents and Settings\''User Name''\My Documents\Visual Studio 2008\Projects\''Project Name''\''Project Name''</code> (This is the folder containing your <code>.vcproj</code> file.)<br>'''Ex:''' <code>C:\Documents and Settings\Andy\My Documents\Visual Studio 2008\Projects\Left4Dead Plugin\Left4Dead Plugin</code><br> | |||
'''Ex:''' C:\Documents and Settings\Andy\My Documents\Visual Studio 2008\Projects\Left4Dead Plugin\Left4Dead Plugin<br> | # You'll want to copy the '''lib''' and '''public''' folders from the SDK zip into your project folder.<br> | ||
# Also copy '''serverplugin_empty.cpp''' from '''utils\serverplugin_sample''' in the SDK zip directly into the project folder.<br> | |||
# Addtionally you may want to copy the '''game''' folder from the zip to the project folder but more on that later.<br> | |||
# To reduce the size of your project folder you can delete all the .cpp files from the SDK (keeping '''serverplugin_empty.cpp''' of course).<br> | |||
# Click and drag '''serverplugin_empty.cpp''' into your visual studio project. Drop it on to the name of your project in the '''Solution Explorer'''.<br> | |||
== Adjusting the Project Settings == | == Adjusting the Project Settings == | ||
[[ | [[File:Left 4 Dead Plugin Project Properties.png|thumb|Project Properties.]] | ||
[[ | [[File:Left 4 Dead Plugin Project Properties-General.png|thumb|General Properties.]] | ||
[[ | [[File:Left 4 Dead Plugin Project Properties-C-General.png|thumb|C/C++ Properties.]] | ||
[[ | [[File:Left 4 Dead Plugin Project Properties-C-Include.png|thumb|The Addtional Include Directories.]] | ||
[[ | [[File:Left 4 Dead Plugin Project Properties-Linker-General.png|thumb|Linker Settings.]] | ||
[[ | [[File:Left 4 Dead Plugin Project Properties-Linker-Input.png|thumb|Linker Settings.]] | ||
1. Right-Click on your project in the '''Solution Explorer''' and chose '''Properties'''.<br> | 1. Right-Click on your project in the '''Solution Explorer''' and chose '''Properties'''.<br> | ||
Line 41: | Line 43: | ||
== Setting the Project to Automatically Copy the Plugin to Left 4 Dead == | == Setting the Project to Automatically Copy the Plugin to Left 4 Dead == | ||
[[ | [[File:Image-Left 4 Dead Plugin Project Copy.png|thumb|Configuring the project to copy automatically.]] | ||
1. Expand '''Custom Build Step''', and Enter '''copy /y "$(TargetDir)$(TargetFileName)" "C:\Program Files\Steam\steamapps\common\left 4 dead\Left4Dead\addons\$(TargetFileName)"''' as the '''Command Line'''.<br> | 1. Expand '''Custom Build Step''', and Enter '''copy /y "$(TargetDir)$(TargetFileName)" "C:\Program Files\Steam\steamapps\common\left 4 dead\Left4Dead\addons\$(TargetFileName)"''' as the '''Command Line'''.<br> | ||
Line 89: | Line 91: | ||
#undef GAME_DLL</pre> | #undef GAME_DLL</pre> | ||
the '''#define GAME_DLL''' tells the compiler you want to use the server code and is undefined afterward because this is not actually a server dll, its a plugin for the server dll. | the '''#define GAME_DLL''' tells the compiler you want to use the server code and is undefined afterward because this is not actually a server dll, its a plugin for the server dll. | ||
{{l4d topicon}}{{l4d2 topicon}}{{source topicon}}[[Category:Programming]] | |||
[[Category:Programming]] [[Category: | [[Category:Plugins]] |
Latest revision as of 06:31, 17 January 2025



In this tutorial you will learn how to compile Server Plugins for the Left 4 Dead series. This tutorial assumes you are well acquainted with both C++ and your chosen compiler; however, if you have ever compiled a program before you should be able to follow the tutorial step-by-step no problem.
If you don't have a compiler installed, you can download Visual C++ Express 2008 for free from Microsoft.
Creating Your Project
1. Under Visual Studio Express 2008 Select File > New > Project.
2. Chose Win32 for the project Type and Win32 Project for the template.
3. When the wizard appears click on application settings and chose DLL as the application type and Select Empty Project under Additional Options (Or you'll be sorry).
Getting the Left 4 Dead SDK
- You'll want to download the reserve-engineered Left 4 Dead SDK from AlliedModders, as Valve has not released a new SDK to create Left 4 Dead Plugins.
- Open the folder containing your new project. It usually looks like:
C:\Documents and Settings\User Name\My Documents\Visual Studio 2008\Projects\Project Name\Project Name
(This is the folder containing your.vcproj
file.)
Ex:C:\Documents and Settings\Andy\My Documents\Visual Studio 2008\Projects\Left4Dead Plugin\Left4Dead Plugin
- You'll want to copy the lib and public folders from the SDK zip into your project folder.
- Also copy serverplugin_empty.cpp from utils\serverplugin_sample in the SDK zip directly into the project folder.
- Addtionally you may want to copy the game folder from the zip to the project folder but more on that later.
- To reduce the size of your project folder you can delete all the .cpp files from the SDK (keeping serverplugin_empty.cpp of course).
- Click and drag serverplugin_empty.cpp into your visual studio project. Drop it on to the name of your project in the Solution Explorer.
Adjusting the Project Settings
1. Right-Click on your project in the Solution Explorer and chose Properties.
2. Under Configuration chose All Configurations.
3. Expand Configuration Properties, click on General and change the Character Set to Use Multi-Byte Character Set.
4. Expand C/C++, click on General and add public;public\tier0;public\tier1;public\tier2;public\tier3;game;game\shared;game\server;game\client to Addtional Include Directories.
5. Expand Linker , click on General and add lib\public to Additional Library Directories.
6. Click on Input and add mathlib.lib tier0.lib tier1.lib tier2.lib vstdlib.lib to Additional Dependencies.
7. Add libc;libcd;libcmt to Ignore Specific Library.
Setting the Project to Automatically Copy the Plugin to Left 4 Dead
1. Expand Custom Build Step, and Enter copy /y "$(TargetDir)$(TargetFileName)" "C:\Program Files\Steam\steamapps\common\left 4 dead\Left4Dead\addons\$(TargetFileName)" as the Command Line.
2. Don't for get to add "C:\Program Files\Steam\steamapps\common\left 4 dead\Left4Dead\addons\$(TargetFileName)" to Outputs or the plugin will not copy.
3. Optionally, add a description.
Making the Code Compile
1. Press Ctrl+H and find and replace all occurences of IGameEventManager with IGameEventManager2.
2. Change the IGameEventListener line 50 to IGameEventListener2.
3. Change the KeyValues on line 70 to IGameEvent.
4. Change line 185 from gameeventmanager->AddListener( this, true ); to gameeventmanager->AddListener( this, "player_say", true );
5. Remove lines 201-204. (This tutorial does cover the bot code in the example plugin, it is probably outdated anyway).
6. Change the KeyValues on line 403 to IGameEvent.
7. Remove the engine-> from lines 257 and 295.
somewhere under line 36 (CGlobalVars *gpGlobals = NULL;) but before line 251 (void CEmptyServerPlugin::ClientSettingsChanged( edict_t *pEdict )) add this code:
inline int IndexOfEdict(const edict_t *pEdict) { return (int)(pEdict - gpGlobals->baseEdict); } inline edict_t *PEntityOfEntIndex(int iEntIndex) { if (iEntIndex >= 0 && iEntIndex < gpGlobals->maxEntities) { return (edict_t *)(gpGlobals->baseEdict + iEntIndex); } return NULL; }
8. You may also want to compile your plugin in Release mode so it loads in to Left 4 Dead easily. (In Debug mode you must add -allowdebug to your Left 4 Dead launch options.)
9. Build your plugin!
Installing the plugin into Left 4 Dead
1. Create file named C:\Program Files\Steam\steamapps\common\left 4 dead\Left4Dead\addons\my plugin.vdf containing this text:
"Plugin" { "file" "..\left4dead\addons\[Plugin Name].dll" }
(this can be done by opening the file with notepad but make sure the file is .vdf not .txt or .vdf.txt, also the name itself it not important as Left 4 Dead reads all .vdf files in the addons folder.)
2. If your plugin does not automatically, copy your plugin .dll into your addons folder.
3. Test your plugin by issuing the command empty_version in the console.
Adding Enhanced Entity Interaction
Remember the game folder from before? That can be used to give your plugin access to the CBaseEntity and CBasePlayer classes if you chose to use them.
The easiest way to add this is to include the base server file in your serverplugin_empty.cpp.
#define GAME_DLL #include "server\cbase.h" #undef GAME_DLL
the #define GAME_DLL tells the compiler you want to use the server code and is undefined afterward because this is not actually a server dll, its a plugin for the server dll.