News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 17th Aug 2003, 11:43 PM   #1
MouldyCheese
Registered User
 
Join Date: Aug. 17th, 2003
Posts: 11
using Timer() and cleanup

Reading the relic source code I tried to make a simple regeneration mutator. Since I don't add anything to the inventory, is there any cleanup required? Also, the Timer function does not seem to be called every second, or at all.
Code:
Class HpRegen extends Mutator;

function PostBeginPlay()
{
  Super.PostBeginPlay();
  Settimer(1.0, true);
}

function Timer() 
{
  if((Owner != None) && Owner.bIsPawn)
  {
    if(Pawn(Owner).Health < 100)
    {
      Pawn(Owner).Health = FMin(100, Pawn(Owner).Health +3);
    }
  }  
  Super.Timer();
}
MouldyCheese is offline   Reply With Quote
Old 18th Aug 2003, 12:06 AM   #2
Dryn
Registered User
 
Join Date: Feb. 20th, 2003
Posts: 128
Urm... The health addition code is correct, but the 'owner' part is completely out of it. (Not sure you can _be_ the 'owner' of a mutator, and even so, it would only be for the owner itself that your effect happens, not all the pawns in the world)

Instead, what you want in your time is a quick search through the level's pawnlist, and running your health addition check on those pawns, without any 'owner' data.

As for super.Timer(), if the superclass has a timer, and its not called on a per tick - second basis, overwriting like that will completely mash compatability: remember, each class gets one timer and one timer only.
Dryn is offline   Reply With Quote
Old 18th Aug 2003, 03:33 AM   #3
Mychaeel
 
Join Date: Oct. 3rd, 2001
Location: Frankfurt/Main, Germany
Posts: 3,829
Quote:
Originally Posted by Dryn
Urm... The health addition code is correct, but the 'owner' part is completely out of it. (Not sure you can _be_ the 'owner' of a mutator, and even so, it would only be for the owner itself that your effect happens, not all the pawns in the world)
Mutators aren't owned by any player.

Quote:
As for super.Timer(), if the superclass has a timer, and its not called on a per tick - second basis, overwriting like that will completely mash compatability: remember, each class gets one timer and one timer only.
No. Each actor (every instance, not every class) has a timer, and one timer only. For that matter, there's no timer used in class Mutator, so making one in a custom subclass isn't a problem.
Mychaeel is offline   Reply With Quote
Old 18th Aug 2003, 12:17 PM   #4
MouldyCheese
Registered User
 
Join Date: Aug. 17th, 2003
Posts: 11
1) Is this what you mean; If I subclass a class that has a Timer() function, and my class will have one too, I should add Super.Timer() in the Timer() function?

Incase anyone is interested, I got the regeneration code to work. I am in the middle of make a window to be able to edit 3 of the variables, but without the window, the mutator still works
Code:
Class HpRegen extends Mutator config(Monkey);

var() globalconfig int HpMax;
var() globalconfig int HpRegenAmount;
var() globalconfig float HpRegenSpeed;

function PostBeginPlay()
{
  Super.PostBeginPlay();
  Settimer(HpRegenSpeed, true);
}

function Timer() 
{
  //AllActors() takes too much time
  local Pawn myPawn;

  for(myPawn = Level.PawnList; myPawn != None; myPawn = myPawn.NextPawn)
  {
    if(myPawn.Health < HpMax)
    {
      myPawn.Health = FMin(HpMax, myPawn.Health+HpRegenAmount);
    }    
  }
  
  Super.Timer();
}

defaultproperties 
{
  HpMax=100
  HpRegenAmount=3
  HpRegenSpeed=1.0
}
2) When I get the menu working, do you think I should add it to the WiKi with, or without the configure menu? (I know there already is a regen and config tutorial, but the regen is for UT2003, and the config doesn't tie it into a mutator)
MouldyCheese is offline   Reply With Quote
Old 18th Aug 2003, 01:40 PM   #5
Mychaeel
 
Join Date: Oct. 3rd, 2001
Location: Frankfurt/Main, Germany
Posts: 3,829
Quote:
Originally Posted by MouldyCheese
If I subclass a class that has a Timer() function, and my class will have one too, I should add Super.Timer() in the Timer() function?
If any superclass of your own class uses a timer, you should neither call SetTimer nor implement Timer without knowing how exactly that class sets and uses the timer.

GameInfo, for example, sets a timer with a one-second interval. In GameInfo subclasses you can overwrite the Timer function without a problem, but you shouldn't change the timer interval or stop the timer, and you absolutely should call Super.Timer lest important parts of the base code stop working (such as the game time or the part of the code that prevents chat spamming).

Last edited by Mychaeel; 18th Aug 2003 at 01:44 PM.
Mychaeel is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:27 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer