Mini-mod tutorial: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (→‎First off: a space is important here)
m (Nesciuse moved page Mini-mod tutorial/en to Mini-mod tutorial without leaving a redirect: Move en subpage to basepage)
 
(11 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{tutpov}}
{{LanguageBar}}
{{cleanup}}
={{HL2}} Making your own Mini-mod=


Ok so you don't know C++ and have no idea what a [[cpp]] file is, but that doesn't limit you to the normal HL2 style game play on your custom single player map.
==Introduction==
Modifying the gameplay of a Source game such as Half-Life 2 does not have to require knowledge of programming or Source-modding. This short tutorial is going to teach you how to use [[CFG|configuration files]] to modify gameplay. Configuration files are simply files which contain a list of instructions for the Source engine to perform. The instructions are developer console commands, so therefore anything that can be typed in the console can be placed in a configuration file.


This tutorial is going to teach you how to make a [[CFG]] file and how to execute it from inside your map.
With console commands, you can change anything from the maximum ammunition capacity of a weapon to the damage that an antlion-guard deals when it charges into you. A full list of console commands is available [[Console Command List|here]], but remember that some listed there are only applicable to Half-Life 2 and its episodic sequels. If a command in the list has Yes written in the Cheat column, then you must add <code>sv_cheats 1</code> to the beginning of your config file before you can use it.


First thing to think about is that you are only limited by commands you can type in the console. With that said there are a lot of little things you can do to make your map different from others.
==Creating the config==


For example, you can change the distance the gravity gun can pull from, the speed it throws objects, you can change the max ammo a weapon can carry, you could activate colliding ragdolls, or even the damage a weapon deals. Anything you can set in the console. So start looking through those commands.
Open Notepad or a text editor of your choice, and write some console commands of your choice, separated by new lines. To perform the aforementioned tasks involving ammunition and antlion-guards, you would enter these two commands:


==First off==
<code>
sk_max_crossbow 30<br />
sk_antlionguard_dmg_charge 60
</code>


Open notepad.
There are obviously many more console variables to choose from, but this serves as an example.


Now for anything you want to happen for your map, type as you would in the console.
Using config files, you can also bind keys to actions. For example, if you wanted to create a key to toggle a 'bullet-time' mode, you would enter this (it requires cheats to be enabled at the beginning of the config file):
In my case the first two lines read:


<code>sv_cheats 1</code>
<code>
sv_cheats 1<br />
alias "BulletTimeOn" "host_timescale 0.5; mat_yuv 1; switchToOff"<br />
alias "BulletTimeOff" "host_timescale 1; mat_yuv 0; switchToOn"<br />
alias "switchToOff" "bind tab BulletTimeOff"<br />
alias "switchToOn" "bind tab BulletTimeOn"<br />
switchToOn
</code>


