Announcement

Collapse
No announcement yet.

General OOP question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    General OOP question

    Hello,
    I am very new to UScript and OOP in general, but not programming. I have a question:

    Say I am writing a mutator to give the MachineGun unlimited ammo. I want the mutator to inherit the properties of a Mutator, but I also need it to inherit the properties of the machine gun. Is there a way to extend multiple classes?

    Eya

    #2
    No, you can't do that, but you shouldn't really need to. You would need to create a new weapon class and a new WeaponFire class. In the WeaponFire class you would set AmmoPerFire=0 in the default properties, and boom! Doesn't use any ammo!

    You could make a simple mutator that iterated though all the existing machine guns and replaced them with yours at the start of the match.

    Comment


      #3
      I know that it would be a PreBeginPlay function, but that is as far as my comprehension goes. Is there a specific page in the Wiki that deals with this? I dont anyone posting codeblocks, I like to do it myself.

      Comment


        #4
        No specific page dealing with what you want to do, but there is one that deals with iterators:

        http://wiki.beyondunreal.com/wiki/Iterator

        Basically what you want to do is in prebeginplay(), do a foreach dynamic actors(class'XWeaponBase', Base (or some name) ) and check if they have your custom gun pickup class and if they don't, replace their gun pickup class with your gun pickup class. Or, if you want it to be an instagib scenario (in which all players spawn with the weapon and nothing else), take a look at the MutInstagib code.

        Comment


          #5
          Ok, here is a first try:

          PHP Code:
          class FullAmmo extends Mutator;

          function 
          PreBeginPlay()
          {
             
          local int NewAmmoUsage;

             foreach 
          AllActors('MiniGunPickup' NewMachineGun)
            {
                 
          NewMachineGun.AmmoPerFire=0;
             } 
          Now I know this is wrong. Gonna watch 3d Buzz tute on Wepon Modification to see how this works.
          But am I kinda sorta in the same universe as I need to be?

          Eyaw

          Comment


            #6
            Alright, I have finally created the class (now that I understand what you said) and it works great. I called it UberMiniGun. But I am unsure how I translate that to a mutator that replaces all the miniguns with mine. Help?

            Eyaw

            Comment


              #7
              Originally posted by Eyaw_Nayr
              Alright, I have finally created the class (now that I understand what you said) and it works great. I called it UberMiniGun. But I am unsure how I translate that to a mutator that replaces all the miniguns with mine. Help?

              Eyaw
              something like this:

              Code:
              class UberMiniGun extends Mutator;
              
              var class<Weapon> NewWeaponType;
              var class<Weapon> OldWeaponType;
              
              
              function PreBeginPlay()
              {
                  local xWeaponBase WB;
                  local MiniGunAmmoPickup MP;
              	
              	foreach AllActors(class'xWeaponBase', WB) //look through all the bases
              	{
              		if (WB.WeaponType == OldWeaponType) //if they spawn the minigun
              			WB.WeaponType = NewWeaponType; //alter them to spawn the uberminigun
              	}
              	
              	foreach AllActors(class'MiniGunAmmoPickup', MP) //look for minigun ammo pickups
              		MP.Destroy(); //destroy them since we don't need them
              }
              	
              defaultproperties
              {
              	NewWeaponType=class'YourPackage.UberMiniGun'
              	OldWeaponType=class'XWeapons.Minigun'
              }
              I haven't tested this in game but I am about to now (with a different weapon). It should work.

              EDIT: Just tested it. Works like a charm. I'm sorry I posted a code block (I know you said you didn't want people doing that), it was just easier to do than explain it (doesn't really need explaining anyway - read the code comments)

              Comment


                #8
                Eyaw, have you done the mutator tutorials on the Wiki? I think you'll find them to be a great help.

                Comment


                  #9
                  I have looked at them, but not really spent alot of time with them. I have one question about the codeblock. When you are declaring the variables, you use 'WB' and 'MP'. What is the purpose of that?

                  And thanks very much for the help!

                  Eyaw

                  Comment


                    #10
                    Nevermind, I got it working

                    Thanks again!

                    Eyaw

                    Comment


                      #11
                      That isn't the best way of doing it. There is a function in the mutator class called checkreplacement. That is used to do exactly what you want to do, it replaces one class with another. I suggest you download the source code so you can look at the function. You can find the source at http://udn.epicgames.com .

                      Comment

                      Working...
                      X