Telling how much damage a projectile did in its Death state?
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
-
- ... in rememberance ...
- Posts: 6109
- Joined: Fri Jul 06, 2007 2:34 pm
Telling how much damage a projectile did in its Death state?
Is there a way for a projectile to figure out how much damage it did to what it hit?
-
- Posts: 269
- Joined: Tue Jan 19, 2010 5:07 pm
Re: Telling how much damage a projectile did in its Death st
Using ZScript.
1) You can use event "WorldThingDamaged" (wiki). This thing is called every time anything got hit and damaged. Inside, you can just check the name of "inflictor" if you want to check what exactly hit, and "damage" to get the damage number.
2) You can override DamageMobj on actors which you want to check. This work in similar way - just check inflictor for name of projectile, and damage for damage.
If you don't know how to make these work, I'll write a simple example for you.
3) I just thought of another method. Not sure if this works though, never tested it. You might use "DamageFunction" instead of "Damage", and inside, you put a function that generates damage and stores it in a variable.
In death state you can check the DamageGen variable. Should have generated by then.
1) You can use event "WorldThingDamaged" (wiki). This thing is called every time anything got hit and damaged. Inside, you can just check the name of "inflictor" if you want to check what exactly hit, and "damage" to get the damage number.
2) You can override DamageMobj on actors which you want to check. This work in similar way - just check inflictor for name of projectile, and damage for damage.
If you don't know how to make these work, I'll write a simple example for you.
3) I just thought of another method. Not sure if this works though, never tested it. You might use "DamageFunction" instead of "Damage", and inside, you put a function that generates damage and stores it in a variable.
Code: Select all
Class MyProjectile : Actor
{
int DamageGen;
Default
{
DamageFunction (SetDamage());
}
(...)
int SetDamage()
{
DamageGen = random(1, 8) * 5;
return DamageGen;
}
}
-
- ... in rememberance ...
- Posts: 6109
- Joined: Fri Jul 06, 2007 2:34 pm
Re: Telling how much damage a projectile did in its Death st
I believe the third method would work, but wouldn't quite work for what I need; in my case I need the damage that was actually dealt, not the damage that it's supposed to deal. In the case that the projectile's supposed to do 40 damage but the victim only had 23 health, I want to store 23 for example.
-
- Posts: 269
- Joined: Tue Jan 19, 2010 5:07 pm
Re: Telling how much damage a projectile did in its Death st
Well then you need to add HITTRACER flag to this. When the projectile hits some actor, it is being assigned to projectile "tracer". So then in this function SetDamage, you can add a checkGhastly wrote:I believe the third method would work, but wouldn't quite work for what I need; in my case I need the damage that was actually dealt, not the damage that it's supposed to deal. In the case that the projectile's supposed to do 40 damage but the victim only had 23 health, I want to store 23 for example.
Code: Select all
if(DamageGen > tracer.Health)
Edit. Only one thing, Im not 100% sure if the "tracer" is being assigned before the DamageFunction is being called. If it's not, then the tracer field will be empty at the time of this check (and that's a crash). But even then, you could just make your own function in death state, that uses DamageMobj on tracer.
-
- ... in rememberance ...
- Posts: 6109
- Joined: Fri Jul 06, 2007 2:34 pm
Re: Telling how much damage a projectile did in its Death st
That also assumes the projectile's put in its Death state in between the tracer pointer being assigned, and before damage is dealt.
This is why you should always if(*pointer*) before using any pointer, by the way.krokots wrote:If it's not, then the tracer field will be empty at the time of this check (and that's a crash).
-
- Posts: 269
- Joined: Tue Jan 19, 2010 5:07 pm
Re: Telling how much damage a projectile did in its Death st
From the source code, the missile first assigns its tracer, next goes to Death state. Thats P_ExplodeMissile. So I think that will work, without using own functions in Death state.Ghastly wrote:That also assumes the projectile's put in its Death state in between the tracer pointer being assigned, and before damage is dealt.
This is why you should always if(*pointer*) before using any pointer, by the way.krokots wrote:If it's not, then the tracer field will be empty at the time of this check (and that's a crash).
BTW what I meant by that, I mean something like this:
Code: Select all
Class MyProjectile : Actor
{
int DamageDealt;
Default
{
DamageFunction 0;
+HITTRACER
}
States
{
Death:
TNT1 A 0 GetDamage;
Stop;
}
void GetDamage()
{
if(tracer)
{
int dam = random(1, 8) * 5;
DamageDealt = tracer.DamageMobj(target, self, dam, 'Normal');
}
}
}
Edit. Meh, turns out that DamageMobj returns just damage, not counting victims health. So you could just check the tracer's health before and after DamageMobj to check that.
-
- ... in rememberance ...
- Posts: 6109
- Joined: Fri Jul 06, 2007 2:34 pm
Re: Telling how much damage a projectile did in its Death st
Ah! Didn't think of making the death state do the damage instead of having the engine do it. I got it working. Thanks!