Gah - a solution with more questions. – EntropicLqd

Difference between revisions of "User:Eliot/Modify Players"

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
(Created page with 'This tutorial will explain how to make a simple {{classgames|Mutator}} that can modify a player when the player spawns. '''Note:''' You need to understand how to make a project …')
 
m (We who?, i mean you!)
Line 3: Line 3:
 
'''Note:''' You need to understand how to make a project and how to compile a project to succeed this tutorial.
 
'''Note:''' You need to understand how to make a project and how to compile a project to succeed this tutorial.
  
First we will make a new .uc file named '''FastPacedMutator.uc''', open it and write down the following code <code>class FastPacedMutator extends Mutator;</code>, now we need to override a function from the parent class ''mutator'' named '''ModifyPlayer''' this function is called by the <code>GameInfo.uc</code> class whenever a player is about to posses a new {{classgames|Pawn}}.  
+
First you will make a new .uc file named '''FastPacedMutator.uc''', open it and write down the following code <code>class FastPacedMutator extends Mutator;</code>, now you need to override a function from the parent class ''mutator'' named '''ModifyPlayer''' this function is called by the <code>GameInfo.uc</code> class whenever a player is about to posses a new {{classgames|Pawn}}.  
  
Write this code <code>function ModifyPlayer( Pawn Other )</code>, '''Pawn''' is the object class this function accepts, you cannot change it because we have to accept the same class as the parent class ''mutator'', '''Other''' is the name we'll use as reference to the passed ''pawn'' instance, you can change this reference name to whatever you like.  
+
Write this code <code>function ModifyPlayer( Pawn Other )</code>, '''Pawn''' is the object class this function accepts, you cannot change it because you have to accept the same class as the parent class ''mutator'', '''Other''' is the name you will use as reference to the passed ''pawn'' instance, you can change this reference name to whatever you like.  
  
now that's done we can start writing code, add <code>{</code> next to the end of ''ModifyPlayer'' on a new line(optional), now lets use the ''Other'' reference to access a member of the class ''Pawn'' by doing <code>Other.</code> followed by <code>GroundSpeed</code> (you can always use something else too, just take a look at <code>Pawn.uc</code>), now add <code>+=</code> this is an operator that will increment the value of ''GroundSpeed'' by the specified value, we do this by writing <code>100</code> after the <code>+=</code>, that's done now this means whenever this function is called, the passed ''Pawn'' instance will have it's ''GroundSpeed'' incremented by 100.  
+
now that's done you can start writing code, add <code>{</code> next to the end of ''ModifyPlayer'' on a new line(optional), now lets use the ''Other'' reference to access a member of the class ''Pawn'' by doing <code>Other.</code> followed by <code>GroundSpeed</code> (you can always use something else too, just take a look at <code>Pawn.uc</code>), now add <code>+=</code> this is an operator that will increment the value of ''GroundSpeed'' by the specified value, you do this by writing <code>100</code> after the <code>+=</code>, that's done now this means whenever this function is called, the passed ''Pawn'' instance will have it's ''GroundSpeed'' incremented by 100.  
  
We got nothing else to add so we can finish this line by adding a <code>;</code> next to the value. Because this is the only thing we want this function to do we can tell the compiler where the end is of this function by writing <code>}</code> on a new line.
+
We got nothing else to add so you can finish this line by adding a <code>;</code> next to the value. Because this is the only thing you want this function to do you can tell the compiler where the end is of this function by writing <code>}</code> on a new line.
  
 
That's how easy it is to do folks! now you've got a ''mutator'' that will increment the speed of all spawning players by 100!.
 
That's how easy it is to do folks! now you've got a ''mutator'' that will increment the speed of all spawning players by 100!.
  
 
==Additional functionality==
 
==Additional functionality==
To make this ''mutator'' cooler we could add a variable, see [[Variables]] e.g. <code>var float GroundSpeedIncremention;</code>.
+
To make this ''mutator'' cooler you could add a variable, see [[Variables]] e.g. <code>var float GroundSpeedIncremention;</code>.
  
 
Add <code>GroundSpeedIncremention += 0.1;</code> inside the ''ModifyPlayer'' function after the <code>Other.GroundSpeed += 100;</code> line.
 
Add <code>GroundSpeedIncremention += 0.1;</code> inside the ''ModifyPlayer'' function after the <code>Other.GroundSpeed += 100;</code> line.

Revision as of 20:06, 12 June 2010

This tutorial will explain how to make a simple Mutator(RTNP, U1, UT, U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3) that can modify a player when the player spawns.

Note: You need to understand how to make a project and how to compile a project to succeed this tutorial.

First you will make a new .uc file named FastPacedMutator.uc, open it and write down the following code class FastPacedMutator extends Mutator;, now you need to override a function from the parent class mutator named ModifyPlayer this function is called by the GameInfo.uc class whenever a player is about to posses a new Pawn(RTNP, U1, UT, U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3).

Write this code function ModifyPlayer( Pawn Other ), Pawn is the object class this function accepts, you cannot change it because you have to accept the same class as the parent class mutator, Other is the name you will use as reference to the passed pawn instance, you can change this reference name to whatever you like.

now that's done you can start writing code, add { next to the end of ModifyPlayer on a new line(optional), now lets use the Other reference to access a member of the class Pawn by doing Other. followed by GroundSpeed (you can always use something else too, just take a look at Pawn.uc), now add += this is an operator that will increment the value of GroundSpeed by the specified value, you do this by writing 100 after the +=, that's done now this means whenever this function is called, the passed Pawn instance will have it's GroundSpeed incremented by 100.

We got nothing else to add so you can finish this line by adding a ; next to the value. Because this is the only thing you want this function to do you can tell the compiler where the end is of this function by writing } on a new line.

That's how easy it is to do folks! now you've got a mutator that will increment the speed of all spawning players by 100!.

Additional functionality

To make this mutator cooler you could add a variable, see Variables e.g. var float GroundSpeedIncremention;.

Add GroundSpeedIncremention += 0.1; inside the ModifyPlayer function after the Other.GroundSpeed += 100; line.

Change the Other.GroundSpeed += 100; line to Other.GroundSpeed += 5 * GroundSpeedIncremention;.

Now compile the mutator and test!. As you might have noticed this mutator will now increment the spawned player's GroundSpeed by 5 multiplied by GroundSpeedIncrementation, then GroundSpeedIncrementation is incremented by 0.1 so that the next time a player spawns he will be even faster than the first time a player spawned, and so on.