Liandri
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Liandri

The forum offers unofficial support for UnrealEd users and serves as a comfortable rest-room for a friendly community.
 
HomeLatest imagesRegisterLog in

 

 [WIP]Expanding on Mutators: Players

Go down 
AuthorMessage
PhoenixWing




Posts : 22
Join date : 2009-03-12
Location : Sunny Cali!

[WIP]Expanding on Mutators: Players Empty
PostSubject: [WIP]Expanding on Mutators: Players   [WIP]Expanding on Mutators: Players Icon_minitimeTue Apr 07, 2009 2:23 am

Welcome to Part 2

NOTE: These tutorials are meant to help and support your desire to code in the Unreal series. To help you get a better understanding of the coding world, download the UT2004 Source code and have a look through the classes and try and customize the tutorial by changing what i have done, and inserting your own custom pieces. Don't do exactly what the tutorial says, try and mix it up by changing what it does, like giving the person Speed instead of Berserk. I have found out this is a lot more helpful then just doing exactly what i have said.

Well now that you have finished the MyFirstMutator you are ready to move on to more advanced mutators! Today we are going to find out how to change players in UScript. In our little mutator we will give the flag carrier berserk, and lower your score by 1 if you die just like in Halo 1 and 2. So lets start out with our usual first line
Code:
class FlagBerserk extends Mutator;

That should be familiar to you. Now lets start writing the gut of our code. How do we check if somebody has the flag in Unreal? Well in UT theres a class called a "Pawn" which is the base for all Players. Then we have the xPawn which is the actual player which is subclassed off of the Pawn. We will ask the xPawn, hey do you have the flag? And if it says "Why yes! Yes i do" We will give Mr. xPawn and nice little boost to help him get back to his base. Now lets translate that into solid code:
Code:

auto state startup
{
  function tick(float deltatime)
  {
    local xPawn P;
   
    foreach DynamicActors(class'xPawn',P)
Whats auto state startup mean? Well just as its called, its the "state" that the mutator is in when it first startups. A state is just a position (not literally a position like sitting) that the class is currently at. Then we have our little function called "tick". A tick is every frame that is refreshed, which is about 30-40 each second. So this function will be called every tick that it goes. A float, is a number that isnt a whole number. EX: It could be 4.38 or 4.39394573292034081234 so it can be very long. Deltatime is the time since the last tick. Then we state a local value that we are going to use. This time it is a value called P which is the xPawn in the foreach command. Now we get to the foreach command which means for each thing that its told to look for it finds on the map, do this to it. We are telling it to look for a DynamicActor since xPawns are constantly changing, and then the xPawn that its currently on we will call P. But why do we have to say DynamicActor? Well if we put AllActors, it would have the same effect as DynamicActors, but it would take more resources to find the xPawn as it will ask each and every Actor "Are you an xPawn?" which we wouldn't want. You could put TouchingActors which would look for two of the same classes touching each other, if you wanted some specific thing to happen if two things collide, like 2 cars, or you could be more specific and put ForEach Owner.TouchingActors so every owner of the actor (such as a player's weapon) that is touching an actor that you define you could tell to do something. We will put DynamicActors as it is the fastest, and most efficient for our purpose. So we have our start to look for xPawns in the map, but how do we see if they have the flag? Lets find out!
Code:

auto state startup
{
  function tick(float deltatime)
  {
    local xPawn P;
    local bool bPickedUp;

    foreach DynamicActors(class'xPawn',P)
      {
        if ( (P.PlayerReplicationInfo != None) && (P.PlayerReplicationInfo.HasFlag!=None))
        {
            P.Weapon.StartBerserk();
        }
        else
        {
          if(P.bBerserk = false)
              P.Weapon.StopBerserk()
        }
      }
  }
}
So that is the main gut of the code ladies and gentlemen! Let me explain what a few of those things are. So when the foreach command finds an xPawn it will ask the xPawn's (we named it P so it doesn't think its asking the xPawn class itself) PlayerReplicationInfo (which is the class that sends out players location, weapons, status, and other player related items to other people playing) if it is not nothing, and also that the PlayerReplicationInfo has the flag. Why do we need to ask the PlayerReplicationInfo? Well the xPawn class itself is just holding the code for movement, animations, and other player items, it doesn't contain values like HasFlag. If we put P.PlayerReplicationInfo it will check the xPawns PlayerReplicationInfo which does have the values for the flag. You can use that method to ask for example the xPawns weapon like this: xPawn.Weapon which could change it if you wanted to, to a shock rifle. If it does have the flag we tell the xPawn's weapon to start the Berserk function which increases its speed. If the xPawn doesn't have the flag, it stops the berserk function, just in case you drop the flag by translocating unless you have the combo Berserk on (bBerserk is the boolean that is turned on by the combo class) in which case it doesn't. But what if you don't want the Berserk for the flag carrier? What if you want to give them speed, or invisibility? Well that is very simple! We only need to change the P.Weapon.StartBerserk(); to a different function!
For invisibility you would put P.SetInvisibility(60.0) which is 60% invisibility so you are still partially visible. For speed you would put P.GroundSpeed *=1.4; which would increase it by 140% A * in UScript means multiply just as a note. How am i finding these functions out? Well i have a handy little program called WOTgreal, have a look at the bottom of my post and i'll explain it. Need the source code for the game to have a look at the code? Try here: http://unreal.student.utwente.nl/uncodex-ut2004/ or go to google and search for Ut2004 Source Code and you should find a 3-4mb download for all the code for the game. Then you can search through all the codes such as the combos to find out what else you could put for the FlagCarrier or even make your own code that could be based off of this and go way beyond the tutorial.

Tada! We have the first part of our tutorial finished. I'm currently finding out a better way to check for recent deaths to minus the score of the player that just died. Until then this tutorial is a WIP. As soon as i figure it out you can bet this will be finished! This is a working mutator so far, all you need is to add the default properties just like in the MyFirstMutator thread.

What is WOTgreal?
WOTgreal is an editing program for the Unreal Engine. It helps you by labeling which functions can go where in a class, fast searching for certain things in UT2004 code, and a built in compiler to bypass having to run Command Prompt to compile. It supports all Unreal Powered games. I use it as its a big help when making long code and it makes correcting mistakes easier. Try it at http://www.wotgreal.com/
Note that the program is not free, however you can use the trial as long as you wish, but it will take a litter longer to load each time until you purchase it.

-Phoenix]
Back to top Go down
 
[WIP]Expanding on Mutators: Players
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Liandri :: = Tutorials :: UnrealEngine 2-
Jump to: