My First Mod

From Valve Developer Community
Revision as of 16:43, 9 January 2008 by TheRatcheteer (talk | contribs) (Alter the rocket's speed: in meters, too)
Jump to: navigation, search

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 2005, should you own a different copy than 2003 guides are available for Compiling under VS2002 and Compiling under VS2005.
  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 HL2"

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, infact 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 <code>run_mod.bat</code>. Use this batch file to launch your MOD. 

Don't use the bat file to lanuch your mod as it has not been updated for the sdk base. Best way is to restart steam and launch it from there (should be in you games list) 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. 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 which can be extracted from the original 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.

Known issues

Gravity Gun sprite glitches: Use of the 215 appid has been known to cause a glitch with the gravity gun. The sprites surrounding it do not have correct transparency and as such are surrounded by black. Simply extracting the correct files from the source materials.gcf will resolve the issue. Extracting the entire materials/sprites folder is the quickest and least complicated approach.

Installing under Vista: Because of the security settings in Vista you may be required to manually add your mod to "Steamdir\steamapps\*username*\sourcesdk\bin\GameConfig.txt". Copy a pre-existing entry and make note of the following vars and example values.

  1. "GameExe" - \*SteamUserDir*\source sdk base\hl2.exe
  2. "GameExeDir" - \*SteamUserDir*\source sdk base\
  3. "MapDir" - \*SteamUserDir*\sourcesdk_content\*ModFolder*\mapsrc
  4. "BSPDir" - \SourceMods\*ModFolder*\maps

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