The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on November 24, 2010, 08:58:35 PM

Title: Variable Stat Booster for Enemies
Post by: modern algebra on November 24, 2010, 08:58:35 PM
Variable Stat Booster for Enemies
Version: 1.0
Author: modern algebra
Date: November 24, 2010

Version History



Description


This script allows you to boost the stats of enemies in-game by modifying the value of a variable. It will affect only the stats that you specify and you can specify different variables for different enemies. One of the most obvious uses for this is to modify the difficulty of a game, but it may also be used to make certain enemies stronger at night, etc...

Features


Instructions

Place this script in its own slot above Main and below Materials in the Script Editor. Please see the header for configuration instructions.

Script


Code: [Select]
#==============================================================================
#    Variable Stat Booster for Enemies
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: November 24, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to boost the stats of enemies in-game by modifying
#   the value of a variable. It will affect only the stats that you specify and
#   you can specify different variables for different enemies. One of the most
#   obvious uses for this is to modify the difficulty of a game, but it may
#   also be used to make certain enemies stronger at night, etc...
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Paste this script into its own slot in the Script Editor (F11) below
#   Materials but above Main.
#
#    Configuration for this script is pretty easy. Simply add which stats you
#   want to be modified via variable in the array at line 34. Then choose
#   a default variable that will apply to all enemies at line 43. If you want
#   to set it so that only certain enemies are affected by some other variable,
#   you can just put \boost[var_id] in that enemy's notebox. When set, the
#   enemy's stats will be boosted as a percentage. So, if the variable is set
#   to 80, then the enemy's stats will be at 80% the default.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Configuration:
#
# VSB_STAT_ARRAY - include the stats that you want a booster variable to
#  modify. You can use any of the following - :atk, :def, :spi, :agi, :hit,
#  :eva, :maxhp, :maxmp, :gold, and :exp. If using YEM New Battler Stats, then
#  you can also use :res and :dex.
VSB_STAT_ARRAY = [:atk, :def, :spi, :agi]
# VSB_BOOST_VARIABLE_ID - this is the ID of the default variable that you want
#  to affect all enemies. It will only apply to enemies that do not have a
#  boost variable specified in their notebox. If 0, then no variable will apply
#  by default. When the variable chosen is <0 or 100, then the enemy's stats
#  will be normal. Otherwise, they will be that percent of the regular. EX. if
#  the variable chosen is set to 120, then the enemy stats will be boosted to
#  120% of the regular. So, if the enemy's stat is normally 15, then a variable
#  at 120 will mean the enemy's stat is going to be 18.
VSB_BOOST_VARIABLE_ID = 1
#==============================================================================

#==============================================================================
# ** RPG::Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - vsb_boost_variable
#==============================================================================

class RPG::Enemy
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Boost Variable ID
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def vsb_boost_variable
    if !@vsb_boost_variable
      @vsb_boost_variable = self.note[/\\BOOST\[(\d+)\]/i].nil? ? VSB_BOOST_VARIABLE_ID : $1.to_i
    end
    return @vsb_boost_variable
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Stat Aliases
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  VSB_STAT_ARRAY.each { |stat|
VSB_STAT_DEF = <<_END_
    alias malg_vsb_#{stat}_4vn1 #{stat} unless self.method_defined? (:malg_vsb_#{stat}_4vn1)
    def #{stat} (*args)
      if $game_variables && $game_variables[vsb_boost_variable]
        var = $game_variables[vsb_boost_variable].to_f / 100.0
      end
      var = 1 if var == nil || var <= 0
      return (var*(malg_vsb_#{stat}_4vn1 (*args))).to_i
    end
_END_
    eval (VSB_STAT_DEF)
  }
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Compatibility Patch for Note Editor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  if self.method_defined? (:ma_reset_note_values)
    alias mlg_vsb_resetnote_6yc4 ma_reset_note_values
    def ma_reset_note_values (*args)
      @vsb_boost_variable = nil
      mlg_vsb_resetnote_6yc4 (*args) # Run Original Method
    end
  end
end

Credit



Thanks


Support


Please post in this topic if you have any suggestions or if you encounter any bugs. It doesn't matter how old the post is, put it here anyway and do not start a new topic or PM me.

Known Compatibility Issues

If using the Note Editor, it will require that you have the General Compatibility Patch and that this script is placed below the General Compatibility Patch. Otherwise, no currently known problems.
Title: Re: Variable Stat Booster for Enemies
Post by: hiromu656 on January 03, 2011, 03:52:30 AM
Could I make the enemies get stronger as the player levels up? Kinda like how Oblivion does it.
Title: Re: Variable Stat Booster for Enemies
Post by: modern algebra on January 03, 2011, 04:10:27 AM
Yes, with some minor eventing. All you'd need to do is set a variable to the player level, then increase the booster variable based on that value. You'd probably want to do it in a parallel process common event with maybe a 60 frame Wait at the end of it.
Title: Re: Variable Stat Booster for Enemies
Post by: hiromu656 on January 03, 2011, 11:43:17 PM
Ah, why didn't I think of that. Thanks for the script.