Wikis / Unreal Wiki / Legacy:MutTutorial

This Unreal Tournament 2004 Tutorial will take you through the basic process of creating a mutator that allows you to alter a players health and the number of multi-jumps they can perform.

You can download the code from [1], but it might not be as up to date as the code on this page. For the original page check out MutTutorial code.

Before You Start

As with the UnrealScript Hello World tutorial we need to create a directory to hold our mutator code. The name of the directory determines the name of the package into which your code will be compiled. To that end you need to Set Up Package Folders:

  1. Create a directory MutNeedBetterName within your UT2004 directory
  2. Create a directory Classes within the MutNeedBetterName you just created.

You should have the following folder tree:

UT2004
__TREETAG_2__MutNeedBetterName
__TREETAG_0____TREETAG_2__Classes

The Mut prefix is used as a convention within UT2004 to indicate all packages and classes that relate to mutators. It is not mandatory to do this and we could have called our package (and therefore the directory) NeedBetterName. It is recommended that you use the conventional Mut prefix though for organisations sake.

Writing the Mutator

Now to actually write some code that can be compiled.

Within your /UT2004/MutNeedBetterName/Classes directory create a file called MutNeedBetterName.uc. All Unreal Script class files have an extension of .uc. They must also be named after the class file they are contained within.

Add the following code to the file. The code is described after each logical block.

class MutNeedBetterName extends Mutator;

This is the class declaration. We are essentially telling the game that this is a new class called MutNeedBetterName and that it is a type of (it extends, or subclasses) Mutator. And finally, like all good things in life, the class declaration is terminated with a semi-colon. You can see Class Syntax for more information.

var int MultiJumpCount, MultiJumpBoost, StartingHealth, MaximumHealth, SuperDuberMaximumHealth; // The number of multi-jumps allowed
//The boost the player gets from a multi-jump and the player's starting health

The section above defines three variables (all integers - see Variable Types) that are all properties of the class being defined.

function ModifyPlayer(Pawn Other)
{
  local xPawn x; //x is a variable
  x = xPawn(Other); 
  if (x != None)
  {
    x.MaxMultiJump = MultiJumpCount;
    x.MultiJumpBoost = MultiJumpBoost;
    x.Health = StartingHealth;
    x.HealthMax = MaximumHealth;
    x.SuperHealthMax = SuperDuberMaximumHealth;
  }
  // YOU FORGOT TO CALL THE SUPERCLASS! THIS BREAKS THE MUTATOR CHAIN
 
  // Tested this code with the Superclass below and it was not recognized (UT2K4)
  // Super.ModifyPlayer( Pawn Other );
 
}

The first line declares the function (see Function Syntax). This is the function that actually updates the player's attributes. Because our class is a type of Mutator the ModifyPlayer() function will be called automatically for every player in the game as they spawn.

The next two lines of code (ignoring the braces) do the following.

  • Declare a local (only visible within the function) variable of type xPawn (xPawn is a type of Pawn, and can be found in the xGame package).
  • Assign a value to our local variable after Typecasting the value passed in the Other function parameter. Note that if Other is not a type of (or subclass) xPawn our local variable will contain None.

The if statement checks to see if the local variable has a value by comparing it to the "empty value" None using the not equal to (!=) operator. See Operators for more information. Remember - if the object referenced by Other is not an xPawn our local variable will be equal to (----) None.

The block of code within the if statement adjusts the player's jump and health properties using the values from our mutator's configurable properties.

defaultproperties
{
  MultiJumpCount=10
  MultiJumpBoost=50
  StartingHealth=250
  MaximumHealth=250
  SuperDuberMaximumHealth=500
  GroupName="MutNeedBetterName"
  FriendlyName="What ever you want the Mutator to be called" //This is the name of the Mutator that will display in game
  Description="Changes your initial health and Multi-Jumping ability"
}

This block of code allows you to specify default values for all of your class properties. If a class property is declared as configurable then the value within the mutator's ini file will be used if available instead of the value specified here. The Default Properties page contains much more information about how default values should be specified.

Compiling and Using the Mutator

Next add this code to the file UT2004.ini: "EditPackages=MutNeedBetterName"

Move the folder MutNeedBetterName into C:\UT2004 (or where ever you installed UT2004)

Move the file MutNeedBetterName.int into UT2004\system

Open Command line (a quick way to do this is to open "run" and type cmd)

type in "C:\UT2004\System\ucc make" press enter and wait.

Ucc will go through all the folders and if you edited your UT2004[or 3 i think].ini right it should go through your folder.

Hopefully it will say success, there were no errors. If it does run Unreal Tourney and you will see under mutators Mutation Tutorial.

Adding a Configuration Window

If you want to allow your mutator's configurable parameters to be changed from the standard UT2004 mutator config window then please see the Mutator Config GUI (UT2004) reference.

Useful Pages


Conclusion

You should now have code that looks like this (without the comments): MutTutorial Code

Discussion

See Legacy talk:MutTutorial.

Page Categories

Page Information

2022-11-18T09:39:02.400714Z 2009-06-18T05:50:34Z 70.24.14.46 /* Writing the Mutator */ https://wiki.beyondunreal.com/Legacy:MutTutorial Attribution-NonCommercial-ShareAlike 3.0