Skip to content

Creating a Mutator

Colin Basnett edited this page Oct 14, 2016 · 4 revisions

This guide will teach you basics of how to create a simple mutator.

For illustrative purposes, our task will be to write a mutator that will send a periodic message to all players connected to the server.

Prerequisites

This guide assumes that you have already installed the DarkestHourDev development environment.

What is a mutator?

Mutators are compiled code and/or asset packages that, when applied to a game server, can make modifications and additions to the base game. Mutators can be used to add weapons, vehicles, administration menus, and entirely new game types to Darkest Hour.

Creating the package

All of the code files (*.uc) for a mutator must live inside of a package. Our first job is to create that package.

To create a mutator package, we must first create a folder in the Red Orchestra directory with the name of our package.

  1. Navigate to the Red Orchestra directory (eg. C:\Program Files (x86)\Steam\SteamApps\common\Red Orchestra).
  2. Create a folder named MyMutator.
  3. Inside the MyMutator folder, create a folder called Classes.

Now your package folder is set up. Simple, right? Now we need to add some code so our mutator will do something!

Adding the code

Create a file called MyMutator.uc inside the %RODIR%/MyMutator/Classes directory. This will be the primary file for your mutator.

Once the file is created, copy and paste the the code below into MyMutator.uc and save it.

class MyMutator extends Mutator;

function PostBeginPlay()
{
    SetTimer(60.0, true);
}

function Timer()
{
    Level.Game.Broadcast(self, "Welcome to" @ Level.Game.GameReplicationInfo.ServerName $ ", enjoy your stay!");
}

Compiling the mutator

Now that we've got our mutator package created and some code to execute, we need to compile the package so that it can be executed on your server.

The first thing we need to do is to add the name of our package to a list of packages to be compiled.

The file we need to edit is %RODIR%/DarkestHourDev/System/DarkestHourDev.ini.

DarkestHourDev.ini does not exist if you have not run DarkestHourDev before. To run DarkestHourDev, use the batch file located at %RODIR%/System/DarkestHourDev.bat.

Open DarkestHourDev.ini in any text editor and search for EditPackages. You should see the following:

...
EditPackages=DH_Effects
EditPackages=DH_Engine
EditPackages=DH_Game
EditPackages=DH_Interface
EditPackages=DH_Weapons
EditPackages=DH_Vehicles
EditPackages=DH_Guns
EditPackages=DH_Equipment
EditPackages=DH_ATWeapons
EditPackages=DH_Mortars
EditPackages=DH_LevelActors
EditPackages=DH_GerPlayers
EditPackages=DH_BritishPlayers
EditPackages=DH_USPlayers

In order to compile your mutator, add the following line after the last EditPackages line in the file.

EditPackages=MyMutator

Now we're ready to compile! To compile the mutator, execute the following batch file:

%RODIR%\tools\make\make.bat
Clone this wiki locally