<code>bind "tab" "incrementvar host_timescale 0.25 1 0.75; incrementvar mat_yuv 0 1 1"</code>
With this config executed, you could press the Tab key to slow down the game and create a monochrome effect on the screen, and press it again to revert the game to normal. To find out more about how that toggle works (it seems quite complicated but it isn't), see [[alias]] and [[bind]].


That's the command to bind that action to the 'tab' key. It will act like bullet time and switch on/off. Try not to bind anything that is already used like 'e' or 'z.' That would be a silly thing to do.


To string commands together use the <code>;</code> character.
==Saving the config==
When saving your configuration file, remember to always have the 'Save as type' drop-down box set to 'All file types'. Save your config as anything you want, but remember the .cfg extension. If you were creating a config for Half-Life 2, you would save it here:


If there is any thing else particular to your map that you want to add do that too.
WhereSteamIs\steamapps\YourUsername\half-life 2\hl2\cfg
Mine looks like this:


<code>sv_cheats 1</code>


<code>bind "tab" "incrementvar host_timescale 0.25 1 0.75; incrementvar mat_yuv 0 1 1"</code>
==Running the config in-game==
To execute this configuration in-game, you would open the developer console and type this:


<code>cl_ragdoll_collide 1</code>
<code>exec CONFIGNAME.cfg</code>


<code>sk_max_ar2_altfire 10</code>
This will only work if you have saved your configuration in the correct directory (see the above section). With any luck, the changes made in your config file will have taken place.


When you go to save, make sure you have "all files" selected in the 'save as type' drop down, and save it as X.cfg (where X is the name you want it to be) in the following directory:


\steam\SteamApps\[user name]\half-life 2\hl2\cfg
==Removing the config==
There is one problem, however. After running the config, your commands will still be loaded the next time you play the game, on any map. To work around this, create another config file called uninstall.cfg (or whatever you want) and in that file, unbind all the keys that you bound in your config. To do this, use this command for each key:


==Create a map==
<code>unbind KEY</code>


Add a ''logic_auto'' into your map. (I like to keep it next to the player start to keep track of things.)
So, for example, if you bound the arrow keys and Tab, you would put this in the uninstall config:
Now add a ''point_clientcommand'' next to that, and name it "console."


Then in the outputs for your ''logic_auto'' fill it out like this:
<code>
unbind tab<br />
unbind uparrow<br />
unbind downarrow<br />
unbind leftarrow<br />
unbind rightarrow
</code>


Output: OnMapSpawn


Target entites named: console
==Configuration for a particular map==
If you want your config to automatically run with a map of your creation, simply place a [[logic_auto]] and a [[point_clientcommand]] (or [[point_servercommand]] for a multiplayer game) in the map. Name the point_clientcommand/point_servercommmand 'console'. Add this output to the logic_auto:


Via this input: Command
Output: OnMapSpawn<br />
Target entity: console<br />
Input: Command<br />
Parameter: exec YOURCONFIG


With a parameter override of:  exec YOURCFGNAME
When distributing your map, remember to include the cfg files with it. Also include instructions on how to install the configs, and how to use the uninstaller.
 
What this does is once your map loads the ''logic_auto'' tells the ''point_clientcommand'' to load the cfg file you chose, essentially typing in all the console commands you entered into that file.
 
That's it.. all your changes should be loaded for your player.
For added professionalism you could add some ''game_text'' entities with little messages like "'tab' bullet time on/off"
So your player knows about the new button changes.
 
==Distribution==
 
All you have to do is make sure you add the cfg file to your map folder containing your bsp files and stuff. And make sure you give instructions on moving it to the cfg folder.
 
==Uninstall==
 
Because the bind command is actually binding commands to a key, even without the [[cfg]] file in your HL2 directory those commands will be kept.
 
Make a new cfg file called uninstallyourmapname.cfg
And make sure all the key you binded are removed i.e:
 
<code>bind "tab" ""</code>
 
That will remove that binding in my example.
Distribute this file with you map, and write instructions on performing the uninstall.
 
==Downside==
 
The downside is, your commands will stay loaded even when the player stops playing your map and plays another one like an official HL2 maps. Or even quits HL2 (so use the uninstall method to clean things up.
And thirdly im only learning all this and there are some bugs to iron out but you guys can work around 'em.
And if any one knows a way to slow the audio down with console commands, I’d love to make that bullet time effect cooler, so let me know.
 
==Alternate==
 
Alternatively, you could just create a point_clientcommand entity. Then in the outputs for an object, you could fill it out:
 
Via this input: Command
 
With a parameter override of:  ENTERCOMMANDHERE
 
Difference: You don't have to create a .cfg file, you would only have to create one output for every command (you can still string commands together with ;).


==Alternative (for per-map configs)==
If you wanted to adjust settings for your map like you can in a config file, but you didn't want to have to bother with installing/uninstalling config files, you could use logic_auto and point_clientcommand/point_servercommand alone. Simply use the output shown in the previous section, but change the parameter to the command of your choice.
[[category:Tutorials]]
[[category:Tutorials]]
[[Category:Level Design]]
[[Category:Level Design]]

Latest revision as of 08:22, 12 July 2024

English (en)Français (fr)Русский (ru)中文 (zh)Translate (Translate)

Introduction

Modifying the gameplay of a Source game such as Half-Life 2 does not have to require knowledge of programming or Source-modding. This short tutorial is going to teach you how to use configuration files to modify gameplay. Configuration files are simply files which contain a list of instructions for the Source engine to perform. The instructions are developer console commands, so therefore anything that can be typed in the console can be placed in a configuration file.

With console commands, you can change anything from the maximum ammunition capacity of a weapon to the damage that an antlion-guard deals when it charges into you. A full list of console commands is available here, but remember that some listed there are only applicable to Half-Life 2 and its episodic sequels. If a command in the list has Yes written in the Cheat column, then you must add sv_cheats 1 to the beginning of your config file before you can use it.

Creating the config

Open Notepad or a text editor of your choice, and write some console commands of your choice, separated by new lines. To perform the aforementioned tasks involving ammunition and antlion-guards, you would enter these two commands:

sk_max_crossbow 30
sk_antlionguard_dmg_charge 60

There are obviously many more console variables to choose from, but this serves as an example.

Using config files, you can also bind keys to actions. For example, if you wanted to create a key to toggle a 'bullet-time' mode, you would enter this (it requires cheats to be enabled at the beginning of the config file):

sv_cheats 1
alias "BulletTimeOn" "host_timescale 0.5; mat_yuv 1; switchToOff"
alias "BulletTimeOff" "host_timescale 1; mat_yuv 0; switchToOn"
alias "switchToOff" "bind tab BulletTimeOff"
alias "switchToOn" "bind tab BulletTimeOn"
switchToOn

With this config executed, you could press the Tab key to slow down the game and create a monochrome effect on the screen, and press it again to revert the game to normal. To find out more about how that toggle works (it seems quite complicated but it isn't), see alias and bind.


Saving the config

When saving your configuration file, remember to always have the 'Save as type' drop-down box set to 'All file types'. Save your config as anything you want, but remember the .cfg extension. If you were creating a config for Half-Life 2, you would save it here:

WhereSteamIs\steamapps\YourUsername\half-life 2\hl2\cfg


Running the config in-game

To execute this configuration in-game, you would open the developer console and type this:

exec CONFIGNAME.cfg

This will only work if you have saved your configuration in the correct directory (see the above section). With any luck, the changes made in your config file will have taken place.


Removing the config

There is one problem, however. After running the config, your commands will still be loaded the next time you play the game, on any map. To work around this, create another config file called uninstall.cfg (or whatever you want) and in that file, unbind all the keys that you bound in your config. To do this, use this command for each key:

unbind KEY

So, for example, if you bound the arrow keys and Tab, you would put this in the uninstall config:

unbind tab
unbind uparrow
unbind downarrow
unbind leftarrow
unbind rightarrow


Configuration for a particular map

If you want your config to automatically run with a map of your creation, simply place a logic_auto and a point_clientcommand (or point_servercommand for a multiplayer game) in the map. Name the point_clientcommand/point_servercommmand 'console'. Add this output to the logic_auto:

Output: OnMapSpawn
Target entity: console
Input: Command
Parameter: exec YOURCONFIG

When distributing your map, remember to include the cfg files with it. Also include instructions on how to install the configs, and how to use the uninstaller.

Alternative (for per-map configs)

If you wanted to adjust settings for your map like you can in a config file, but you didn't want to have to bother with installing/uninstalling config files, you could use logic_auto and point_clientcommand/point_servercommand alone. Simply use the output shown in the previous section, but change the parameter to the command of your choice.