XP Damage Formula editing gone wrong

I'm trying to do the following:
PDEF and MDEF can only max out at 85 and they decrease damage by a percentage rather the default direct subtraction.

STR partially ignores armor (is currently 20% of your Str)

Physical and Magical defense does not affect healing spells

For some reason, I keep getting 0 as final damage even if I max all stats to 999 and PDEF/MDEF at 0 while making all the "_f" at 100 (except pdef_f and mdef_f). Even when I changed "power / 25" to just "power," it still ended up being 0. Can someone help me because I've been editing the damage formula, and its been a nightmare? I'm fine with someone re-editing this or just leading me to a whole new script that makes it easier.

The default damage formula is this:

Code:
 power = skill.power + user.atk * skill.atk_f / 100
      if power > 0
        power -= self.pdef * skill.pdef_f / 200
        power -= self.mdef * skill.mdef_f / 200
        power = [power, 0].max
      end
      # Calculate rate
      rate = 20
      rate += (user.str * skill.str_f / 100)
      rate += (user.dex * skill.dex_f / 100)
      rate += (user.agi * skill.agi_f / 100)
      rate += (user.int * skill.int_f / 100)
      # Calculate basic damage
      self.damage = power * rate / 20

This is what I have:
Code:
power = skill.power
      #Damage spells
    if skill.power > 1
        rate = 25
        rate += user.str * skill.str_f / 100
        rate += user.dex * skill.dex_f / 100
        rate += user.agi * skill.agi_f / 100
        rate += user.int * skill.int_f / 100
        rate += user.atk * skill.atk_f / 100
        power *= rate
        if self.pdef > 85
          rate = self.pdef - 85
        else
          rate = 0
        end
        power *= (100 - (self.pdef - rate - user.str / 5)) / 100 * skill.pdef_f / 100
        if self.mdef > 85
          rate = self.mdef - 85
        else
          rate = 0
        end
        power *= (100 - (self.mdef - rate)) / 100 * skill.mdef_f / 100
        self.damage = power / 25
      end
    #For healing
    if skill.power <= 0
        rate = 25
        rate += user.str * skill.str_f / 100
        rate += user.dex * skill.dex_f / 100
        rate += user.agi * skill.agi_f / 100
        rate += user.int * skill.int_f / 100
        rate += user.atk * skill.atk_f / 100
        power *= rate
        self.damage = power / 25
    end

I've moved this thread to RGSS Support. Thank you.

I've moved this thread to RGSS Support. Thank you.



Edit: ninja'd
Here's a couple of things for you to check. These suggestions may come off as me being condescending but I can't tell you how many times I've overlooked something simple, so it pays to be thorough.

-The code you're editing only applies to skills. Are you experiencing this problem with skills or something else?
-Is the power of the skill set to 0? Zero times anything is still zero, and all you do in your code is multiply power with other things.
-Is the power of the skill 1? If it is, you'll never trigger your own code since the first check looks for it to be greater than 1 and the second looks for it to be equal to or less than zero. Since your code isn't run, damage won't be set and it defaults to 0.
-You can perform some poor man's debugging by adding "print X" statements in your code to check that the values of the variables are what you expect. For example, "print rate" will let you check that all the math you did on rate worked out how you expected. If you think the value should be 100 but it's actually 50 that can help narrow your search for what you did wrong.
Problem is only with skills and I'm aware it only affects skills and not your normal attack

Power is 15

I found the reason for the 0. If p.def_f or if m.def_f is 0, the damage becomes 0 since the damage deduction is multiplied rather than subtracted. Therefore, all I had to do was check to see if p.def_f and m.def_f is greater than 0 which I did here:


Code:
# Calculate power
     power = skill.power
      #Damage spells
    if skill.power > 1
        rate = 25
        rate += user.str * skill.str_f / 100
        rate += user.dex * skill.dex_f / 100
        rate += user.agi * skill.agi_f / 100
        rate += user.int * skill.int_f / 100
        rate += user.atk * 1.25 * skill.atk_f / 100
        power *= rate
       
        #Checks if Physical Defense > 85
        if self.pdef > 85
          rate = self.pdef - 85
        else
          rate = 0
        end
       
        #Checks if Physical Defense Multiplier > 0
        if skill.pdef_f > 0
          power *= (100 - (self.pdef - rate - user.str / 5)) / 100 * skill.pdef_f / 100
        end
       
        #Checks if Magical Defense > 85
        if self.mdef > 85
          rate = self.mdef - 85
        else
          rate = 0
        end
       
        #Checks if Magical Defense Multiplier is > 0
        if skill.mdef_f > 0
          power *= (100 - (self.mdef - rate)) / 100 * skill.mdef_f / 100
        end
        self.damage = power / 25
      end

    #For healing
    if skill.power < 1
        rate = 25
        rate += user.str * skill.str_f / 100
        rate += user.dex * skill.dex_f / 100
        rate += user.agi * skill.agi_f / 100
        rate += user.int * skill.int_f / 100
        rate += user.atk * skill.atk_f / 100
        power *= rate
        self.damage = power / 25
    end

And thankfully, this formula works. I just have to change the normal attack formula to be something similar which I will do later.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/xp-damage-formula-editing-gone-wrong.95761/