My favorite part of the newer RPG Makers like XP and VX is access to the gritty depths of game mechanics. In previous iterations all you could do was live with the decisions of others of how much character attributes mattered, how they scaled, and their relation to each other. The best you could do was look at the elusive damage formula you could never change and had to work around. The worst was put in numbers and hope it worked out well enough.
Working around the damage algorithms was my only option back in the days of
Demon's Gate. Due to the RM2k3 damage algorithms trying to do what I wanted, like making the Spirit/Intelligence stat worth a damn and big damage values, came down to manipulating the battle algorithm. Everything needed an element and every element had multipliers attached to them. This gave the big numbers I wanted and it helped make the Spirit stat marginally more useful if I reduced the base damage of a skill to a low value and jacked up the Spirit influence. Even then there were plenty of issues with the numbers being thrown around, especially how little effect defense had on reducing damage.
But now no more! Thanks to RMVX I can pop in and just change the damage algorithm to a function I like. When I was coming up with a new damage algorithm I had some goals of what I wanted out of it:
1) A unified damage algorithm. In RM2k3 there are two different algorithms: One for regular attacks and one for skills. I wanted to combine the two into a single function that would be used for both attacks and skills. This puts attacks and skills on an even ground, everything is easier to balance,
and it's more intuitive for players. If a skill does "Damage = Attack", then it should do the same amount of damage as a regular attack dang nabbit!
2) Stat dependent damage. The biggest factor in determining the effectiveness of an attack are the stats of the attacker and the target. Replicating this in Rm2k3 was aggravating at best (although part of the issue could be lack of understanding the algorithm but now I can just make my own!) but now most skills are a function of the user's stats.
3) Noticeable effect of changing attack/defense/spirit. I want the player to notice an improvement and have an idea of the results from increasing stats. The best way to do this was a linear function: Increasing your attack
X points will increase your damage output by
X*Y points for a given
Y.
4) Never hit zero damage. If a combatant has excellent defense I still want them to take a non-trivial amount of damage that increases with higher attack/defense.
The first two goals are simple to implement. Goal #1 is simply use the same damage function in both methods that calculate attack and skill damage. Goal #2 just means having the attacking and defending stats being the biggest factors in the damage function. Goal #3 and Goal #4 are a bit incompatible: A linear function can't have a horizontal asymptote which is used to keep damage from hitting zero. I was stumped for a bit but I did come up with a damage function that could satisfy these goals.
brace yourselves
(or text version)
Damage = Max( 2 * (Attacker.atk - Target.def), Attacker.atk^2 / (2 * (Attacker.atk + Target.def) ) )
(I need to learn how to write with tablets)
My solution: I have
two damage functions! This isn't the full algorithm; I didn't include common parts of the algorithm like elemental multipliers, conditionals which I'll cover later, and some other minor parts of the algorithm. Atk and Def refer to the appropriate stats, like Spirit for spirit-using attack skills or plain Attack/Defense for regular attacks or attack driven skills.
The two damage functions lets me have my cake and pretend to eat it too. The first is the linear function I wanted in Goal #3: A point of attack increases damage by two points and likewise a point of defense reduces damage by two points. The algorithm never gets out of hand due to its degree too. This algorithm heavily favors having a high attacking stat: At equal attack and defense the function is a flat out zero. For this function to return good damage values the attacker needs to beat the target's defense and then some. There's an obvious bias for high attack stats, especially regarding Spirit which covers both attack and defense which I may have to address later.
The second function is for when attack and defense are about equal. It's a diminishing returns curve for defense: Pumping even more defense into this function will reduce damage less and less by each additional point. This is for Goal #4 so combatants can still do damage when their attacking stat can't break the target's defense stat. This function also increases with higher values. Parity between attack and defense give different results based on the input values so damage numbers will always be going up even if you can't beat the target's defense to get to the other damage function.
Assuming Attack = Defense (otherwise the differential becomes a pain), the second function simplifies to:
So the rate of change is:
As long as the attacker can keep up with the defender they'll always see an increase in damage as the attacker grows. If the attack and defense stats are equal the base damage is a quarter of the attacker. There's no stagnation with this setup. The only issue I have with it is the dual damage functions hurt the "what will this +2 attack upgrade give me?" since the answer is "It depends! (but probably +4 damage)". A sudden change in damage growth as a character shifts from one function to the other can be unsettling or confusing. I'll have to see how it turns out but I'm not too worried.
For reference, the magic number that switches between damage algorithms is when Attack > 1.15 * Defense. (or 2 / 3^0.5 for exact values)
unless I screwed up my math
Finally, here's a graph that plots the base damage to an enemy that has 50 defense to show how damage output grows over attack growth. The controlled variable is attack and the result is base damage. The blue graph is the linear function and the red is that terrible second function. The game will always use the higher of the two functions.

I also changed how critical hits and defending works. Usually both just change the output of the damage algorithm. I flipped it around and made both change the inputs into the damage algorithm. A critical hit will now multiply the attacker's attacking stat while defending will double the defender's defense stat. This is because of the dual-damage-function nature of Altima's damage algorithms. A critical hit using the second damage function that doubles the damage output won't give as much as increasing the attack to (hopefully) shift to the linear damage function which gives much better returns. The same applies to defense: If your defense increase shifts the damage function to go from the linear to the second damage function the damage will be reduced more than simply cutting the linear function's result by half.
One nice result of the linear function means that if the damage function doesn't change across a crit/guard it will still produce the same effect as all other crits/guards: Double/Half damage. Now if the algorithm stays in the second function, well, a crit/guard won't change much. Dat's dem breaks.
This is dumb and wrong. The normal flat x2 damage bonus from a crit means the target's defense gets doubled too. A x2 to the attacking stat doesn't affect the target's defense and therefore gives an even
bigger damage bonus on crit. Every +2 damage you get from each +1 attack becomes +4 instead.
Last change: Might Guard now has a 50% chance of negating received damage when guarding instead of further reducing damage. Why?
because
Finally a script snippet to show how I made the changes. The code is just for a physical attack: The skill algorithm is a bit bigger due to also having to handle healing. If you want to change or create your own damage algorithms in RPG Maker VX you can find the algorithms in the
Game_Battler class under the
make_attack_damage_value and
make_obj_damage_value methods. You can use the original algorithms as a framework and to make sure you're covering all circumstances like when the target is defending.
class Game_Battler
# ----------------------------------------------
# New Physical Attack Algorithm
def make_attack_damage_value(attacker)
# If the target is guarding and has super guard, randomly reduce damage to 0
if guarding? and super_guard and rand(2) > 0
@hp_damage = 0
return
end
enemy_atk = attacker.atk
# Crit check: A crit doubles attacking power, not resulting damage
# If the defender is vulnerable to critical hits
unless prevent_critical
# Appliy critical multiplier if the attack was a critical hit
@critical = rand(100) < attacker.cri
enemy_atk *= attacker.crit_multiplier if @critical
end
# If the target is defending, modify their defense
target_def *= 2 if guarding?
# First damage calculation
damage_a = 2 * (enemy_atk - target_def) # For when atk > def by some
damage_b = (enemy_atk ** 2) / (2 * (enemy_atk + target_def) ) # Otherwise
# Pick the larger of the two damage values
damage = [damage_a, damage_b].max
# If no damage was applied, set it to one
damage = 1 if damage < 1
# Apply elemental multiplier
damage = (damage * elements_max_rate(attacker.element_set)) / 100
# Apply damage variance and set the damage received
damage = apply_variance(damage, 20)
@hp_damage = damage
end
end