Announcement

Collapse
No announcement yet.

Question on substituting weapons

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

    Question on substituting weapons

    Hey, Im new to this programming stuff and ive gone through some tutorials along with the ones on the DVD that came with the game.. Im making a small mutator that changes a few things to a couple of weapons (make sniper shoot faster, etc.). The following code is for the mutHalo class, and it just changes some stuff to the sniper..and it works.. my question is how do you get another weapon switch/ or weapons replacement?? Ive tried a few things but it doesnt seem to work, and I would appreciate it if someone could please tell me.. Im sure this is a very nooby question, but everyone is a noob in the beginning.


    ============================================
    class mutHalo extends Mutator;

    function bool CheckReplacement ( Actor other, out byte bSuperRelevant )
    {
    if (xweaponbase(other) != none)
    {
    if(xWeaponBase(other).weapontype == class'ClassicSniperRifle')
    xWeaponBase(other).weapontype = class'HumanSniperRifle';
    else
    return true;
    }
    else if (weaponpickup(other) !=none)
    {
    if (string(other.class) == "xweapons.ClassicSniperRiflePickup")
    ReplaceWith ( other, "Halo.HumanSniperPickup");
    else
    return true;
    }
    else
    return true;

    return false;
    }
    ===========================================

    #2
    Okay, heres the idea. I will walk you through it, you dig through the source code where I say to see it Its complicated, and involves a lot of things, so hold on tight and pay attention.

    Okay, inside Actor.uc there is a variable called bGameRelevant. All actors have this variable. If its set to false, that means that mutators are allowed to modify this actor. Inside Actor.uc, there is an event called PreBeginPlay which is the first event that the engine calls on any actor. This event checks to see if bGameRelevant is false, and if the actor exists on the server (which all actors in a map do), the actor passes itself through the mutator chain with a function called CheckRelevance. This function in turn calls CheckReplacement.

    If CheckReplacement returns true, then CheckRelevance will return true, and the actor (inside PreBeginPlay) will NOT destroy itself. What CheckReplacement is saying is that it has "replaced" or changed the actor in some way, and that it is no longer needed. So when your code returns false, the actor that is passed into the function (Other) gets destroyed. This comes in handy when you want to switch weapons, or vehicles, or a number of other things inside of maps already.

    What the code you pasted is doing is checking Other to see if it is a certain type of actor, and if it is then it changes something in that actor, and returns true, saying dont destroy the actor, but I'm done with it.

    If you are wanting to switch a weapon in a map with yours, you would want to do it the same way, only with your classes, and checking other to see if it is the weapon you want to replace.

    Comment


      #3
      First of all thank you for the well informed reply, its much appreciated . Now... I kinda see what your saying, but am still a little confused as to what I actually do.. I see you say "do it the same way, only with your classes". Well I do have my own class I though, isnt Halo.HumanSniperPickup a class? That switches the original sniper with my new modified one at least.. I dont just copy this whole thing again and paste it again for each weapon right? Is there another IF statement I need to add for each weapon?? Once again, Im very sorry for not completely understanding a very easy question, but Im just trying to learn

      Comment


        #4
        Well, I wasnt sure if the code you posted was yours, or someone elses. If it is indeed yours, then maybe I am misunderstanding your question, heh.

        What it sounds like you are wanting is to replace another weapon with yours? Or replace another weapon with another one of your weapons.

        Well, it can be done of course. You can hard code that (which is what you're doing now, since the only way to change what weapon gets replaced is to recode and recompile), or you can do it another way.

        There is a way using a mutator to have the class which you replace and the class whcih you replace WITH configured via the mutator configuration. I will attempt to explain how this works for you. Its a bit confusing, so I will abstract the setup for you.

        First off, we will be using a function in Mutator class called FillPlayInfo which is called inside of the the game somewhere (I think the PlayInfo class calls it, but I'm not sure). The point is, it gets called for mutators.

        The first thing you need to do here is add a list of classes that are acceptable to replace (such as "UTClassic.ClassicSniperRifle"). These classes can be hard coded or you can build a list of them in the mutator. To do the former, simply create a string such as "UTClassic.ClassicSniperRifle;Classic Sniper Rifle;XWeapons.LinkGun;Link Gun" or whatever classes you want. The alternate way uses a dynamic array of CacheManager.WeaponRecords and calls a static function on the CacheManager class to retrieve an array of weapon classes. This is done in FillPlayInfo() like so:

        Code:
        	local array<CacheManager.WeaponRecord> Recs;
        	local string WeaponOptions ;
        	local int i;
        
        	class'CacheManager'.static.GetWeaponList(Recs);
        	for (i=0;i<Recs.Length;i++)
        	{
        		if (WeaponOptions != "")
        			WeaponOptions $= ";";
        		WeaponOptions $= Recs[i].ClassName $ ";" $ Recs[i].FriendlyName;
        	}
        What this code does is calls GetWeaponList which fills Recs with a list of WeaponRecods, which contain information about weapons. Then we build a string with these classes followed by their readable name (such as "Sniper Rifle", or "Link Gun"). This is the format that the PlayInfo expects, which is why we are doing it like this. This is just for classes to replace, we could do the same with classes to replace WITH, or we could hard code it, or find an easier way to configure that, if we wanted to restrict what weapons can be replaced with.

        Then, all that is left to do is call the function in PlayInfo that adds the option inside the mutator config. This is a basic version using the code above as a base:

        Code:
        PlayInfo.AddSetting(default.RulesGroup, "ReplaceString", default.DisplayText, 0, 1, "Select", WeaponOptions,,,False);
        The function creates a "Select" box (combo box) on the mutator config page, with the options we put in WeaponOptions above. Only some of the parameters should be adjusted. For instance, "ReplaceString" is the actual name of the string variable inside of your mutator class that you want the option the user selects to be placed in to (I think it has to be a string). WeaponOptions is of course the variable above we constructed, or you can use a hard coded string here in its place (however you decide to implement it). The False there means that the option is not an "advanced" option, which only appear when the show advanced obtions check is checked on the mutator config page (making those options able to be hidden).

        You would do the same thing for your ReplaceWithString variable, if you want that to be configurable as well.

        Another function we need is only for tool tips, but is still important.

        Code:
        static event string GetDescriptionText(string PropName)
        {
        	if (PropName == "ReplaceString")
        		return "Select which Weapon to replace";
        
        	return Super.GetDescriptionText(PropName);
        }
        The function above gets called by the tooltip code in the mutator config to get the description for certain variables. It passes in a string representing the variable it is attempting to explain. Since I've only defined one above, I just use that as an example. It will return the description of the variable, or pass the function on as needed.

        Once all that is done, you've got to modify your CheckReplacement code above a little bit. You see, the code i gave you above allows the user to select which class to use, and sets the ReplaceString variable (which is an example variable in your mutator class) to whatever option was selected. But this variable is a string, not a class. So you need to convert it to a class using DLO (DynamicLoadObject) before you do anything in your CheckReplacement. Something like this:

        Code:
        local class<Weapon> ReplaceClass;
        
        ReplaceClass = class<Weapon>(DynamicLoadObject(ReplaceString, class'Class'));
        What the code above is doing is "loading" an object specified by the variable ReplaceString (which is set by the mutator config page) of class 'Class' and "type casting" it to a Weapon class, and placing it in your ReplaceClass variable. You can then use the ReplaceClass in place of your class'ClassicSniperRifle' in your CheckReplacement code above, thus allowing the user to dynamicly select which class to replace.

        You must do something similar for the ReplaceWithClass (if you decide to do it this way).

        So there you have it. Its not easy for n00bs, but its pretty simple code once you get your head around it. There are examples of this being used inside the UT2004 source already, but if anything is still confusing you about where something came from, or how it works, or how it is supposed to fit together, just ask.

        Comment


          #5
          Once again, thank you very much for your very in-depth response and not making fun of a noob like me (which is what i expected). And yes, in a way the code is mine, in that the classes are actually mine..But I essentially just changed the names of the classes from the tutorial on the DVD.. And yea, I have a few weaponclasses I made and just wanted them in the game instead of the normal weapons.

          I will look over what your wrote again (a few times) and see what I can do..But I see that you say theres another way to do it the way Im doing it.. Is that way any easier by any chance? Is there just more code I can write in the mutator to check for more weapons?

          Thank you for your help, it is much appreciated. Im just starting to get into this stuff again (used to work with VB and C++ a lot..), and will be much more into it in the summer when I have free time. And ive been too busy learning mapping too..

          Comment


            #6
            The easier way is to simply hard code the string we created in FillPlayInfo(), but thats not really the "better" way, but its (a little) easier.

            If all you need to do is get your weapon in game so you can test it, you just need to summon it. Bring down the console and type "summon mypackage.myweaponpickup" and it will appear in front of you, heh. Make sure you summon the pickup, or you wont get the weapon.

            Comment


              #7
              Yeah, I actually already know the summon thing :up: .. Like I said, I will read over that stuff, but I also just thought of something else..Say I make a map (im almost done building one..), cant I just place my new weapons in that actual map? (Im almost positive its a yes obviously, but cant hurt to ask.) Thanks for the quick response..

              Comment


                #8
                Yes, you can place the weapons in the map, just like any other weapon. Just select it from the list. If its not in the list, load the .u file from inside the Actor browser, and then try again. It should be in the list then. If its not loaded, it wont appear. It gets loaded by being in your EditPackages list, but be careful as the .u files in that list have to be there for the editor to open, and if you place anything from that package, it will have to be present to play your map.

                Comment


                  #9
                  Okay, yeah I figured that, just wanted to make sure..Well thanks for your help, I will try to do what you said and see how it works out..

                  Comment


                    #10
                    I also have another quick question which im sure is also very easy..kinda off topic of this though..How exactly do you disable the ability to double jump and dodge jump?? I think there is a rule somewhere that is just like a true/false thing, but maybe not..

                    Comment


                      #11
                      You'd use function ModifyPlayer in mutator.

                      Code:
                      function ModifyPlayer(Pawn Other)
                      {
                      	local xPawn P; // need to access xPawn for these vars
                      
                      	P = xPawn(Other);
                      
                      	if (P != None) // make sure the xPawn exists
                      	{
                      		P.MaxMultiJump = 0; // 0 = no double jump
                      		P.MultiJumpRemaining = 0;
                      		P.bCanDodgeDoubleJump = false;
                      	}
                      
                      		Other.JumpZ = Whatever; // Access default variables of class Engine.Pawn here if you want
                      
                      	if (NextMutator != None)
                      		NextMutator.ModifyPlayer(Other);
                      }

                      Comment

                      Working...
                      X