SephirothSpawn
Sponsor
Information :
This tutorial is designed to explain how all stats and all actions are calculated in rmxp. We will be looking directly at code, where to find it, and explaining how each line acts to figure out our values. Feel free to request any formulas missing, or add your own.
--------------------------------------------------Battler Stats :
Maximum HP
Found in : Game_Battler 1
Method name : maxhp
Calculation : See Basic Explanation A
Maximum SP
Found in : Game_Battler 1
Method name : maxsp
Calculation : See Basic Explanation A
Strength (STR)
Found in : Game_Battler 1
Method name : str
Calculation : See Basic Explanation A
Dexterity (DEX)
Found in : Game_Battler 1
Method name : dex
Calculation : See Basic Explanation A
Agility (AGI)
Found in : Game_Battler 1
Method name : agi
Calculation : See Basic Explanation A
Intelligence (INT)
Found in : Game_Battler 1
Method name : int
Calculation : See Basic Explanation A
Attack Power
Found in : Game_Battler 1
Method name : atk
Calculation : See Basic Explanation B
Physical Defense Power
Found in : Game_Battler 1
Method name : pdef
Calculation : See Basic Explanation B
Magic Defense Power
Found in : Game_Battler 1
Method name : mdef
Calculation : See Basic Explanation B
Evasion Correction
Found in : Game_Battler 1
Method name : eva
Calculation : See Basic Explanation B*
Hit Rate
Found in : Game_Battler 1
Method name : hit
Calculation : We start with a base value of 100. We then pass through every state our battler has, and multiple our base value by our state rate percent.
Found in : Game_Battler 1
Method name : maxhp
Calculation : See Basic Explanation A
Maximum SP
Found in : Game_Battler 1
Method name : maxsp
Calculation : See Basic Explanation A
Strength (STR)
Found in : Game_Battler 1
Method name : str
Calculation : See Basic Explanation A
Dexterity (DEX)
Found in : Game_Battler 1
Method name : dex
Calculation : See Basic Explanation A
Agility (AGI)
Found in : Game_Battler 1
Method name : agi
Calculation : See Basic Explanation A
Intelligence (INT)
Found in : Game_Battler 1
Method name : int
Calculation : See Basic Explanation A
Attack Power
Found in : Game_Battler 1
Method name : atk
Calculation : See Basic Explanation B
Physical Defense Power
Found in : Game_Battler 1
Method name : pdef
Calculation : See Basic Explanation B
Magic Defense Power
Found in : Game_Battler 1
Method name : mdef
Calculation : See Basic Explanation B
Evasion Correction
Found in : Game_Battler 1
Method name : eva
Calculation : See Basic Explanation B*
Hit Rate
Found in : Game_Battler 1
Method name : hit
Calculation : We start with a base value of 100. We then pass through every state our battler has, and multiple our base value by our state rate percent.
Actor Stats :
Maximum HP
Found in : Game_Actor
Method name : maxhp
Calculation : The calculation is the same as in Game_Battler, except the max value changes from 999,999 to 9,999.
Base Maximum HP
Found in : Game_Actor
Method name : base_maxhp
Calculation : This value is determined by the value you set in the Actors tab of the database.
Base Maximum SP
Found in : Game_Actor
Method name : base_maxsp
Calculation : This value is determined by the value you set in the Actors tab of the database.
Base Strength
Found in : Game_Actor
Method name : base_str
Calculation : See Basic Explanation C.
Base Dexterity
Found in : Game_Actor
Method name : base_dex
Calculation : See Basic Explanation C.
Base Agility
Found in : Game_Actor
Method name : base_agi
Calculation : See Basic Explanation C.
Base Intelligence
Found in : Game_Actor
Method name : base_int
Calculation : See Basic Explanation C.
Basic Attack Power
Found in : Game_Actor
Method name : base_atk
Calculation : We use the weapon attack power value of our equipped weapon. If we have no weapon equipped, this value is 0.
Base Physical Defense
Found in : Game_Actor
Method name : base_pdef
Calculation : See Basic Explanation D.
Base Magic Defense
Found in : Game_Actor
Method name : base_mdef
Calculation : See Basic Explanation D.
Base Evasion Correction
Found in : Game_Actor
Method name : base_eva
Calculation : See Basic Explanation D*.
Found in : Game_Actor
Method name : maxhp
Calculation : The calculation is the same as in Game_Battler, except the max value changes from 999,999 to 9,999.
Base Maximum HP
Found in : Game_Actor
Method name : base_maxhp
Calculation : This value is determined by the value you set in the Actors tab of the database.
Base Maximum SP
Found in : Game_Actor
Method name : base_maxsp
Calculation : This value is determined by the value you set in the Actors tab of the database.
Base Strength
Found in : Game_Actor
Method name : base_str
Calculation : See Basic Explanation C.
Base Dexterity
Found in : Game_Actor
Method name : base_dex
Calculation : See Basic Explanation C.
Base Agility
Found in : Game_Actor
Method name : base_agi
Calculation : See Basic Explanation C.
Base Intelligence
Found in : Game_Actor
Method name : base_int
Calculation : See Basic Explanation C.
Basic Attack Power
Found in : Game_Actor
Method name : base_atk
Calculation : We use the weapon attack power value of our equipped weapon. If we have no weapon equipped, this value is 0.
Base Physical Defense
Found in : Game_Actor
Method name : base_pdef
Calculation : See Basic Explanation D.
Base Magic Defense
Found in : Game_Actor
Method name : base_mdef
Calculation : See Basic Explanation D.
Base Evasion Correction
Found in : Game_Actor
Method name : base_eva
Calculation : See Basic Explanation D*.
Enemy Stats :
Base Maximum HP
Found in : Game_Enemy
Method name : base_maxhp
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Maximum SP
Found in : Game_Enemy
Method name : base_maxsp
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Strength
Found in : Game_Enemy
Method name : base_str
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Dexterity
Found in : Game_Enemy
Method name : base_dex
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Agility
Found in : Game_Enemy
Method name : base_agi
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Intelligence
Found in : Game_Enemy
Method name : base_int
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Basic Attack Power
Found in : Game_Enemy
Method name : base_atk
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Physical Defense
Found in : Game_Enemy
Method name : base_pdef
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Magic Defense
Found in : Game_Enemy
Method name : base_mdef
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Evasion Correction
Found in : Game_Enemy
Method name : base_eva
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Found in : Game_Enemy
Method name : base_maxhp
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Maximum SP
Found in : Game_Enemy
Method name : base_maxsp
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Strength
Found in : Game_Enemy
Method name : base_str
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Dexterity
Found in : Game_Enemy
Method name : base_dex
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Agility
Found in : Game_Enemy
Method name : base_agi
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Intelligence
Found in : Game_Enemy
Method name : base_int
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Basic Attack Power
Found in : Game_Enemy
Method name : base_atk
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Physical Defense
Found in : Game_Enemy
Method name : base_pdef
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Magic Defense
Found in : Game_Enemy
Method name : base_mdef
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Base Evasion Correction
Found in : Game_Enemy
Method name : base_eva
Calculation : This value is determined by the value you set in the Enemies tab of the database.
Action Formulas :
Determine Action Speed
Normal Attack Effects
Skill Effects
Item Effects
Slip Damage Effects
Found in : Game_Battler 1
Method name : make_action_speed
Calculation : We use the following code:
We start with our agi value and dividing it by 4. We add 10 to that value, and choose a random number between 0 and our value. We then add agi to this value for our new action speed.
Method name : make_action_speed
Calculation : We use the following code:
Code:
agi + rand(10 + agi / 4)
Normal Attack Effects
Found in : Game_Battler 3
Method name : attack_effect
Calculation : We use the following code:
In this formula, self is the person being attacked and attacker is the person doing the attacking.
From the beginning, we clear the critical flag (responsible for showing "Critical" when damage is being displayed). After this, we determine whether an attack will be successful or not, by picking a random number between 0 and 100. If this number is less than our attackers hit rate, we set a hit_result flag to true, otherwise false.
If our hit_result is true, we start with a atk value determined by the attackers atk value, minus the defenders physical defense divided by 2. We then make this value at least 0. We take this value and multiple it by 20 plus our attacker's strength value. Then divide by 20. We set this value to our defenders damage value.
We multiple our damage by our elemental correction value of our attackers attack element set. Then divide our damage by 100.
If our damage is greater than 0, we will attempt to make this a critical hit or not. If a random number between 0 and 100 is less than the attacker's dexterity, divided by our defenders agility multipled by 4, a critical hit occurs. The damage is multipled by 2 and we set our critical flag to true.
If our defender is defending, our damage is divided by 2.
After this, we randomize our damage value a little bit, but only if the damage is not equal to 0. We start, by taking the absolute value of our damage value, multiple it by 15 and divide it by 100. We then make sure this value is at least equal to 1. We will call this new value amp. We add a random number between 0 and our (amp + 1) twice and then subtract our amp value.
Now, we will try to see if our defender cannot evade the attack. We will take 8 times the defenders agi value and divide it by our attackers dex value, then add our defenders evasion value. We set this value to eva. Now if our damage is less than 0, we set a hit value to 100, otherwise, we set a hit value to 100 minus our eva value. If our defender can't evade, we then set our hit value to 100. Then we pick another random number between 0 and 100, and if it is less than our hit value, we set another hit_result value to true, otherwise false.
If hit_result is true again, we remove states that are removed when our defender is hit. We then subtract our damage value from the defenders hp and add our attackers attack element set and subtract our attackers minus element set.
If hit_result is false, we set our damage to "Miss" and clear or critical flag again.
Method name : attack_effect
Calculation : We use the following code:
Code:
#--------------------------------------------------------------------------
# * Applying Normal Attack Effects
# attacker : battler
#--------------------------------------------------------------------------
def attack_effect(attacker)
# Clear critical flag
self.critical = false
# First hit detection
hit_result = (rand(100) < attacker.hit)
# If hit occurs
if hit_result == true
# Calculate basic damage
atk = [attacker.atk - self.pdef / 2, 0].max
self.damage = atk * (20 + attacker.str) / 20
# Element correction
self.damage *= elements_correct(attacker.element_set)
self.damage /= 100
# If damage value is strictly positive
if self.damage > 0
# Critical correction
if rand(100) < 4 * attacker.dex / self.agi
self.damage *= 2
self.critical = true
end
# Guard correction
if self.guarding?
self.damage /= 2
end
end
# Dispersion
if self.damage.abs > 0
amp = [self.damage.abs * 15 / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
# Second hit detection
eva = 8 * self.agi / attacker.dex + self.eva
hit = self.damage < 0 ? 100 : 100 - eva
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
end
# If hit occurs
if hit_result == true
# State Removed by Shock
remove_states_shock
# Substract damage from HP
self.hp -= self.damage
# State change
@state_changed = false
states_plus(attacker.plus_state_set)
states_minus(attacker.minus_state_set)
# When missing
else
# Set damage to "Miss"
self.damage = "Miss"
# Clear critical flag
self.critical = false
end
# End Method
return true
end
From the beginning, we clear the critical flag (responsible for showing "Critical" when damage is being displayed). After this, we determine whether an attack will be successful or not, by picking a random number between 0 and 100. If this number is less than our attackers hit rate, we set a hit_result flag to true, otherwise false.
If our hit_result is true, we start with a atk value determined by the attackers atk value, minus the defenders physical defense divided by 2. We then make this value at least 0. We take this value and multiple it by 20 plus our attacker's strength value. Then divide by 20. We set this value to our defenders damage value.
We multiple our damage by our elemental correction value of our attackers attack element set. Then divide our damage by 100.
If our damage is greater than 0, we will attempt to make this a critical hit or not. If a random number between 0 and 100 is less than the attacker's dexterity, divided by our defenders agility multipled by 4, a critical hit occurs. The damage is multipled by 2 and we set our critical flag to true.
If our defender is defending, our damage is divided by 2.
After this, we randomize our damage value a little bit, but only if the damage is not equal to 0. We start, by taking the absolute value of our damage value, multiple it by 15 and divide it by 100. We then make sure this value is at least equal to 1. We will call this new value amp. We add a random number between 0 and our (amp + 1) twice and then subtract our amp value.
Now, we will try to see if our defender cannot evade the attack. We will take 8 times the defenders agi value and divide it by our attackers dex value, then add our defenders evasion value. We set this value to eva. Now if our damage is less than 0, we set a hit value to 100, otherwise, we set a hit value to 100 minus our eva value. If our defender can't evade, we then set our hit value to 100. Then we pick another random number between 0 and 100, and if it is less than our hit value, we set another hit_result value to true, otherwise false.
If hit_result is true again, we remove states that are removed when our defender is hit. We then subtract our damage value from the defenders hp and add our attackers attack element set and subtract our attackers minus element set.
If hit_result is false, we set our damage to "Miss" and clear or critical flag again.
Skill Effects
Found in : Game_Battler 3
Method name : skill_effect
Calculation :
Method name : skill_effect
Calculation :
Item Effects
Found in : Game_Battler 3
Method name : item_effect
Calculation :
Method name : item_effect
Calculation :
Slip Damage Effects
Found in : Game_Battler 3
Method name : slip_damage_effect
Calculation :
Method name : slip_damage_effect
Calculation :
Basic Explanations :
Basic Explanation A
Basic Explanation B
Basic Explanation C
Basic Explanation D
For : maxhp, maxsp, str, dex, agi, int
Formula :
base : The base value is determined in either Actor or Enemy Stats. If you are calculating maxhp for an actor, you would look in base_maxhp in Actor stats.
plus : This value is a bunus given your your base value. If you are calculating maxhp, you would use @maxhp_plus.
rate : You use the rate percent for a certain state.
min/max : Each stat has it's own min and max value. The value for every stat must be within this range when it is returned.
How it works : We start off by taking our base value and adding our plus bonus. We set this value between our min and max value. We then pass through all our current states and multiple our state percent rate. Then we return a value between our min and max.
Formula :
Code:
n = [[base + plus, min].max, max].min
for i in @states
n *= $data_states[i].rate / 100.0
end
n = [[Integer(n), min].max, max].min
return n
plus : This value is a bunus given your your base value. If you are calculating maxhp, you would use @maxhp_plus.
rate : You use the rate percent for a certain state.
min/max : Each stat has it's own min and max value. The value for every stat must be within this range when it is returned.
How it works : We start off by taking our base value and adding our plus bonus. We set this value between our min and max value. We then pass through all our current states and multiple our state percent rate. Then we return a value between our min and max.
Basic Explanation B
For : atk, pdef, mdef, eva
Formula :
For eva:
base : The base value is determined in either Actor or Enemy Stats. If you are calculating atk for an actor, you would look in base_atk in Actor stats.
rate : You use the rate percent for a certain state.
How it works : We start off by taking our base value. We then pass through all our current states and multiple our state percent rate, except with eva, we add an eva bonus.
Formula :
Code:
n = base_atk
for i in @states
n *= $data_states[i].atk_rate / 100.0
end
return Integer(n)
Code:
n = base_eva
for i in @states
n += $data_states[i].eva
end
return n
rate : You use the rate percent for a certain state.
How it works : We start off by taking our base value. We then pass through all our current states and multiple our state percent rate, except with eva, we add an eva bonus.
Basic Explanation C
For : base_str, base_dex, base_agi, base_int
Formula :
base : The base value is determined in either Actor Stats.
plus : These are bonuses you recieve from your equipment that you set in the database.
How it works : We start off by taking our base value. Then add our bonuses from all our equipment, and return a value between 1 and 999, our min and max value.
Formula :
Code:
n = base
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.plus : 0
n += armor1 != nil ? armor1.plus : 0
n += armor2 != nil ? armor2.plus : 0
n += armor3 != nil ? armor3.plus : 0
n += armor4 != nil ? armor4.plus : 0
return [[n, 1].max, 999].min
plus : These are bonuses you recieve from your equipment that you set in the database.
How it works : We start off by taking our base value. Then add our bonuses from all our equipment, and return a value between 1 and 999, our min and max value.
Basic Explanation D
For : base_pdef, base_mdef, base_eva
Formula :
* Eva does not include weapon stats
stat : These are values set for each piece of equipment.
How it works : We return the collective value of all our equipment stat values.
Formula :
Code:
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
v1 = weapon != nil ? weapon.stat : 0
v2 = armor1 != nil ? armor1.stat : 0
v3 = armor2 != nil ? armor2.stat : 0
v4 = armor3 != nil ? armor3.stat : 0
v5 = armor4 != nil ? armor4.stat : 0
return v1 + v2 + v3 + v4 + v5
stat : These are values set for each piece of equipment.
How it works : We return the collective value of all our equipment stat values.