Calculation of damage with debuffs

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,305
Reaction score
11,732
First Language
English
Primarily Uses
RMVXA
My understanding is that debuffs, like states, are applied after damage has been calculated. However, I'm now wondering if that is actually true.

I have a skill where the actor is healed by the enemy's ATK x 2. It also applies an ATK debuff. For the healing to be worth it, that debuff must happen after the actor gets the heal. However, it doesn't seem to be quite like that.

I have an enemy with an ATK of 30. Healing should, if I am correct, be 60. It never is. With variance set to zero, it is 46, which looks like it's being calculated after the debuff has been applied.

Here is my damage formula:
Code:
a.hp += b.atk*2; b.add_debuff(2,2,); b.atk*2

As you can see, the damage part of the formula is at the end, after the debuff, but that is because the formula has to end with a number. If I end it with the debuff, I get zero damage.

Can anyone enlighten me as to what's going on here?
Thank you.
 

kirbwarrior

Veteran
Veteran
Joined
Nov 13, 2014
Messages
821
Reaction score
556
First Language
English
Primarily Uses
N/A
My understanding is that debuffs, like states, are applied after damage has been calculated.
I didn't know that. I know common events happen after damage, but I thought buffs and states applied right when they were received.

Code:
a.hp += b.atk*2; b.add_debuff(2,2,); b.atk*2
And as such, you're applying the debuff before the damage but after the healing. You could set a temporary variable first;

Code:
c = b.atk*2; a.hp += c; b.add_debuff(2,2,); c

"c" is set up to be the target's attack. In order, it then heals the user for c, applies a debuff, then damages for c.

Mind, that last part makes me pause. It sounds like what you want is to only heal and debuff, not do damage. If that's true, I'd actually make this two different skills;

A - This skill targets the enemy. It gives an invisible state (for simplicity, you can call this state Target and use it for other skills).. It then calls a common event that stores the target's attack into a variable (using Target to 'find' the right enemy), then forces skill B.
B - The user heals equal to the variable, then gives the Target'd enemy a debuff and removes Target. This might need a second common event.

That's without plugins, I'm certain it's much easier with plugins.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,378
Reaction score
1,782
First Language
EN
Primarily Uses
RMMZ
Since the debuff is being added to the target and seems to have fixed duration, I wonder if it might be easier to just add it as a skill effect?
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
165
Reaction score
191
First Language
Danish
Primarily Uses
RMMV
Hmm I just tried to replicate the issue, but when using a skill with your damage formula against an enemy with 30 ATK I did heal for 60 as expected. :rswt
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,305
Reaction score
11,732
First Language
English
Primarily Uses
RMVXA
@Magnus0808 That confirms my logic, so thank you for the test. I'm not at all sure what is causing the difference at my end.

@kirbwarrior I tried your damage formula and that appears to have sorted it out, so thank you very much.

@caethyril I'll keep that in mind for other skills where I want to do something like this. Thank you.
 

kirbwarrior

Veteran
Veteran
Joined
Nov 13, 2014
Messages
821
Reaction score
556
First Language
English
Primarily Uses
N/A
Since the debuff is being added to the target and seems to have fixed duration, I wonder if it might be easier to just add it as a skill effect?
This actually sounds way easier. Since the attack heals the user and damages the target, it could just be a drain spell that does "b.atk * 2" damage, then adds the debuff with effects instead of the damage formula, which should come after the damage.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,305
Reaction score
11,732
First Language
English
Primarily Uses
RMVXA
@kirbwarrior That does indeed sound much more straightforward. I was simply overthinking it. That's what I get for being away from game making for a few months.
Thank you.
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
165
Reaction score
191
First Language
Danish
Primarily Uses
RMMV
Maybe I misunderstod what the skill was supposed to do. I thought it was on purpose that you deal less damage than you heal.
So what your damage formular does is (when the target has 30 ATK):
Heal for 2 * target ATK (60)
Apply ATK debuf to target for 2 rounds (reduces ATK to around 22)
Deal 2 * target ATK (44)

The reason this happens is because the damage formular gets evaluated (basically run as code) where the last statement is returned as the damage value. So the first two statements (Lines before ; ) gets run first in order.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,350
Reaction score
1,371
First Language
Spanish
Primarily Uses
RMVXA
in terms of objects, "b" is always the same object.
if you apply a modifier to "b", and then reference "b", you're referencing "b" + modifier, not "b, the object that is stated in the database"

if there's no separation of references, the program doesn't know that you want to keep them separated.
 

Latest Threads

Latest Posts

Latest Profile Posts

Voting for the second round of the Map Madness Tournament is now live! Vote for your favorite in each matchup! https://forums.rpgmakerweb.com/index.php?forums/map-madness-2021-polls.187/
Just bought the Visustella All Waves bundle... Time to go IN!!
Oh, I was just confirmed I'll be doing small online classes during june - july, on one side I'm nervous and looking forward it, on the other one: I've became the very thing I swore to destroy. :kaodes:
Work starts today at 2pm. I hate jeans, but the dress code says I have to wear them... That's how I discovered I was a plus size. Shopping for my first pair of jeans.
Anyhow, I'll post a new video on TheDazzlingsAreBack as soon as I'm able to.
dEj6ha4.png

WIP :)
Added some cliffs / walls / roofs to the tilesheet and am currently working on roof objects to make them prettier and more variable. And of course, windows and doors that fit to the game's style.
I also adjusted the grass color but i have some issues with my display, so if it looks weird, please let me know :)

Forum statistics

Threads
110,572
Messages
1,054,299
Members
143,685
Latest member
Yatsuzuka_Kou
Top