Lesson 1 - Your first mutator

Lessons and tutorials about mods and maps
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Lesson 1 - Your first mutator

Post by Feralidragon »

First, in order for you to create your mods and addons into UT, you need external tools to do so.
Please, do NOT use the Unreal Editor that comes with the game for this!

For UnrealScript, you need a text editor which is able to show line numbers and highlight the UnrealScript syntax.
There isn't such a thing as "the best one" on this matter, so I will just provide the ones I use out of personal preference:

- Notepad++ (with custom UnrealScript plugin): http://www.mediafire.com/?501s9mutukpwcmf
- UMake: http://www.mediafire.com/?kh7481rhh86fit4

You can of course use any other suitable to your needs, like WOTGreal or Eclipse, it doesn't matter which one you use as long as you like the one you're using and it actually works, however in this and any upcoming lessons I am going to use Notepad++ and UMake since these are the ones I use.

________________________________________________________________________________________________________________________


In this lesson we're going to make a new mutator for the game, and what this mutator is going to do is very simple:
- Every single time the player (re)spawns, the message "The player X respawned!" will be shown, being X the name of the player.


1 - To start, create a new folder with the same name your final package will have.
In this lesson the package will be called MyFirstMutator.u, therefore your folder name should be called MyFirstMutator as well.
Image



2 - Next you enter the folder you just created, and create another called Classes.
All coding files (.uc) go here.
Image



3 - Now it's time to create your first script.
First we must also give it a name, and that name will be MyMut.
Open Notepad++ (or any other editor you use), create a new file and save it as MyMut.uc in the Classes folder you just created.
From here you can start the code itself.
Image

Image



4 - Start the code with the class declaration, as:

Code: Select all

class MyMut extends Mutator;
This means that MyMut is going to be a class extending from Mutator, thus becoming a mutator class you can script yourself.



5 - Now, we write the rest of the code, using ModifyPlayer from the Mutator class.

Code: Select all

function ModifyPlayer(Pawn Other)
{
   if (Other.PlayerReplicationInfo != None)
      BroadcastMessage("The player"@Other.PlayerReplicationInfo.PlayerName@"respawned!");

   if (NextMutator != None)
      NextMutator.ModifyPlayer(Other);
}
ModifyPlayer is automatically called whenever a player (re)spawns, while saying which player through Other, so you can use it to do anything related with player respawns using this function.
Next, a check is made to see if the player Other has a valid PlayerReplicationInfo, since without it there's no way to know the player's name.
Then all there's left to do is to broadcast the message itself to everyone.

The last NextMutator lines are there to keep all the other mutators working. So every time you see this kind of NextMutator code in the original function, be sure to keep it in your code, otherwise you may break other mutators when using them together.



6 - In the end your class should look like this:
Image



7 - Save the file.
Now it's time to create the .u package where your mutator will be stored, so it can be read and used by the game.
For that, copy your MyFirstMutator folder and paste it to your Unreal Tournament main directory.
Image



8 - Next, run UMake, and set the path to the folder you pasted to the Unreal Tournament directory in the previous step, and hit Compile.
Image



9 - Let it finish, and once it says "Done", close UMake.
Image



10 - Now as you can see, a new MyFirstMutator.u in your System folder, in your Unreal Tournament directory.
Image



11 - However, creating the package is not enough, as the game needs to know about its existence in order to load up your mutator.
For that you need to create, in the same directory as your MyFirstMutator.u package, another file with the .int extension.
In this case, we will call it MyFirstMutator.int, and write the following:

Code: Select all

[Public]

Object=(Name=MyFirstMutator.MyMut,Class=Class,MetaClass=Engine.Mutator,Description="My First Mutator")
Name: is your <package name>.<mutator class>.
MetaClass: for now (for the sake of simplicity), consider this to be the way you define what kind of mod you want to load up, in the case of mutators is always Engine.Mutator.
Description: here is where you write how your mutator is called, and the name that will appear in the mutator list when your start the game.



12 - So now you have made all the files needed to run your new mutator, so just launch the game and test it up!
Image

Image

Image



________________________________________________________________________________________________________________________


You can download the source and compiled package used in this lesson here:

Source: http://www.mediafire.com/?xvj31raf9ljdi73

Package: http://www.mediafire.com/?y2hryny7vwfuwsc

________________________________________________________________________________________________________________________

User avatar
Wises
Godlike
Posts: 1089
Joined: Sun Sep 07, 2008 10:59 am
Personal rank: ...

Re: Lesson 1 - Your first mutator

Post by Wises »

awesome tutorial Feralli, keep em coming mate.
very easy to follow and better then 'Hello World!'by 10,000x's

Awesome.
User avatar
Chamberly
Godlike
Posts: 1963
Joined: Sat Sep 17, 2011 4:32 pm
Personal rank: Dame. Vandora
Location: TN, USA
Contact:

Re: Lesson 1 - Your first mutator

Post by Chamberly »

I think the UMake like to be specific, so it have to be under the C:\ ?
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Lesson 1 - Your first mutator

Post by Feralidragon »

Wises wrote:awesome tutorial Feralli, keep em coming mate.
very easy to follow and better then 'Hello World!'by 10,000x's
Thanks. I don't like the "Hello World!" ones either, I never got how they teach anything at all. If anything, a person gets even more confused and demotivated to do stuff at the start:
"So we're going to print the line Hello World";
"And what does that achieve?"
"Absolutely nothing..."
:lol2:

While this way you see something already with just a few lines, thus the feeling of having achieved something starts to build up to serve as motivation and catalyst to learn and do more.
But this is just my opinion of course.
Chamberly wrote:I think the UMake like to be specific, so it have to be under the C:\ ?
Afaik, UMake only needs to be able to detect your UT install, since underneath what it does is calling UCC from the UT System folder.
That's why the packages to compile need to be at the main UT install directory like I have shown up there.
If you are still having trouble, post screenshots or write down the directories you're using so I can tell you what you're doing wrong.
User avatar
Wises
Godlike
Posts: 1089
Joined: Sun Sep 07, 2008 10:59 am
Personal rank: ...

Re: Lesson 1 - Your first mutator

Post by Wises »

Awesome..

so what is the end goal of this set of tutorials? like , is there some kind of big Picture that we can expect to achieve if as we progress along these tutorials?

Be Awesome to see/know what we will end up building :)
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Lesson 1 - Your first mutator

Post by Feralidragon »

The purpose of these tutorials is to make anyone able to make mods for UT, and potentially get enough knowledge to do more in other games.
So in the end, ideally the end user should be able to:
- get some basic programming knowledge
- get some basic algorithms knowledge
- understand how to approach a "problem" (an idea, a fix, etc, thinking outside the box)
- be able to code with some ease in UScript: build mutators, weapons, online stuff, etc

So, basically, the purpose is to not make the end developer a "pro", but to give him the essential "skills" (if we can call it that way), so from there he can discover the rest by himself by just looking at the code, and potentially do the same in other games or other UEngine versions with some ease (since the only thing that changes between games is the structure of the engines and the coding language, but the programming, algorithms and the way to approach each problem remain pretty much the same).
User avatar
Chamberly
Godlike
Posts: 1963
Joined: Sat Sep 17, 2011 4:32 pm
Personal rank: Dame. Vandora
Location: TN, USA
Contact:

Re: Lesson 1 - Your first mutator

Post by Chamberly »

I've completed this and it works. Made me laugh, worthy experience. :) Thank you!
Pileyrei
Masterful
Posts: 745
Joined: Tue May 05, 2009 3:10 pm
Personal rank: UT Survivor

Re: Lesson 1 - Your first mutator

Post by Pileyrei »

Really enjoyed this lesson Feralidragon :tu:

I changed my message to:

BroadcastMessage(""@Other.PlayerReplicationInfo.PlayerName@"IS BACK AGAIN BABY!!");

Works great 8)

Thanks for sharing your knowkedge, I may just have to make something now :oops:
Image

Our Server
Image

[donate][/donate]
Donate to UT99.org!
User avatar
UnrealGGecko
Godlike
Posts: 2894
Joined: Wed Feb 01, 2012 11:26 am
Personal rank: GEx the Gecko
Location: Kaunas, Lithuania
Contact:

Re: Lesson 1 - Your first mutator

Post by UnrealGGecko »

Here's something I learned today, adding a description of a mutator:
NOTE: for this, in UT, go to ''Help'' and turn ''Context Help'' on.

Now in the .int file, you can add something like this:

...,Description="My First Mutator,Shows when each player or bot respawns on the talkbox")

That text should appear at the bottom tab (which should be there if you followed my note) when you click at your mutator.
Hope this turned useful ;)
User avatar
ChA1NsAw
Novice
Posts: 5
Joined: Tue Sep 06, 2011 11:09 pm
Location: Belgium
Contact:

Re: Lesson 1 - Your first mutator

Post by ChA1NsAw »

