My First Mod: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(→‎Set the active configuration: Can use debug if desired)
(Direct reference to Compiling in VS2008, Compiling in VS2005, and Launching from Visual Studio)
Line 26: Line 26:
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.
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 solution ==
== Prepare the solution ==


# Launch your copy of '''Microsoft Visual Studio'''. See [[Compiler Choices]].
# Carefully follow the instructions in [[Compiling in VS2008]] or [[Compiling in VS2005]], whichever is appropriate.
# Select '''File-&gt;Open Solution''' from the menu and open the '''Game_HL2-2005.sln''' solution located in your mod's <code>src</code> 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.
# Carefully follow the instructions in [[Launching from Visual Studio]].


== Alter the rocket's speed ==
== Alter the rocket's speed ==


If you are editing Half-life Single-player, open file <code>hl2_dll/weapon_rpg.cpp</code>. Otherwise open <code>hl2mp_dll/weapon_rpg.cpp</code>.
If you are editing Half-life Single-player: in the Solution Explorer, open file <code>Server Episodic > Source Files > HL2 DLL > weapon_rpg.cpp</code>.
Otherwise open <code>hl2mp_dll/weapon_rpg.cpp</code>.


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.
Near the beginning of the file, find the line:
 
At the top of the file, find the line:


  #define RPG_SPEED 1500
  #define RPG_SPEED 1500
Line 46: Line 45:


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.
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 &quot;Release HL2&quot;.
To do this:
# Select '''Build-&gt;Configuration Manager'''.
# Change the '''Active Solution Configuration''' drop-down list to &quot;Release HL2&quot;
# Select '''Close'''.
For Visual Studio 2005/2008 users:
# Select Project -> Properties (last entry in menu)
# Press Configuration Manager (upper right button)
# Change the '''Active Solution Configuration''' drop-down list to &quot;Release&quot;
{{note|Debug configuration can be used, but must be properly configured. See [[Compiling under VS2008]] or [[Compiling under VS2005]]}}


== Compile the project ==
== Compile the project ==
Line 72: Line 56:
SDK Base provides only Half-Life 2's shared content, however. If you want to use content from a specific game, or HL2's maps, you will need to change the AppId [[Steam Application IDs|to that of the game you want to load from]]. If you want to 'mount' more than one game [[Mounting Other Content|you can do so]], but you should avoid that method unless you really need it for reasons explained on its page.
SDK Base provides only Half-Life 2's shared content, however. If you want to use content from a specific game, or HL2's maps, you will need to change the AppId [[Steam Application IDs|to that of the game you want to load from]]. If you want to 'mount' more than one game [[Mounting Other Content|you can do so]], but you should avoid that method unless you really need it for reasons explained on its page.


In the directory that you created your mod, there will be a batch file called <code>run_mod.bat</code>. 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 - if not, check your AppId) or via the debugging option in vis (read how to debug the source code).
In the directory that you created your mod, there will be a batch file called <code>run_mod.bat</code>. 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 from within Visual Studio by pressing F5, or restart Steam and launch it from your Games list (where it should hopefully have appeared - if not, check your AppId).


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 <code>maplist.txt</code>, ignore it.  
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 <code>maplist.txt</code>, ignore it.  


In "Options", "Keyboard", and "Advanced", enable the Developer Console. Hit the tilde key (<b>~</b>) to bring up the [[Developer Console]]. This console will provide you with numerous tools to help you create content for the Source engine.  
In "Options", "Keyboard", and "Advanced", enable the Developer Console. Hit the tilde key (<b>~</b>) to bring up the [[Developer Console]]. This console will provide you with numerous tools to help you create content for the Source engine. {{note|The console will always appear if -allowdebug is specified as a command line argument/advanced option}}


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. "<code>map d1_canals_01</code>") then type "<code>impulse 101</code>" to give yourself a load of weapons.
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. "<code>map d1_canals_01</code>") then type "<code>impulse 101</code>" to give yourself a load of weapons.

Revision as of 18:30, 1 January 2010

Template:Otherlang2

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

Create the 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.

Prepare the solution

  1. Carefully follow the instructions in Compiling in VS2008 or Compiling in VS2005, whichever is appropriate.
  2. Carefully follow the instructions in Launching from Visual Studio.

Alter the rocket's speed

If you are editing Half-life Single-player: in the Solution Explorer, open file Server Episodic > Source Files > HL2 DLL > weapon_rpg.cpp. Otherwise open hl2mp_dll/weapon_rpg.cpp.

Near the beginning 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.

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 AppId 215 (Ep1) or 218 (Orange Box). This loads the correct version of Source SDK Base, which is accessible to almost everyone with a Valve game and, in the case of 218/Orange Box, is kept up to date with the latest engine built. You can check or change your AppId in the game's GameInfo.txt file.

SDK Base provides only Half-Life 2's shared content, however. If you want to use content from a specific game, or HL2's maps, you will need to change the AppId to that of the game you want to load from. If you want to 'mount' more than one game you can do so, but you should avoid that method unless you really need it for reasons explained on its page.

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 from within Visual Studio by pressing F5, or restart Steam and launch it from your Games list (where it should hopefully have appeared - if not, check your AppId).

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.

Note.pngNote:The console will always appear if -allowdebug is specified as a command line argument/advanced option

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.pngNote:A map that you can always use and is guaranteed to work is sdk_shader_samples.bsp, found in steamapps\[USER ID]\half-life 2\hl2\maps
Note.pngNote: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 set up and built your first mod.