![]() |
|
|
#1 |
|
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();
}
|
|
|
|
|
|
#2 |
|
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. |
|
|
|
|
|
#3 | ||
|
Join Date: Oct. 3rd, 2001
Location: Frankfurt/Main, Germany
Posts: 3,829
|
Quote:
Quote:
|
||
|
|
|
|
|
#4 |
|
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
}
|
|
|
|
|
|
#5 | |
|
Join Date: Oct. 3rd, 2001
Location: Frankfurt/Main, Germany
Posts: 3,829
|
Quote:
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. |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|