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 [19], 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:
- Create a directory
MutNeedBetterName
within your UT2004 directory - Create a directory
Classes
within theMutNeedBetterName
you just created.
You should have the following folder tree:
UT2004 +- MutNeedBetterName +- 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 }
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 ifOther
is not a type of (or subclass) xPawn our local variable will containNone
.
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
Tarquin: I don't understand what this is trying to show, or why there is no text on that page, only script. Secondly, in your script comments there are a number of questions you've left, and a few misconceptions. I suggest you get wait for feedback on it first before adding it to the chain of lessons.
EntropicLqd: Imagine you are completely new to Unreal Script. Is this page going to actually help you in Setting Up UnrealScript or how to Set Up Package Folders. There's no set of pre-requisites mentioned anywhere or even any real explanation of what is going on (note to self - must add them to my tut. page). To my mind the worst thing about the tutorial is that you've assumed that someone has downloaded your code. Try and fit your tutorial into a similar structure to the other tutorials on the Wiki. At least that way all of the tutorials will be in a similar form. Also one of your stated commands will not work under Windows XP, and one of them is redundant - but maybe I'm just being picky in my old age.
Mr.bob Uhhhhhhhhhh... what are pre-requisites (I mean in ucode context). Also that is kind of weird because I just used this mut in windows xp and it compiled and then worked flawlessly. Also what does redundant mean. About the prompt command I think you are talking about, I'm surprised it didn't work. Maybe I misspelled it but when I type "prompt $1 into command line in windows XP it gives me a blank prompt which is what I want. Finally there is a smiley I've been wanting to try out...
Oh ya, most importantly this tutorial was not meant for reading, it was meant for downloading as folders a .uc file and a .int file. However that didn't seem to work out. In response to Tarquin (who seems to really enjoy messing with and moving around my things ... this gives me an idea ) this code is trying to give newbs some code that they can mess around with and understand. The very first step people do when they are learning to mess with code is to do things like replace the word health with shield, and this code lets them do that.
Later: Just discovered that all the links I had previously posted to the .zip file were broken. Here is one that has to work: [THE FILE]
Tarquin, why don't you tell me what the misconceptions are so I can fix them, you people should really give me a lot more input, although the problem is you can't because there are no links to this page.
Tarquin: things like "says that there is a local variable that applies only to Xpawns, and that varaible is x." Please also take care to spell correctly. And please remove your tutorial from the list – you can put the link further down the page if you like. You can get it linked by addding a category tag to this page.
EntropicLqd: The redundant command is indeed the prompt one. You might not like to see where you are in the directory structure but I'm betting most people (like me) do. Not only that, but the command is irrelevant. You don't need it to compile any Unreal Script at all - but that's not explained.
The one I thought wouldn't work under XP was running "command". It does work but gives you the old Win9x DOS shell. The XP version (like NT) is cmd.
Pre-requisites in Unreal Script terms are the basic things someone needs to know before they can starting writing code. I linked to them in my previous post. Also, simply downloading some code and then tweaking the values to see what they do is a very inefficient way of learning. A good tutorial does the following:
* Explains what the tutorial will cover and what the person is supposed to learn from doing it.
* Explains what the person doing the tutorial needs to know in order to complete it. That is - the assumed base knowledge or as we like to say prerequisites.
* Explain in simple steps what must be done to accomplish the goal of the tutorial. At this point explaining why things are done (in this case why ModifyPlayer() was used) in a lot of detail is necessary. Your description of ModifyPlayer() is somewhat vague – and could even be misleading. And also, you should never ever leave questions unanswered in a tutorial.
* Conclude with a summary of what the person is supposed to have learned from the tutorial.
So to reiterate my original point, simply providing people with some code they can mess about with is not a tutorial. It's also unlikely to help them write their own code in the future as it provides no method for understanding why something was done in a specific way.
Mr.bob: At this point I am once again forced to admit to my newbishness (is that even a word?) and bow down to your superior knowledge. Putting the tutorial on the front page was reckless and hasty (what do you expect, I'm 14). I will delete it from the front page and start working on one worthy of this terrific site, thx for the advice EntropicLqd and sorry for bugging you by posting so much junk Tarquin. A few more points, command, while not as good a cmd still works, but thx anyway for the update. Just saying it would help if you included a description of what modify player does, considering my description was very incorrect.
Growing up in the age of spell checkers has severely damaged my spelling capabilities.
My brother is insisting that I keep the things in progress section intact with my link in it, but I'm telling him Tarquin isn't going to be happy.
Whew, that should do it, the tutorial isn't perfect yet, but it is much better then before. It is still not in traditional tutorial format, but I don't really like the traditional tutorial format.
Foxpaw: I put some more comments in there to explain some stuff that was a bit misleading. However, as you can now see, the comments take up so much space it's hard to see the code. What you might consider doing is listing the code in it's entirety (without the play by play comments) and then below that take each line and show it dissected.
Tarquin: "I was sick of lessons like the regeneration mutator that would tell you to modify some code you found without telling you what that code meant." – I think that is an excellent point! We should look into adding a "How it works" or "What's going on" section to our scripting tutorial pages!
Mr.Bob's brother: a simple note about the prompt $1 thing. we use it because in Windows XP home edition you start in this part of the directory structure: C:/Documents and settings/~username> and the UT2004 directory is C:/UT2004 so we need to make the directory structure become blank to go down to C:/.
PS. call me Doodle77 because it is my username for a bunch of games
EntropicLqd: The prompt command simply changes the DOS prompt. It does not change the directory you are in. I suspect you actually meant cd c:\UT2004
. If you wanted to make the directory structure blank then format C:\
is the command you are after.
Mr.bob: Never mind, you can type in the file path without typing in prompt $1 first, i have changed the script apropratly in light of this new discovery.
Wow this tutorial is really something now. Now i think it can add it to the chain. I will update the .zip file with the new code, and add it to the top of the Uscript lessons. The full exspanation of what the code means will REALLY help out people who are compleate newbs to programing.
Tarquin: Please could you:
- make links in your text
- add a few headings perhaps
- fix spelling mistakes
- explain what the variables you have modified mean
- I think it would be better to remove the explanations from the script entirely, it would make then easier to read – instead of comments within script, a section of text with script extracts within it.
EntropicLqd: Right then Mr.Bob. Please finish off your tutorial in the style it has started in. If you do a good job maybe I'll come back and extend it with information regarding constructing a configuration GUI for it.
Mr.bob: This is what I like about the wiki, it is not me writing this tutorial anymore, it is the whole wiki community. It's very much like open source code, that is what makes open source programs so good and flawless, there is a large amount of people who can look at the code and change things.
EntropicLqd: Maybe, maybe not. I'm just showing you how you should have written it in the first place. I won't be finishing it off for you (and I doubt whether anyone else will) as I don't have time. I certainly won't be restructuing any more of your tutorials if they are presented in the manner similar to the way this one was.
RegularX: While I like that more verbal tutes like this are getting written - it should be noted that because this is the wiki, tutes like Regen mutator can be appended to describe the inner workings of the tutorial itself...
Mr.bob: You said that you wouldn't be finishing it off. Personally I have seen much less polished tutorials then this. I think it is finished, what more does it need?
arg i read it and there is some sloppy coding, i changed it, Please don't change it back, it is acutally really bad. And this is a newb telling you this. First of all the config part is junk, second of all you repeated a lot of parts you didn't have to repeat, third of all the pre-requisites are MUCH steeper then what i had in mind ... ok it is so bad i am sequencering (<-spelling bad) the whole new section and making one that doesn't suck so much later. Please don't put it back, the code is very misleading and wasteful. I can't do anything too soon becuase my mouse is broken, sry.
EntropicLqd:
Firstly - Thanks Foxpaw. I was in a hurry and didn't bother to read what I'd actually written. Apologies to Mr Bob. for introducing junk into his perfect tutorial, and also to Foxpaw for making him come in here and fix it.
Mr Bob, just because there are much less polished tutorials than this doesn't mean that is one is finished. It just means that the other tutorials are not as good. While I agree I repeated a lot of the stuff that is covered within the UnrealScript Hello World tutorial I felt it was necessary to make the tutorial complete. You could also argue that this would be a better Hello World style tutorial than the existing one as it actually does something.
Yes I agree the pre-requisites are fairly heavy. However there is actually a fair amount of stuff that you need to know, and get right before you even start writing any code.
I'm also fairly sure that the code is broken around the "health" area but I've not had time to actually compile it and check (I'm relatively sure the player's health will get reset to 100 should thep layer actually run over a standard health pickup).
I've essentially left the compilation and use section for you to complete. When that's done I'll add the GUI elements unless you also fill those in.
Mr.bob: New tutorial, in traditional format (me don't like tradition) and the coding is awful, I will make a major revision after I get my mouse fixed. I'm just glad entropiclqd didn't delete anything important. I thought he was skilled, and maybe he is, but it looks like he was trying to make a 2004 GUI and didn't quite complete it. You should know that when changing a public page you don't present new incomplete code that you haven't even complied and tested. If I complied this code, it probably would compile and even if it did, it would be very sloppy wasteful code that might glitch the program in a worst case scenario. I don't like the traditional format that much, but if you people insist that my tutorial look like everyone else's then it shall be. If you complete the 2004 GUI soon enough I will forgive you entopiclqd, but if you don't, I'm scraping all your work, or at least sequestering it.
One more point, the pre-requisites are completely ridiculous, you don't need the unreal script source code, you don't need to have read any of those pages, and I haven't glanced at the terminology page. The installed UT2004/3 on your computer is way too obvious. I also don't like how you changed it to MutPlayerTweak. NO ONE CHANGE THE ORIGANAL PAGE SECTION, good I made my self clear.
I just turned 15 today
EntropicLqd:
- This isn't a public page yet.
- Tutorials should be written for people to follow and understand. Tradition has nothing to do with it.
- Thankyou for scrapping all my work. I look forward to seeing your alternative offering.
- MutTutorial is a crap name for the muator.
- I am indeed an old geezer.
- Happy birthday.
- Oh dear - I just changed the original page section.
Mr.bob: Damn, i thought I deleted the old geezer part, (I did, you just looked at the history) i was in a bad mood. Your right, both the names are stupid, we need a good name. And I didn't scrap all your work yet, i will in five minutes. Your right about the part about tradition, the whole time i've been trying to create a downloadable tutorial, so you don't need to copy and paste too much, that is what my origanal structure was about. Thank you for the happy birthday. Now to look at the origanal page section ... YOU DELETED IT!!! that is very annoying, now I need to harvest it from the history. Are you mad at me for calling you an old geezer (i deleted it i tell you). But comeon, that was just pointless. Now to scrap most of your changes (i was going to wait a while, but you deleted the origanal page, and i have nothing better to do).
"sigh", you could have just taken the compiling instructions from the origanal code, but i seems that you were too lazy.
I didn't compleatly scrap everything and a lot of the things you said were pretty good, all i ask is that you make a seperate page for the 2004 GUI, although i really want you to make one.
Tarquin: We can leave the GUI part out – the Mutator Config GUI (UT2004) tutorial should be generic enough to work with any mutator (and should be tweaked so it works like that). MrBob, if people are too lazy to copy & paste instead of downloading, then modding really isn't for them. I really don't think it's much of a timesaver, you still need to compile, and it's harder for us to maintain it here.
Mr.bob: Ok fine I'll take the download part out.
Entopiclqd, if you are interested in making a GUI for 2004 then look at this .uc file, if you have UT2004 then you probably have it, but for your convinance you can download it here: [Air Control]. As you can tell the file is the air control mutator for UT2004, which is vaguly similer to the mutator above. I was not able to make any sense of it, or figure out how to tweak it enough to work with health instead of air control, but you know much more about Uscript then I do.
EntropicLqd: Please see the Mutator Config GUI (UT2004) reference page for instructions on how to add GUI configuration to your mutator. I will add a discussion section at the bottom of that page should you have additional questions. If you find youself struggling with the page then I suggest referring to the set of pre-requisites I originally added to the tutorial. Calling me an old geezer is in no way offensive - I am over twice you age.
Mr.bob: Kewl, about the whole GUI thing, the above link doesn't help me, makes no sense at all. Also the volume control mutator, helped a bit more, but doesn't have enough comments in the GUI section. So far my most useful resource has been air control.
Tarquin: Like I said above, Mutator Config GUI (UT2004) should give you a template to create a GUI for any given mutator, I hope. Since I don't have UT2004 I can't try it for myself. Now as for this page's name.... I have altered the listing on the Lessons page to be a bit clearer, and I want to do the same to the name. Since the main thing this does is alter jumping, how about "SuperJump Mutator Tutorial"?
Tarquin: Message for ppp-62-235-110-208.tiscali.be – thanks for your typo corrections, much appreciated! But please don't introduce "smart quotes" into the wiki text (the ’ things) – either turn them off in MS Word or use a text editor. Thanks!
Random Guest: Sorry about that.. I don't know how that happened, maybe because i'm using IE 5.0. Anyway, this script isn't working when I try to compile it. Says MaxHealth isn't a member of xPawn. The code-page doesn't use MaxHealth. Maybe this page, or the other needs some updating. I deleted the maxhealth thing, since it didn't work. There's HealthMax in Pawn, but setting Other.HealtMax gives me another error. I don't know why, I'm a newbie. I also had to take it out of the defaultproperties. Now it works.
MythOpus: I don't have the time to test this Mut out but... have you tried x.HealthMax instead of just deleteing it completely? I think it's a critical part in the mutator... I think without changing the HealthMax property, the health can't be set over it's max... which is... 199 I believe? And why use Other when you can use x
Tarquin: The variable I think you want is Pawn.HealthMax. MrBob, did you actually TEST this????
Mr.bob: Ya, i tested it, three times, but not sense the most recent changes. sry. I'll test it now, and update the zip file.
Yay it compiled , now to update the zip file.
Wait those aren't the problem. I see the problem now. The problem is that it is "healthmax", not "maxhealth". I have edited the code.
Random Guest: That was indeed the problem. The code as it is now works, but there's one small problem. Taking health vials (the +5 things) only boosts your health till 199, not till 250 of whatever. Regular health packs do get you to 250! Therefore, i would propose this code:
x.Health = StartingHealth; x.HealthMax = StartingHealth; x.SuperHealthMax = HealthMax;
This sets the paws starting health, as discussed before, says the normal health you can reach is the same starting health, and the super health (normally 199) is set to the maximum.
I also made gui-code (mutator settings in the configuration-screen), should i post them or is that overkill for this example?
EntropicLqd: It's a little overkill for this example. Also, if the Mutator Config GUI (UT2004) page isn't good enough then it is that page that should be updated. In terms of the smart-quotes - if you edit the tutorial text in Word, they will be added in automatically. And if you use Notepad remember to turn wordwrap off.
Mr.bob: Greetings from saratoga! I've been on vacation and i havn't had acess to a computer. Right now I am using the library computer, unfortanatly I don't have a apointment and i'm in the childrens section computers (the adult comps were full). So they could kick me off at any time.
Ok, I'm going to change the code so there is super health max. Also random guest, if you have this mut with the GUI zip the .uc file(s), put them on your website (you have a website right?) and put a link to them. You can also make an extention tutorial on the wiki that tells you how to add a GUI to this mutator. Put it under the currently existing "Adding a Configuration Window" heading.
arg the : p_i_s_s_e_d : (ignore the underscores, they have a bunch of wierd filtering software on this computer which makes it so I can't write words like p_i_s_s. just don't ask) smily is broke! (or is it the filtering software on the kidy computers?).
Tarquin: I don't think SuperHealthMax = SuperMaxHealth is a good choice of variable names.........
Mr.bob: Greating from independent lake camp! Can't think of a better var name sry. Also when is random guest going to show me how to make a GUI? Hope it is soon
Tarquin: well TRY. Having variables called SuperHealthMax and SuperMaxHealth is just horribly confusing. What is the difference between these two vars? How do their names tell me of this difference? If you're going to write tutorials, you HAVE to think of this. Also, I don't think this tute should contain the GUI – see what Ent said above.
MythOpus: Instead of using 'x' as a variable. Couldn't you make life easier by using:
if (xPawn(Other) != None) { xPawn(Other).MaxMultiJump = MultiJumpCount; xPawn(Other).MultiJumpBoost = MultiJumpBoost; } Other.Health = StartingHealth; Other.HealthMax = MaximumHealth Other.SuperHealthMax = SuperMaxHealth
EntropicLqd: Mr Bob have you not read what has been written in the comments section? RandomGuest has been specifically asked not to add a section on creating a GUI for the mutator as this is covered on the Mutator Config GUI (UT2004) page. If you do not understand the information on that page then you should post some questions there.
Mr.bob: You said that he shouldn't add it on to this page. I am asking him to make a seperate page. I know you are proud of the Mutator Config GUI (UT2004) page. But I have looked at it and tried some things and ....
EntropicLqd:....Comments moved to Mutator Config GUI (UT2004) page as originally requested....
Mr.bob: I didn't request it to be moved to that page .
Random guest, at some point I would like to see this mut customized with a GUI somewhere. Don't worry, I wo't get inpatiant until I get back to NYC.
Random Guest: I've already put it on the wiki, but i haven't linked yet, since i don't know if i may, it's at MutTutorial Code With GUI. Read the Recent Changes
Tarquin: MR Bob, have you actually read the comments above? Have you read my note about variable names? If you want to have a hand in writing a tutorial here, please take note of these things instead of asking for more help.
Mr.bob: Sorry about my laziness tarquin. I'll change the bad var name now.
You are the coolest random guest. Thank you so much.
I tested the mutator with the GUI, it works perfectly. After I tweak it and make it bigger, i'm going to make a tutorial for it (unless random guest wants to first).
Tarquin: I thought this tutorial was meant to be simple.
Random Guest: Be my guest Mr. bob, make all you like. I don't like typing tutorials You can use wotgreal (don't know the link to the page), that expands a menu when you type a dot.
Mr.bob: I meant I would make a different tutorial for this, one that would say that it was harder.
Does anyone know what other modifiable things are a part of the class Xpawn, besides the ones used above?
Mr.bob: It's been about 2 months, and the Mut turorial code with GUI hasn't been updated. And no one ahs responded to my question.
The mut tutorial with GUI has some confusing variable names, for example multijumpboost = multijumpboost and healthmax = healthmax , and superhealthmax = superhealthmax. They should be changed, in my opinion at least, (Behind my back my brother is compaining that those names make it easier and i'm wrong.
GRAF1K: Your question either is confusingly stated or assumes something incorrect, so people are unlikely to respond. Rephrase it and you'll have better luck.
Tarquin: With the variable names, I think you need to adopt a scheme that makes it clear which xPawn variable it relates to. Eg,
x.MultiJumpBoost = myMultiJumpBoost ;
and so on.
SuperApe: I'm just guessing by the sheer volume of discussion entries that this page needs a RefactorMe tag. If not, (or if refactored) please remove.