Announcement

Collapse
No announcement yet.

Help with n00b script - Health for Kills

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

    Help with n00b script - Health for Kills

    I'm a n00b learning unrealscript and I'm trying to make a simple mutator for ut2k4 that would give 10 health for each normal kill, and 50 vehicle health for each kill in a vehicle. I keep getting the compile error in the file KillHealthReward.uc, "Unrecognized class member thisMutator in class GameRules." But I've declared thisMutator, so I don't understand why it's giving me the error :/

    I tried this after looking at the BigHead and the regen code. Here are the scripts:

    Code:
    //KillHealthRewardRules.uc
    class KillHealthRewardRules extends GameRules;
    
    var KillHealthReward thisMutator;
    
    function ScoreKill(Controller Killer, Controller Killed)
    {
    	if ( (Killer != None) && (Killer.Pawn != None) )
    	{
    		if ( Vehicle(Killer.Pawn) != None )
    		        Killer.Pawn.Health += 10.000000;
    		else
    			Killer.Pawn.Health += 50.000000;
    	}
    
    	if ( NextGameRules != None )
    		NextGameRules.ScoreKill(Killer,Killed);
    }
    
    defaultproperties
    {
    }
    Code:
    //KillHealthReward.uc
    class KillHealthReward extends Mutator;
    
    function PostBeginPlay()
    {
    	local GameRules G;
    	
    	Super.PostBeginPlay();
    	G = spawn(class'KillHealthRewardRules');
    	G.thisMutator = self;
    	if ( Level.Game.GameRulesModifiers == None )
    		Level.Game.GameRulesModifiers = G;
    	else    
    		Level.Game.GameRulesModifiers.AddGameRules(G);
    }
    
    defaultproperties
    {
         FriendlyName="Kill-Health-Reward"
         Description="Rewards 10 health for every kill, and 50 vehicle health for vehicle kills."
    }
    To compile I put "EditPackages=KillHealthReward" into ut2004.ini and then at the command line typed "ucc make." Both script files are in UT2004/KillHealthReward/Classes.

    Any ideas on what's wrong? :P

    #2
    Re: Help with n00b script - Health for Kills

    Originally posted by dataangel
    local GameRules G;

    Super.PostBeginPlay();
    G = spawn(class'KillHealthRewardRules');
    G.thisMutator = self;
    You need to typecast this GameRules object as your gamerules extension class. Like this:

    local GameRules G;

    Super.PostBeginPlay();
    G = spawn(class'KillHealthRewardRules');
    KillHealthRewardRules(G).thisMutator = self;


    As far as I can tell, this is why you're getting the compile error. I couldn't tell you whether or not this stuff will work since I haven't played around with the GameRules stuff at all.

    Good luck!

    Comment


      #3
      Hey that worked, thanks =)

      I should've made it a KillHealthRewardRules object instead of a GameRules one to begin with. Still getting used to Uscript.

      Comment


        #4
        Alright cool.

        I've been learning Uscript over the last few weeks. The sad truth for me is that I'm having more fun scripting than I am playing the game.

        [EDIT: Don't get me wrong... I LOVE THE GAME! I just love scripting even more.]

        Comment


          #5
          Re: Re: Help with n00b script - Health for Kills

          Originally posted by MayContainNuts
          You need to typecast this GameRules object as your gamerules extension class. Like this:

          local GameRules G;

          Super.PostBeginPlay();
          G = spawn(class'KillHealthRewardRules');
          KillHealthRewardRules(G).thisMutator = self;


          Allow me to hijack this thread for a bit, and ask something slightly off topic.

          What exactly is being done here? I was trying to reverse engineer the big head mutator, and came across this very same thing. I have been unable to find a really good description of what is done, how and why it works etc.

          So any links or elaborations would be greatly appreciated, so I can enhance my understanding.

          Comment


            #6
            Here's my analysis from dissecting it, not sure how accurate this is. First, it creates a new GameRules object. Then, it sets a pointer on the object to itself -- I think this is necessary for the big linked list of GameRules objects to work (more on why that is in a second). Then it does a check, if there are currently no GameRules (a normal UT game has none -- GameRules are added on by mods/mutators) it simply sets the GameRules to be what you just created, or, if there are GameRules already in place, it adds this mutator to the linked list of GameRules. The reason this is important is that the game loops through all the GameRules objects that have been added and applies them individually. This is so that you can have multiple mutators that alter GameRules.

            Although my question would be -- why aren't the GameRules and Mutator classes merged?

            Comment


              #7
              I thought you had to set and USE the variable in the .uc file that the variable is set in, or you'd get an error, (because it wasnt used).??

              Comment


                #8
                Originally posted by RC321
                I thought you had to set and USE the variable in the .uc file that the variable is set in, or you'd get an error, (because it wasnt used).??
                Yes and no. A class variable if not used gives no warning or error because the compiler recognizes that subclasses may use it (I'm not positive that it actually checks to make sure that subclasses do though). It never gives errors for not using variables, only warnings (i.e. you still get a working .u file even though the compiler complains), and only when they're inside some sort of block {}.

                I'm just learning scripting, but I think that info is accurate.

                Comment

                Working...
                X