Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Battle Control Script, Version 0.3
- # Released 8/4/2015
- # Author: bgillisp
- # Description:
- # The first of my planned battle system scripts, this script gives the designer
- # better control over how many of the little things are calculated inside the
- # engine
- #
- # Current Features:
- #
- # -Can add a state that makes the target always do the minimum possible
- # damage (like the curse spell in some games).
- # -Can add a state that makes the target always do the maximum possible
- # damage (like the bless spell in some games).
- # -Can add a notetag to a skill or item which increases or decreases the
- # to hit chance of a physical or magical attack by x%.
- # -Can add a notetag to a skill or item which makes the skill or item
- # always do at least x damage, or at most x damage
- # -Can set a global max or min in the editible region, which can be
- # overridden on a skill by skill basis.
- # -Can change the global value for critical damage
- # -Can set states which increase or decrease critical damage done
- # -Can set equipment which increase or decrease critical damage done
- # -Can make enemies do increased or decreased critical damage
- # -Can set up complex formulas which increase your critical hit damage
- # by a stat, current HP, MP, TP, or a combination of the four!
- # Planned features:
- # -Ability to add states which dampen or stretch the variance.
- # -Ability to make a skill use a normal distribution curve for computing
- # damage. This will allow you to still have the possibility of a high
- # power hit, but it would be rarer than it is now.
- # Overwtitten Methods:
- # make_damage_value, from class Game_Battler.
- # item_hit, from class Game_Battler.
- # Aliased Methods: None
- # To use: Place the script in your materials section, but above main.
- # ***Important*** This script must go *above* any script that aliases
- # the make_damage_value function and the item)hit function. It is highly
- # advised for that reason that you put this script *first* in your script
- # list. If that is not possible, put this script above your battle system
- # scripts.
- # Compatibility issues: Must go above any battle system scripts, or the
- # battle system will fail to work. Must go above my HP Barrier script,
- # else the HP Barrier script will not work.
- # Requires some editing to work with Yanfly's Battle Engine. Patch will be
- # posted for that engine once finished (no ETA at the moment). I cannot
- # provide support for other battle engines though as I don't have them set
- # up on my system. However, you do have my permission to find someone else
- # to edit this script so it works with the other battle systems.
- # Terms of use: Free for use for commercial and non-commercial games, with
- # credit given.
- #-------------------------------------------------------------------------
- # Editable Region
- module BG_Battle_Control_Script
- #Set the state which, if applied, the attacker always does minimum damage
- BG_Variance_Min = 26
- #Set the state which, if applied, the attacker always does max damage
- BG_Variance_Max = 27
- #Set here the states which will change the variance. Seperate each state
- #by a comma
- BG_Variance_Change = [ #Opening [, do not delete
- [28, 0.5], #State 28 will reduce the variance by 50%, or cut it in half.
- [29, 2.0], #State 29 will double the variance.
- #Insert your states here, or replace the ones above
- ] #Do not delete this!
- #Set here the highest the variance is to ever be.
- #Waring: Values more than 1.00 can resulit in an attack doing negative damage!
- BG_Variance_Max = 1.00
- #Set to the lowest damage you want any skill to be able to do, without a
- #notetag, before resistances are calculated
- BG_Minimum_Damage = 1
- #Set to the highest damage you want any skill to be able to do, without a
- #notetag, before resistances are calculated
- BG_Maximum_Damage = 9999
- #Set the states that can raise or lower critical hit damage done by the
- #one inflicted with the state
- #Format: Everything is entered in an array, inside of an array. To add a state,
- #the format is [x, y], where x is the id of the state, and y is the percent
- #the state increases (or decreases) your critical damage by.
- BG_Critical_Damage_Given_States = [ #Opening [, do not delete
- [30, 0.25 ], #State 30 adds 25% to critical damage done
- [31, -0.25], #State 31 removes 25% to critical damage done.
- #Insert your states here, or replace the ones above.
- ] #Do not delete this!
- BG_Critical_Damage_Received_States = [ #opening [, do not remove
- [32, 0.25], #State 32 increases critical damage taken by 25%.
- [33, -0.25], #State 33 reduces critical damage taken by 25%.
- #insert your states here, or replace the ones above.
- ] #Do not delete this!
- #Set to the default critical hit percent you wish the game to use.
- #The script uses 2.0 by default, though the default engine uses 3.0
- BG_Default_Critical_Value = 2.0
- #Set to true to turn on the advanced critical hit damage features below
- BG_Critial_Features_On = false
- ###### Advanced Features for Critical Hit. Use with caution!!!! ####
- # ***Disabled by default*** #
- ########################################################################
- #Set here the amount critical damage is to increase, based on a stat
- #Set to 0.00 to disable
- BG_Critical_Boost_Value = 0.00
- #Amount current HP boosts your critical damage by. Using this would mean that
- #wounded monsters do less damage on a critical hit. Set to 0.00 to disable
- BG_Critical_HP_Boost = 0.00
- #Amount current MP boosts your crtiical damage by. Set to 0.00 to disable
- BG_Critical_MP_Boost = 0.00
- #Amount current TP boosts your critical damage by. Set to 0.00 to disable
- BG_Critial_TP_Boost = 0.00
- #Set here the max of the critical boost, from stats, HP, MP and TP
- #Default is 1.0, for 100% boost.
- BG_Critical_Boost_Max = 1.0
- #Set here the number corresponding to the param that you wish to boose
- #the critical damage. Currently, it is set to param 7, which is LUK.
- #Key:
- # 0 = MHP
- # 1 = MMP
- # 2 = ATK
- # 3 = DEF
- # 4 = MAT
- # 5 = MDF
- # 6 = AGL
- # 7 = LUK
- # 8 onward will crash the game, as those params do not exist without a custom
- # script to add them.
- BG_Critical_Boost_Stat = 7
- end
- #End of Editable Region
- #---------------------------------------------------------------------------
- #Do not edit anything below here unless you know what you are doing. Failure to
- #follow these directions may result in your game crashing or doing unpredictable
- #things. I am not responsible for any damage which results if you decide to edit
- #things below this line
- #------------------------------------------------------------------------------
- module DataManager
- #--------------------------------------------------------------------------
- # alias method: load_database
- #--------------------------------------------------------------------------
- class <<self; alias load_database_bg_variancecontrol_load_database load_database; end
- def self.load_database
- load_database_bg_variancecontrol_load_database
- load_notetags_bg_variancecontrol
- end
- #--------------------------------------------------------------------------
- # new method: load_notetags_bg_bpbarrier
- #--------------------------------------------------------------------------
- def self. load_notetags_bg_variancecontrol
- groups = [$data_actors, $data_classes, $data_weapons, $data_armors,
- $data_enemies, $data_states, $data_skills, $data_items]
- for group in groups
- for obj in group
- next if obj.nil?
- obj.load_notetags_bg_variancecontrol
- end
- end
- end
- end # End moudle DataManager
- #Code to load the notetags and store it in a state
- class RPG::BaseItem
- #Define all variables needed for notetag loading here
- attr_accessor :to_hit_modify
- attr_accessor :skill_max
- attr_accessor :skill_min
- attr_accessor :critical_value
- #Used in equips and enemies only, this is the amount to add or subtract
- #to the critical damage done.
- attr_accessor :critical_modify
- #Used for actors and enemies only, this overrides the default value to multiply
- #the damage by when a critical hit occurs.
- attr_accessor :hhhhh
- def load_notetags_bg_variancecontrol
- #Initialize all variables. This should avoid any of them being nil
- @to_hit_modify = 0.0
- @critical_value = 0.0
- @critical_modify = 0.0
- @skill_max = BG_Battle_Control_Script::BG_Maximum_Damage
- @skill_min = BG_Battle_Control_Script::BG_Minimum_Damage
- @store = self.note[/(?<=<To_Hit_Modify: ).*?(?=[>])/].to_f
- if(@store != nil && @store != 0)
- @to_hit_modify = @store
- end
- @store = self.note[/(?<=<Critical_Value: ).*?(?=[>])/].to_f
- if(@store != nil && @store > 1)
- @critical_value = @store
- end
- @store = self.note[/(?<=<Critical_Modify: ).*?(?=[>])/].to_f
- if(@store != nil && @store != 0)
- @critical_modify = @store
- end
- @store = self.note[/(?<=<Skill_Max: ).*?(?=[>])/].to_f
- if(@store != nil && @store > 0)
- @skill_max = @store.to_i
- end
- @store = self.note[/(?<=<Skill_Min: ).*?(?=[>])/].to_f
- if(@store != nil && @store > 0)
- @skill_min = @store.to_i
- end
- #Error catch. If you ever set the min > max, it will set them equal to each
- #other
- if(@skill_min > @skill_max)
- @skill_min = @skill_max
- end
- end #End load_notetags
- end #End class RPG::BaseItem
- class Game_Battler < Game_BattlerBase
- #Overwrite method, make_damage_value
- def make_damage_value(user, item)
- value = item.damage.eval(user, self, $game_variables)
- #Set the damage to the minimum allowed by the skill now, if it is not healing
- if(value < item.skill_min && !item.damage.recover?)
- value = item.skill_min
- end
- #Set the minimum for healing skills now
- if(value > -item.skill_min && item.damage.recover?)
- value = -item.skill_min
- end
- #Set the damage to the maximum allowed by the skill now.
- if(value > item.skill_max && item.skill_max > 0 && !item.damage.recover?)
- value = item.skill_max
- end
- #Set the maximum for healing skills now
- if(value < -item.skill_max && item.skill_max > 0 && item.damage.recover?)
- value = -item.skill_max
- end
- value *= item_element_rate(user, item)
- value *= pdr if item.physical?
- value *= mdr if item.magical?
- value *= rec if item.damage.recover?
- #Changes to the critical hit system are here. Copy/paste the appropriate
- #code as needed.
- ########### Begin changes to the critical hit system
- #Save the old value, before first calculation is done.
- oldvalue = value
- #Check for critical hit
- if(@result.critical)
- msgbox_p(user.actor.class_id)
- #Check if the skill or item has a special critical value. If so, use it.
- #If not, call the default.
- if(item.critical_value > 1)
- value *= item.critical_value
- else
- value = apply_critical(value)
- end #End code for calculating the critical hit value.
- #Check to see if we need to add to the boost (or take away from it), based
- #on user equips
- #Check if an actor is the user
- if(user.actor?)
- for equip in user.equips
- next if equip.nil?
- value += oldvalue * equip.critical_modify
- end #End for loop
- end
- #Check if the enemy has a modification to their critical damage
- if(user.enemy?)
- value += oldvalue * user.enemy.critical_modify
- end
- #Check now to see if the user has a state which raises or lowers the
- #amount of critical damage they do
- for states in BG_Battle_Control_Script::BG_Critical_Damage_Given_States
- if(user.state?(states[0]))
- value += oldvalue * states[1]
- end
- end
- #Finally, check to see if the target has a state which reduces critical
- #damage taken.
- for states in BG_Battle_Control_Script::BG_Critical_Damage_Received_States
- if(self.state?(states[0]))
- value += oldvalue * states[1]
- end
- end
- #Check to see if the boost took us below normal damage. If so, reset
- #the damage to the lowest allowed critical hit value, which is 1 more
- #than standard damage.
- if(value < oldvalue)
- value = oldvalue + 1
- end
- #If optional features to boost critical damage based on stats is turned on,
- #apply the boost here
- if(BG_Battle_Control_Script::BG_Critial_Features_On == true)
- #Initial boost calculation, based on the boost stat
- boostvalue = oldvalue * BG_Battle_Control_Script::BG_Critical_Boost_Value * user.param(BG_Battle_Control_Script::BG_Critical_Boost_Stat)
- #Next, calculate the boost, based on current HP
- boostvalue += oldvalue * BG_Battle_Control_Script::BG_Critical_HP_Boost * user.hp
- #Next, calculate the boost, based on current MP
- boostvalue += oldvalue * BG_Battle_Control_Script::BG_Critical_MP_Boost * user.mp
- #Finally, calculate the boost, based on user's current TP.
- boostvalue += oldvalue * BG_Battle_Control_Script::BG_Critial_TP_Boost * user.tp
- #Check to see if it is too high, based on the max
- if(boostvalue >= BG_Battle_Control_Script::BG_Critical_Boost_Max * oldvalue)
- boostvalue = BG_Battle_Control_Script::BG_Critical_Boost_Max * oldvalue
- end #End check to see if boost is too large
- #Check to see if the boost is worse than doing no critical hit at all
- if( (value + boostvalue) < (value - oldvalue) )
- #If we are here, the boost was worse than standard damage. Reset the
- #damage back to the old value, and set the boost to 0.
- value = oldvalue + 1
- boostvalue = 0
- end #End check
- #Add in the amount of the boost now
- value += boostvalue
- end #End if statement for optional boost features
- end #End check for critical hit.
- ########### End changes to the critical hit system################
- #Changes to the variance calculation are here. If you wish to apply these
- #to a different battle system comment out the line apply_variance, then
- #copy and paste these lines in its place.
- ########### Begin changes to the variance system here ############
- #Compute the HP value of the variance
- amp = [value.abs * item.damage.variance / 100, 0].max.to_i
- #Debug line, uncommment if you wish to see the HP value of the variance
- #msgbox_p(amp)
- #If we are to do the minimum damage, apply the variance now.
- if user.state?(BG_Battle_Control_Script::BG_Variance_Min)
- var = -amp
- elsif user.state?(BG_Battle_Control_Script::BG_Variance_Max)
- var = amp
- else
- #Calculate the value of the variance normally
- var = rand(amp + 1) + rand(amp + 1) - amp
- end
- #Apply the variance
- if(value >=0)
- value += var
- else
- value -= var
- end
- #End modified code. The rest of this is the same as the default battle
- #Engine
- value = apply_guard(value)
- @result.make_damage(value.to_i, item)
- end
- #Changes to how to_hit is calculated. Now, it checks to see if there is a
- #notetag on an item to add a boost (or penalty) to the to hit for a physical
- #attack.
- def item_hit(user, item)
- rate = (item.success_rate * 0.01) # Get success rate
- #To add this to another battle system, replace the check if item_physical
- #with this code, up to the *** part below
- if item.physical?
- rate *= user.hit # Physical attack: Multiply hit rate
- #If bonus or penalty to hit is defined, add it into the rate.
- if(item.to_hit_modify != nil)
- rate += item.to_hit_modify
- end
- end #End if item.physical?
- if item.magical?
- #If bonus or penalty to hit is defined, add it onto the rate, which is
- #1.0, or 100%, by default.
- if(item.to_hit_modify != nil)
- rate += item.to_hit_modify
- end
- end #End if item.magical?
- #******End of edits to item_hit, rest is the default code###
- return rate # Return calculated hit rate
- end
- #Does a random damage between the min and max. Best used directly in the
- #damage formula
- def uniform_damage(min, max)
- #Compute the range of the numbers
- roll = (max - min).to_i
- #Safety check, make sure the number is at least 1
- if(roll < 0)
- roll = 1
- end
- #Compute the random number
- udvalue = rand(roll) + 1 + min
- return udvalue
- end
- #Overwritten method, apply_critical
- def apply_critical(damage)
- damage * BG_Battle_Control_Script::BG_Default_Critical_Value
- end #End apply_critical
- end #End Game_Battler
RAW Paste Data