Unintended reverse damage

Hi. When I use a physical/magical skill against an enemy who has very high defense/magical defense stat, the target will heal itself instead of taking "null damage". I don't know why it happens tho. It may be a script in particular that I've adopted. But in either case, it kinda sucks. I could go in each damage formula and put conditions to prevent this phenomenon from happening, but I don't think it's efficient.

Is there anyway to prevent this through an additional script?
that shouldn't happen, as there is a way for the engine to make damage always negative and healing always positive.
could you elaborate?
that shouldn't happen, as there is a way for the engine to make damage always negative and healing always positive.
could you elaborate?
Well. One day, I was making custom formulas through "Lunatic Damage" script and testing them. In one of the cases, the enemy used one skill with custom formula and it healed the target. I was like: why is this happening? I immediately understood that the enemy's damage was far below the target's defense stat. I updated the formula and put the following condition: if the damage was below 0, then the target would lose 1 HP. When I did this, the enemy's damage would work properly. If value was "positive", the target would be damaged. If value was "negative", the target would lose 1 HP damage instead of being healed.

This phenomenon would occur in other occasions where the damage value was "below 0", and the target would heal instead of taking null damage.

I don't know if I can elaborate further than this. But feel free to ask anything.
does the same effect happen if you use the regular damage formula, or does it only happen when you use notetags to override the regular damage formula?
does the same effect happen if you use the regular damage formula, or does it only happen when you use notetags to override the regular damage formula?
That's it! The reverse damage only occurs when I'm using the lunatic damage script. If I put the equation on the skill's damage formula box through the dataset, things happen normally. So it must be some problem with yanfly's script, which sucks because I depend a lot on it, since the regular damage formula box on the dataset is very limited on characters...

Does anyone have a guess on how to solve this problem?
That's it! The reverse damage only occurs when I'm using the lunatic damage script. If I put the equation on the skill's damage formula box through the dataset, things happen normally. So it must be some problem with yanfly's script, which sucks because I depend a lot on it, since the regular damage formula box on the dataset is very limited on characters...

Does anyone have a guess on how to solve this problem?
It would help to see the code of the database object.
If you do not believe that is the issue, I would look toward organizing your plugin list if it is not yet organized.
The list on Yanfly's site is exactly how their plugins should be organized in your own projects.
not exactly

it's not a problem, it's a feature....

basically the damage formula and the regular event commands are protected against errors, and that includes the filters protecting against negative values.

but all "lunatic code"-type eval's are intentionally missing that protection, exactly because sometimes you want those effects intentionally.
If you're using lunatic code, you are responsible for keeping the filters there yourself.

the only thing we would help with is checking if there are easier ways to get the same filters if you post the codes you're using

@residntevl no plugins, this is for Ace
not exactly

it's not a problem, it's a feature....

basically the damage formula and the regular event commands are protected against errors, and that includes the filters protecting against negative values.

but all "lunatic code"-type eval's are intentionally missing that protection, exactly because sometimes you want those effects intentionally.
If you're using lunatic code, you are responsible for keeping the filters there yourself.

the only thing we would help with is checking if there are easier ways to get the same filters if you post the codes you're using

@residntevl no plugins, this is for Ace
Ah, my apologies, didn't look at that forum category. Thank you for letting me know. :hswt:
not exactly

it's not a problem, it's a feature....

basically the damage formula and the regular event commands are protected against errors, and that includes the filters protecting against negative values.

but all "lunatic code"-type eval's are intentionally missing that protection, exactly because sometimes you want those effects intentionally.
If you're using lunatic code, you are responsible for keeping the filters there yourself.

the only thing we would help with is checking if there are easier ways to get the same filters if you post the codes you're using

@residntevl no plugins, this is for Ace

Great! Here you go:


Spoiler: Codes
1655667581231.png
some problem with yanfly's script, which sucks because I depend a lot on it
yeah.... both those things tend to happen, together, a lot.

the regular damage formula box on the dataset is very limited on characters
whatever you put in the damage formula can be the result of some other function somewhere else.
if you tell the damage formula to "go look for this expression here" through a call to a module, you can write whatever you want in that module.
and you wouldn't need a whole 3rd party script that must be limited to account for errors.
yeah.... both those things tend to happen, together, a lot.


whatever you put in the damage formula can be the result of some other function somewhere else.
if you tell the damage formula to "go look for this expression here" through a call to a module, you can write whatever you want in that module.
and you wouldn't need a whole 3rd party script that must be limited to account for errors.
Is there a tutorial of how to do it?
Code:
MODULE::CONSTANT

or

MODULE::procedure(param)

in the plugin list, add a new entry:

Code:
module DMG
LargeFixDmg = 999
SmallFixDmg = 1

 def direct_damage(attacker)
   return attacker.atk
 end

 def defended_damage(attacker, defender)
  return attacker.atk - defender.def
 end
end

you can make whatever structure you want.
just remember that there's two parameters passed down implicitly from the object skill or item which are "a" and "b", as used in the damage formula.
if you were to call the second function, that'd be
Code:
DMG::defended_damage(a,b)

procedures are always written lower case while constants must begin with upper case
Code:
MODULE::CONSTANT

or

MODULE::procedure(param)

in the plugin list, add a new entry:

Code:
module DMG
LargeFixDmg = 999
SmallFixDmg = 1

 def direct_damage(attacker)
   return attacker.atk
 end

 def defended_damage(attacker, defender)
  return attacker.atk - defender.def
 end
end

you can make whatever structure you want.
just remember that there's two parameters passed down implicitly from the object skill or item which are "a" and "b", as used in the damage formula.
if you were to call the second function, that'd be
Code:
DMG::defended_damage(a,b)

procedures are always written lower case while constants must begin with upper case
Thank you for sharing your time with me. But since you're talking about plugins, I presume you might not be using Ruby language, is that correct? Because I'm using rmvxace.
Well, nevermind, I found a solution after beating my head against the wall several times. I modified a section of the original Yanfly's script as follows:

Ruby:
      when /FINALIZATION/i
        value *= item_element_rate(user, item)
        value *= pdr if item.physical? && @calc_pdr
        value *= mdr if item.magical? && @calc_mdr
        value *= rec if item.damage.recover?
        value = apply_critical(value) if @result.critical && @calc_cri
        value = apply_variance(value, item.damage.variance) if @calc_var
        value = apply_guard(value) if @calc_guard
        value = 0 if !item.damage.recover? && value < 0

The major differences between Yanfly's code and mine are the conditions that I've added, which are on the last line. First, if the value calculated by the custom formula were below zero (value < 0), then the final value will be recalculated to null. At first glance, this would not work, since it would nullify all healing skills. So I've put an additional condition: it will only be recalculated to zero if the source of the action is not a healing skill (!item.damage.recover?).

I can't believe the solution was simple like that. But considering that I am illiterate at ruby language, it couldn't take less time.

Original thread: https://forums.rpgmakerweb.com/threads/unintended-reverse-damage.148643/