I am trying to make a weapon that deals less damage at close range versus longer ranges instead of the other way around, but I can't quite figure out how to implement it.
I'm only able to find a method for making a weapon do less damage as the distance gets further away but not the other way around. My current idea is for a weapon that has an inverted damage falloff where for the first 256 or so map units it deals low damage but beyond that distance it deals medium-to-high damage.
Inverse damage falloff?
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!)
Re: Inverse damage falloff?
If ZScript is an option, i do have a potential solution for this. I believe the weapon you'd like to make is a hitscan weapon, since for projectiles it is far easier to do:
Just add this following piece of code into the weapon code:
This piece of code simply doubles the damage if the distance between shooter and the target is more than 256 units, you'll need to adjust it to your own use case of course.
Just add this following piece of code into the weapon code:
Code: Select all
override void ModifyDamage (int damage, Name damageType, out int newdamage, bool passive, Actor inflictor, Actor source, int flags)
{
if (passive)
return;
int Length = Owner.Distance3D(source);
if (Length > 256.0)
{
newdamage = damage *2;
}
}
Re: Inverse damage falloff?
I was hoping for something that works in DECORATE and I forgot to mention it in my post since I am working with Zandronum. Thanks for the code though! I guess I can repurpose the logic if I ever come up with a solution.
At the moment I'm considering changing the pistol's hitscan attack to a FastProjectile instead since you mentioned that it's far easier with projectiles.
At the moment I'm considering changing the pistol's hitscan attack to a FastProjectile instead since you mentioned that it's far easier with projectiles.
Re: Inverse damage falloff?
Zandronum, eh?
Well, first thing first: you will need to use [wiki=Puff]+PUFFGETSOWNER[/wiki]. That means your hitscan attack will know who shot it. You'll also need PUFFONACTORS and HITTRACER.
From there, you can run a script with [wiki]ACS_ExecuteAlways[/wiki], or [wiki]CallACS[/wiki] if Zandy supports named scripts. You can also use [wiki]GetDistance[/wiki] as one of the parameters, that'll give you the distance between the puff and its target -- meaning between the victim and its shooter.
In that ACS script, since you have the distance, you can compute damage however you want it to be. Multiply damage by distance, or even by distance squared; scale by some factor; clamp with a min and a max; whatever.
The last step is to actually inflict damage. To do that, first you'll change the script's activator to be the victim. Remember that since we used HITTRACER, the victim is in the tracer pointer. So we use [wiki]SetActivator[/wiki] with AAPTR_TRACER. And now that the activator is the victim, it can damage itself with [wiki]DamageThing[/wiki].
Well, first thing first: you will need to use [wiki=Puff]+PUFFGETSOWNER[/wiki]. That means your hitscan attack will know who shot it. You'll also need PUFFONACTORS and HITTRACER.
From there, you can run a script with [wiki]ACS_ExecuteAlways[/wiki], or [wiki]CallACS[/wiki] if Zandy supports named scripts. You can also use [wiki]GetDistance[/wiki] as one of the parameters, that'll give you the distance between the puff and its target -- meaning between the victim and its shooter.
In that ACS script, since you have the distance, you can compute damage however you want it to be. Multiply damage by distance, or even by distance squared; scale by some factor; clamp with a min and a max; whatever.
The last step is to actually inflict damage. To do that, first you'll change the script's activator to be the victim. Remember that since we used HITTRACER, the victim is in the tracer pointer. So we use [wiki]SetActivator[/wiki] with AAPTR_TRACER. And now that the activator is the victim, it can damage itself with [wiki]DamageThing[/wiki].