[SOLVED] Calculating the damage an actor would receive

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

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!)
Post Reply
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

[SOLVED] Calculating the damage an actor would receive

Post by Cherno »

Is there a way to calculate the damage an actor would receive, modifed by DamageType, in DamageMobj, before returning Super.DamageMobj()?
The only way I could see it work is to create one specific item per actor, which has the exact same DamageFactors, and then given to the actor. This item could then be accessed in DamageMobj to call it's ModifyDamage or ApplyDamageFactors functions.
Last edited by Cherno on Sat Apr 04, 2020 7:36 pm, edited 1 time in total.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Calculating the effective damage an actor would receive

Post by Apeirogon »

You mean calculate amount of damage actor would receive inside overridden damagemobj? If yes, then

Code: Select all

override int damagemobj(arguments)
{
    int original_damage = super.damagemobj(arguments);
    and virtual still executes, because its not hit return word
}

User avatar
phantombeta
Posts: 2178
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Calculating the effective damage an actor would receive

Post by phantombeta »

As far as I can tell, the OP wants to calculate the damage that would be dealt but without actually dealing it. Your answer does not do that.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Calculating the effective damage an actor would receive

Post by Cherno »

phantombeta wrote:As far as I can tell, the OP wants to calculate the damage that would be dealt but without actually dealing it. Your answer does not do that.
Correct!
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Calculating the effective damage an actor would receive

Post by Apeirogon »

Hmm, I remember I doing something like that and use DamageMobj.
If its not work, there are ApplyDamageFactor function
https://github.com/coelckers/gzdoom/blo ... or.zs#L664
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Calculating the effective damage an actor would receive

Post by Cherno »

AppplyDamageFactor is an Inventory function though, see OP.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Calculating the effective damage an actor would receive

Post by Apeirogon »

Eeeee, no, its an actor function.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Calculating the effective damage an actor would receive

Post by Cherno »

Apeirogon wrote:Eeeee, no, its an actor function.
Sorry, I mistyped. It is indeed an actor function. However, it requires an Inventory class parameter.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Calculating the effective damage an actor would receive

Post by Apeirogon »

What makes you think so?
Its literally directly called in C++ DamageMobj function, to adjust damage by actors matching to damage type factor.
https://github.com/coelckers/gzdoom/blo ... .cpp#L1171
Target there is an actor which are harmed.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Calculating the effective damage an actor would receive

Post by Cherno »

From the wiki:
Returns the value passed to damage after adjustment, which is done by multiplying it with the chosen damage factor from the specified item class
Edit:

You are right again, the function can be called without passing anything but damage and mod. Thanks for the help!
The wiki article doesn't mention this quite important fact.
Post Reply

Return to “Scripting”