I love this website. Thanks, helps a lot!
Sakura
Novice
Posts: 6
Joined: Sun Nov 02, 2014 5:22 am

Re: Lesson 1 - Your first mutator

Post by Sakura »

Thanks for the tutorial.

I added braces, a counter, and changed the Other variable name.

Code: Select all

class Ferli extends Mutator;

var int counter;


function ModifyPlayer(Pawn pOther)
{
   if  (pOther.PlayerReplicationInfo != None) {
      BroadcastMessage("The player"@pOther.PlayerReplicationInfo.PlayerName@"respawned!");
      counter++;
      BroadcastMessage(counter@"yes, this is like the +"); }
  
   if  (NextMutator != None) {
      NextMutator.ModifyPlayer(pOther);  }
      

}
I know basic C#.

The @ symbols are just like + operator in C#.

Code: Select all

"The player" + pOther.PlayerReplicationInfo.PlayerName + "respawned!"
The function ModifyPlayer is a pre-existing function. How can I become aware of all these functions and properties that already exist? UnrealScript is not like C# Visual Studio where you type in one letter and a box of autocomplete pops down below. I see some new datatypes around that I'm not used to. Sound, Texture, and now Pawn. You don't even have to call functions either? They just run?

Does anyone have gopostal's IE documentation site?
UT99.org

Re: Lesson 1 - Your first mutator

Post by UT99.org »

billybill wrote:Can also use $ to switch between them without having a space. The @ will apply a space but you could use

Code: Select all

"text "$var$" text"
same result

You don't have to declare the functions but they should exist in a parent class. I'm sure you will see what I mean if you follow instructions I give

Open UnrealEd, go to the View menu, Actor Class Browser. In the window that comes up go to File menu, Export All Scripts.

Now if you go to the Mutator class you will see all the functions you can extend off of

And sorry I don't have a link to any of the UScript/UE tutorials posted by gopostal if that's what you meant. I have them on another drive though if nobody gets back to you

By the way welcome to forums, don't forget an introduction post although it's optional. And read the rules.
Sakura
Novice
Posts: 6
Joined: Sun Nov 02, 2014 5:22 am

Re: Lesson 1 - Your first mutator

Post by Sakura »

billybill wrote:Can also use $ to switch between them without having a space. The @ will apply a space but you could use

Code: Select all

"text "$var$" text"
same result

You don't have to declare the functions but they should exist in a parent class. I'm sure you will see what I mean if you follow instructions I give

Open UnrealEd, go to the View menu, Actor Class Browser. In the window that comes up go to File menu, Export All Scripts.

Now if you go to the Mutator class you will see all the functions you can extend off of

And sorry I don't have a link to any of the UScript/UE tutorials posted by gopostal if that's what you meant. I have them on another drive though if nobody gets back to you

By the way welcome to forums, don't forget an introduction post although it's optional. And read the rules.
Thanks billybill, you probably answered a future question. Now if I see a $ for an operator I won't be confused. @ for a space and $ without a space.

Yes, I will export all the scripts. That would help me alot... My Actor browser crashes when I try to export the scripts. I have a chicken edition of UT which he edits himself. I guess I'll have to install a regular disc UT and see if I can transfer the new files over. I will post an introduction later today.
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Lesson 1 - Your first mutator

Post by JackGriffin »

Sakura wrote: Does anyone have gopostal's IE documentation site?
gopostal is a dick, I wouldn't fool with him. :ironic:

Bookmark this site:
http://uncodex-ut.host56.com/
It's an easily readable breakdown of the class tree and source code for all the actors in the game. If you know C+ then UScript won't be hard to grasp. I have a local copy somewhere around here if you want to thumb drive it so it's portable.

I hang out at Hitman's teamspeak: 176.9.104.176 on the weekends and most evenings (west coast US time). I'll be in the Mapping/Coding room banging rocks together trying to make fire. Feel free to stop in and I'll send you the tools you are going to need to compile and import most anything you want to make. All the guys in there are great so don't feel odd about jumping on. I'm currently away but I'll be back on in an hour or so (it's almost 2pm PST). I post all my mods both here and on my forum (in sig). Generally I include source code with my downloads (as do several other devs) so it makes it nice to see the mod then see how to make it yourself, and make it better.

Welcome to the scene. I hope you enjoy yourself :)

-Kelly aka gopostal
So long, and thanks for all the fish
User avatar
papercoffee
Godlike
Posts: 10441
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Lesson 1 - Your first mutator

Post by papercoffee »

I've edit your post so everything is now clearer :mrgreen:
Locked