How to transfer damage taken from a class to another?
- Azarael
- UT2004 Administrator
- Posts: 5365
- Joined: Thu 11 Feb , 2010 10:52 pm
Re: How to transfer damage taken from a class to another?
Typecast M to DreamsCombineBackup1A using the following code:
DreamsCombineBackup1A(M).FirstMonster = self;
Typecasting tells the compiler to treat a variable which contains a class as if it contained a variable of one of its subclasses. If it's not done, you can only access properties which exist in the class you originally defined the variable as containing. It's up to you to make sure that the variable actually contains a reference to an instance of that class, otherwise you'll get an Accessed None, but it won't be a problem here.
For example:
var Actor A;
I then assign a Pawn to A and try to access the GroundSpeed property, but cannot because the variable A was declared as holding was an Actor. Therefore I must use Pawn(A).GroundSpeed when trying to access a Pawn-specific property.
DreamsCombineBackup1A(M).FirstMonster = self;
Typecasting tells the compiler to treat a variable which contains a class as if it contained a variable of one of its subclasses. If it's not done, you can only access properties which exist in the class you originally defined the variable as containing. It's up to you to make sure that the variable actually contains a reference to an instance of that class, otherwise you'll get an Accessed None, but it won't be a problem here.
For example:
var Actor A;
I then assign a Pawn to A and try to access the GroundSpeed property, but cannot because the variable A was declared as holding was an Actor. Therefore I must use Pawn(A).GroundSpeed when trying to access a Pawn-specific property.
-
- Member
- Posts: 80
- Joined: Thu 29 Sep , 2011 12:26 am
- Contact:
Re: How to transfer damage taken from a class to another?
Azarael wrote:Typecast M to DreamsCombineBackup1A using the following code:
DreamsCombineBackup1A(M).FirstMonster = self;
Typecasting tells the compiler to treat a variable which contains a class as if it contained a variable of one of its subclasses. If it's not done, you can only access properties which exist in the class you originally defined the variable as containing. It's up to you to make sure that the variable actually contains a reference to an instance of that class, otherwise you'll get an Accessed None, but it won't be a problem here.
For example:
var Actor A;
I then assign a Pawn to A and try to access the GroundSpeed property, but cannot because the variable A was declared as holding was an Actor. Therefore I must use Pawn(A).GroundSpeed when trying to access a Pawn-specific property.
:O this is brilliant, this is is basically getting the id of the specific object dreamscombinebackup1a and save it to (M) variable? this is awsome and gives me many possibilities
I will soon post a reply, if not today it means im in bed and will do in a few hours later.
Thanks as usual for the awsome explanation aza
- Azarael
- UT2004 Administrator
- Posts: 5365
- Joined: Thu 11 Feb , 2010 10:52 pm
Re: How to transfer damage taken from a class to another?
No problem.
That's not exactly how typecasting works. When you do Class(Variable) you're just telling the compiler to treat Variable as if it were subclass Class for the duration of that statement. You don't actually modify the variable you typecast. For example:
function AssignSomething(Pawn Other)
{
local Actor A;
A = Other; //assign Pawn Other to variable A which is declared as holding an Actor
A.GroundSpeed = 500; //fails, A is currently being treated as an Actor
Pawn(A).GroundSpeed = 500; //success, A is being treated in this statement as a Pawn
A.AirSpeed = 500; //fails, A isn't changed in any way by the above typecasting, it still holds an Actor
Pawn(A).AirSpeed = 500; //success, A is being treated once again as a Pawn
}
That's not exactly how typecasting works. When you do Class(Variable) you're just telling the compiler to treat Variable as if it were subclass Class for the duration of that statement. You don't actually modify the variable you typecast. For example:
function AssignSomething(Pawn Other)
{
local Actor A;
A = Other; //assign Pawn Other to variable A which is declared as holding an Actor
A.GroundSpeed = 500; //fails, A is currently being treated as an Actor
Pawn(A).GroundSpeed = 500; //success, A is being treated in this statement as a Pawn
A.AirSpeed = 500; //fails, A isn't changed in any way by the above typecasting, it still holds an Actor
Pawn(A).AirSpeed = 500; //success, A is being treated once again as a Pawn
}
-
- Member
- Posts: 80
- Joined: Thu 29 Sep , 2011 12:26 am
- Contact:
Re: How to transfer damage taken from a class to another?
Hey, back again, thx for ur help izumo once more, this is what i have coded, i have tried my best that in all cases if one of them "dies" so will the other in every single possible case including telefrags:
DreamsBossHunter1A
DreamsCombineBackup1A
What do u think? is it good enough?
Oh theres a problem, how can i give damage to the boss when its minion gets destroyed? i need to kill it through damage because some funky things happen in invasion wave end if i simply destroy the boss.
if i type
DreamsBossHunter1A(FirstMonster).TakeDamage(DreamsBossHunter1A(FirstMonster).PawnHealth,instigatedBy,hitlocation,momentum,damageType);
in the minion destroy event i get this error:
C:\UT2004\HL2ML31A\Classes\DreamsCombineBackup1A.uc(22) : Error, Call to 'TakeDamage': bad or missing parameter 2
DreamsBossHunter1A
Code: Select all
simulated function Destroyed()
{
if(DreamsCombineBackup1A(M) != none && DreamsCombineBackup1A(M).PawnHealth>0)
{
DreamsCombineBackup1A(M).FirstMonster = None;
DreamsCombineBackup1A(M).Destroy();
M = none;
}
Super.Destroyed();
}
function TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, class<DamageType> damageType)
{
Super.TakeDamage(Damage,instigatedBy,hitlocation,momentum,damageType);
if(M != none && Health < 1)
{
DreamsCombineBackup1A(M).FirstMonster = None;
DreamsCombineBackup1A(M).TakeDamage(Damage,instigatedBy,hitlocation,momentum,damageType);
M = none;
}
}
Code: Select all
simulated function Destroyed()
{
if (DreamsBossHunter1A(FirstMonster) != none && DreamsBossHunter1A(FirstMonster).PawnHealth > 0)
{
DreamsBossHunter1A(FirstMonster).M = none;
DreamsBossHunter1A(FirstMonster).Destroy();
FirstMonster = none;
}
Super.Destroyed();
}
function TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, class<DamageType> damageType)
{
if (DreamsBossHunter1A(FirstMonster) != none && DreamsBossHunter1A(FirstMonster).PawnHealth > 0)
DreamsBossHunter1A(FirstMonster).TakeDamage(Damage,instigatedBy,hitlocation,momentum,damageType);
else
{
DreamsBossHunter1A(FirstMonster).M = none;
FirstMonster = none;
Super.TakeDamage(Health,instigatedBy,hitlocation,momentum,damageType);
}
}
What do u think? is it good enough?
Oh theres a problem, how can i give damage to the boss when its minion gets destroyed? i need to kill it through damage because some funky things happen in invasion wave end if i simply destroy the boss.
if i type
DreamsBossHunter1A(FirstMonster).TakeDamage(DreamsBossHunter1A(FirstMonster).PawnHealth,instigatedBy,hitlocation,momentum,damageType);
in the minion destroy event i get this error:
C:\UT2004\HL2ML31A\Classes\DreamsCombineBackup1A.uc(22) : Error, Call to 'TakeDamage': bad or missing parameter 2
- Azarael
- UT2004 Administrator
- Posts: 5365
- Joined: Thu 11 Feb , 2010 10:52 pm
Re: How to transfer damage taken from a class to another?
Set the second parameter to be the boss. Remember you're calling this function alone, and not as a superclass function within itself. You'll need to add values instead of using hitlocation, instigatedby, etc. Make some up.
-
- Member
- Posts: 80
- Joined: Thu 29 Sep , 2011 12:26 am
- Contact:
Re: How to transfer damage taken from a class to another?
ah ic, well i dont know what to type in momentum, if i type a number it says missmatch :SAzarael wrote:Set the second parameter to be the boss. Remember you're calling this function alone, and not as a superclass function within itself. You'll need to add values instead of using hitlocation, instigatedby, etc. Make some up.
this is what i have so far:
DreamsBossHunter1A(FirstMonster).TakeDamage(DreamsBossHunter1A(FirstMonster).PawnHealth,self,DreamsBossHunter1A(FirstMonster).Location,momentum,XWeapons.DamTypeLinkPlasma);
isnt momentum the value that knocks enemies off? like shock balls knocking off a hellbender for example?
- Azarael
- UT2004 Administrator
- Posts: 5365
- Joined: Thu 11 Feb , 2010 10:52 pm
Re: How to transfer damage taken from a class to another?
Momentum takes a vector, because it's directional. Use vect(0,0,0) if you want no momentum to be applied.
class'DamTypeLinkPlasma' is the required entry for the damagetype.
class'DamTypeLinkPlasma' is the required entry for the damagetype.
-
- Member
- Posts: 80
- Joined: Thu 29 Sep , 2011 12:26 am
- Contact:
Re: How to transfer damage taken from a class to another?
Azarael wrote:Momentum takes a vector, because it's directional. Use vect(0,0,0) if you want no momentum to be applied.
class'DamTypeLinkPlasma' is the required entry for the damagetype.
Thank you very much aza, its working like a charm both offline and online!
Again thanks alot for your help on this matter and for the explanations
- Azarael
- UT2004 Administrator
- Posts: 5365
- Joined: Thu 11 Feb , 2010 10:52 pm
Re: How to transfer damage taken from a class to another?
Any time. Holla back if you need any more help.
Who is online
Users browsing this forum: No registered users and 6 guests