Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Defense and Magic Defense Ratings = % Reduction

I have to apologize ahead of time as even though I've tinkered with RPG Maker XP for years, I haven't done much in the way of scripting.  As this is my first script request, I hope my I can make everything easy to understand, and I'm sure it's an easy fix for some of you scripting gurus out there.  I'm going off memory here, so this is probably a little off, but the default battle algorithm in XP figures damage dealt by something like this:
     

  (Skill Power * Strength F ÷ 100)
- (Target Pdef * Pdef F ÷ 200)

Lately, I've been wanting the Defense and Magic Defense to have a much greater scaling effect.  I was wondering if there is a way to change the default battle battle algorithms (either by a script or modifying them directly) to make Defense and Magic Defense ratings reduce all damage taken by a *direct percentage*

For example, we have:

Arshes 
       
DF: 500
MDF: 100
Upcoming Damage = 1,000

If the incoming attack is physical, Arshes Defense Rating of 500 translates into 50% physical damage reduction, so he only receives 500 damage from that attack.  But if we say that 1,000 upcoming damage is magical, his 100 MDF rating translates into 10% magical damage reduction, so he only receives 900 damage.  I'm using 1,000 as a perfection reduction rating here, mainly because I use it as a cap for stats in my game.

Would this be a simple change or a major pain?  Is there anyone willing to help me out with this?  Thanks in advance!
 
Very simple change.

Change these two lines in Game_Battler 3:

Code:
atk = [attacker.atk - self.pdef / 2, 0].max
self.damage = atk * (20 + attacker.str) / 20

to

Code:
self.damage = attacker.atk * (20 + attacker.str) / 20
self.damage -= self.damage * (self.pdef / 1000)

and then take this section:

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

to this

Code:
power = skill.power + user.atk * skill.atk_f / 100
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)
self.damage = power * rate / 20
if self.damage >= 0
  if skill.atk_f > 0
    self.damage -= self.damage * (self.pdef / 1000)
  else
    self.damage -= self.damage * (self.mdef / 1000)
  end
end

This also will ignore the effect if the skill has a negative power (heal) so heals aren't negatively modified by mdef.

It also determines if a skill is physical or magical the same way that the default system does, to determine whether or not to apply pdef or mdef.
 
Thank you so much for the quick reply!  But I seem to be having some trouble.

I'm getting the oddest results on this.  When I plug these in, no damage reductions due to defense and magic defense are occurring...unless a character's stats are high enough to prevent *all* of the damage anyway, in which case the defenses are indeed applied.  At first I thought I had two scripts that were conflicting, but I tested this in a blank project and I'm getting the same results.

The way the formula should work is for every 10 points in defense (or magic defense), 1% of the incoming damage would be ignored.  I've tested these defense values at 100 (10% reduction), 500 (50% reduction), and 999 (99.9% reduction), yet all damage goes through anyway.  Would anyone else mind plugging these in real quick to see where I'm going wrong?  I'm sure I must be overlooking something...
 

Atoa

Member

@mercurygerman
I found the error.
in the way it is, it first make the division, but since the value is an Integer, it don't consider decimals

so (500 / 1000) = 0

for physical attack try this
Code:
self.damage = attacker.atk * (20 + attacker.str) / 20
self.damage -= (self.damage * self.pdef) / 1000

But there's somethig that bothers me in the code for skills:
The Damage reduciton don't consider if the skill have both atk_f and int_f.
Even if it have both, the skill consider only the physical def.
And it completely ignore the  skill pdef_f and mdef_f

I think it would be better if it was like this:
Code:
power = skill.power + user.atk * skill.atk_f / 100
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)
self.damage = power * rate / 20
if power > 0
  self.damage -= (self.damage * self.pdef * skill.pdef_f) / 100000
  self.damage -= (self.damage * self.mdef * skill.mdef_f) / 100000
end
 
Nope.  That didn't seem to fix it either.  Here's how I tested.
I set up a skill (we'll call is "slam") to be physical:

SP 0      Power 1000  AT P 0  Evasion 0
Str 100  Dex 0          Agi  0  Int 0
Acc 100  PDef  100    Mdef 0  Variance 0


I set up a monster who would spam Slam over and over against a character
whose defense value I manipulated directly.  Here are my results:

Defense Value of  0    = 1050 Damage    (Should be 1050 due to 0% reduction)
Defense Value of 10    =  525 Damage    (This is 50% damage reduction,when it should be 1% reduction)
Defense Value of 20    =    o Damage    (100% reduction. Is this set to be on a scale of 1000 or 20?)
Defense Value of 50    = 75,075 Healing  (!)

Any ideas?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top