Difference between revisions of "My First Mod"

From Valve Developer Community
Jump to: navigation, search
(Run the MOD)
(Set the active configuration)
Line 52: Line 52:
 
# Select Project -> Properties (last entry in menu)
 
# Select Project -> Properties (last entry in menu)
 
# Press Configuration Manager (upper right button)
 
# Press Configuration Manager (upper right button)
# Change the '''Active Solution Configuration''' drop-down list to "Release HL2"
+
# Change the '''Active Solution Configuration''' drop-down list to "Release"
  
 
== Compile the project ==
 
== Compile the project ==

Revision as of 09:37, 14 May 2008

Introduction

This tutorial will teach you how to create, setup and build your first simple HL2 MOD. In this MOD we will change the speed at which Half-Life 2's rocket travels through the world.

Create the MOD project

For the purpose of this tutorial we will call our first MOD, "MyMod". When you make your own MOD this can be any name you wish (i.e. "QuickMod", "TreasureTroll", etc.)

Please note that in order to get the latest source-code you must refresh the SDK content.

To create a MOD project:

  1. Open the Source SDK application from Steam's Tools menu.
  2. Open Create A Mod from the Utilities group.
  3. Select either Modify Half-Life 2 Single Player or Modify Half-Life 2 Multiplayer.
  4. Specify where you would like the MOD's project to be placed (i.e. C:\MyMod).
  5. Enter the name of your MOD. In this example, we'll use "MyMod".
  6. Vista may require extra steps depending on your security settings. (see known issues below)

The Steam application will then copy all the relevant files to the destination directory that you specified. You now have a copy of Half-Life 2's source code at that location which you can modify.

Open the MOD solution

  1. Launch your copy of Microsoft Visual Studio, the code was originally designed to work with 2003 but has been retrofitted to work with other versions. Should you own a different copy than 2003 guides are available for Compiling under VS2002 , Compiling under VS2005 and Compiling under VS2008
  2. Select File->Open Solution from the menu and open the Game_HL2-2003.sln or Game_HL2-2005.sln solution located in your MOD's src directory, select the one that matches your version of Microsoft Visual Studio. Note the "HL2" portion of the file name will correspond to the selection you made in the mod creation step. If you selected mod from scratch, "Scratch" will appear there instead.

Alter the rocket's speed

If you are editing Half-life Single-player, open file hl2_dll/weapon_rpg.cpp. Otherwise open hl2mp_dll/weapon_rpg.cpp.

Note: If you can't find the file, try looking in the server_hl2 > Source Files > HL2 DLL folder within your Solution Explorer window within Microsoft Visual Studio.

At the top of the file, find the line:

#define RPG_SPEED 1500

Change this line to read:

#define RPG_SPEED 400

By altering this number, we've told the rocket to travel at 400 units per second (or about 33 feet per second, or 10 meters per second). Previously the rocket traveled at 1500 units per second (125 ft/s, 38 m/s). The difference in speed will be very apparent when we compile and run the MOD.

Set the active configuration

We'll need to set our active configuration to "Release HL2".

To do this:

  1. Select Build->Configuration Manager.
  2. Change the Active Solution Configuration drop-down list to "Release HL2"
  3. Select Close.

For Visual Studio 2005 users:

  1. Select Project -> Properties (last entry in menu)
  2. Press Configuration Manager (upper right button)
  3. Change the Active Solution Configuration drop-down list to "Release"

Compile the project

Now we are ready to build the solution. Choose Build->Build Solution to begin. When the requested compilation has completed there will be a server.dll and client.dll file in the MyMod/bin directory (i.e. C:\MyMod\MyMod\Bin). This is the custom server and client DLL for our MOD and is one of the pieces that would be distributed to end-users.

Run the MOD

Now before you launch it's important to ensure you have something to launch. By default, new mods will use the 215 appid. This loads the Source SDK Base. This is not a bad thing; in fact, it's the best version of the engine available. The only problem it does have is that it has no game specific content. Global resources like textures and models available to all games will be present; however, levels will not be. You will either need to change the appid to use different game engines and load content from that game, or instead copy content out of that game into your mod. GCFScape can allow you to copy that content into your mod, but this content cannot be legally redistributed with your mod. The other approach is simply finding your .../steamapps/sourcemods/MyMod/gameinfo.txt and changing the value to 220 for single player and 320 for multiplayer, although it's advisable to change it back to 215 later.

In the directory that you created your MOD, there will be a batch file called run_mod.bat. Don't use the bat file to launch your mod, as it has not been updated for the SDK Base. The best way to launch your mod is to restart Steam and launch it from your Games list (where it should hopefully have appeared) or via the debugging option in vis (read how to debug the source code).

Now that there's content to load, start the game up. When the engine has loaded, you'll be taken to the title screen. If you are warned about missing content, such as maplist.txt, ignore it.

In "Options", "Keyboard", and "Advanced", enable the Developer Console. Hit the tilde key (~) to bring up the Developer Console. This console will provide you with numerous tools to help you create content for the Source engine.

No maps are provided with your single player mod, so copy a map from the HL2 maps with GCFScape to your mod's /maps/ directory inside of SteamApps/SourceMods. Load a map by typing "map " (including the space) into the console and select from the list (e.g. "map d1_canals_01") then type "impulse 101" to give yourself a load of weapons.


Note.png Note: Enable cheats in the game by typing "sv_cheats 1" in the console (~) for the "impulse 101" command to work

Select and fire the RPG to view the changes you've made.

You've built your first MOD

You’ve now setup and built your first MOD.

Template:Otherlang:en Template:Otherlang:en:de, Template:Otherlang:en:pl, Template:Otherlang:en:ru