The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on September 09, 2008, 12:30:10 AM

Title: Enemy Stat Variance
Post by: modern algebra on September 09, 2008, 12:30:10 AM
Enemy Stat Variance
Version: 1.1
Author: modern algebra
Date: September 26, 2008

Version History




Description



This script allows you to attach a variance to each enemy stat, so that enemy instances aren't all just clones of each other but can have stat differences.

Features


Screenshots

N/A

Instructions

See inside Script Header

Script



#==============================================================================
#  Enemy Stat Variance
#  Version: 1.1
#  Author: modern algebra
#  Date: September 26, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Instructions:
#    Just place the code for each of the stat variances you want into the notes
#   box of the Enemy. The possible codes are:
#  
#      \variance_hp[x]
#      \variance_mp[x]
#      \variance_atk[x]
#      \variance_def[x]
#      \variance_spi[x]
#      \variance_agi[x]
#      \variance_hp%[x]
#      \variance_mp%[x]
#      \variance_atk%[x]
#      \variance_def%[x]
#      \variance_spi%[x]
#      \variance_agi%[x]
#
#    Each of the codes will give a variance of x to the stat chosen. A variance
#   x means that the enemy will have a random number between 0 and x added to
#   its base stat. So, if the base stat set in the database is 120, and x is
#   set to 30, then that stat will be between 120 and 150 for any instance of
#   that enemy. So, if you are fighting two slimes, then one of them could have
#   that stat be 127 while the other has it at 142, for example.
#
#   If the codes have a percentage to them, then it will take a random number
#  between 0 and x and add that percentage of the stat to the enemy's stat. So,
#  if an enemy's max HP is 200 and you set \variance_hp%[10], then the script
#  will choose a random number between 0 and 10. In this case, let's say it
#  chooses 6, then .06*200 will be added to the enemy's HP, resulting in that
#  enemy having 212 HP
#==============================================================================
# ** Game_Enemy
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased method - initialize
#==============================================================================

class Game_Enemy < Game_Battler
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Object Initialization
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias modalg_varystat_enmy_init_9hd4 initialize
 def initialize (index, enemy_id)
   modalg_varystat_enmy_init_9hd4 (index, enemy_id)
   # Add to stats according to variance in notes
   text = enemy.note.dup
   # Dissect Note
   while text[/\\variance_.*\[\d+\]/i]
     text.sub!(/\\variance_(.*)\[(\d+)\]/i) { "" }
     random_num = rand ($2.to_i)
     case $1.to_s
     when /HP%/i then @maxhp_plus += ((random_num.to_f / 100.0)*self.maxhp).to_i
     when /MP%/i then @maxmp_plus += ((random_num.to_f / 100.0)*self.maxmp).to_i
     when /ATK%/i then @atk_plus += ((random_num.to_f / 100.0)*self.atk).to_i
     when /DEF%/i then @def_plus += ((random_num.to_f / 100.0)*self.def).to_i
     when /SPI%/i then @spi_plus += ((random_num.to_f / 100.0)*self.spi).to_i
     when /AGI%/i then @agi_plus += ((random_num.to_f / 100.0)*self.agi).to_i
     when /HP/i then @maxhp_plus += random_num
     when /MP/i then @maxmp_plus += random_num
     when /ATK/i then @atk_plus += random_num
     when /DEF/i then @def_plus += random_num
     when /SPI/i then @spi_plus += random_num
     when /AGI/i then @agi_plus += random_num
     end
   end
   @hp = maxhp
   @mp = maxmp
 end
end


Credit




Support



Please post in this topic at rmrk.net for any support you may need. Also, if you have any suggestions, then please tell me - I am always looking for ways to improve my scripts.

Known Compatibility Issues

No known compatibility issues.

Demo



Not useful or necessary.



Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
Title: Re: Enemy Stat Variance
Post by: Craze on September 11, 2008, 08:47:41 PM
I've always loved your scripts, modern algebra, and this is no exception. This replaces a similar script I used for RMXP functionality back in the day... kudos, good sir.
Title: Re: Enemy Stat Variance
Post by: wsensor on September 23, 2008, 03:50:39 AM
umm you have an error on line 46...
/SP <=should be /MP right?
and also maxsp_plus should be maxmp_plus

right? I was just trying it out and it crashed on a battle test where I was adding mp to monsters
Title: Re: Enemy Stat Variance
Post by: modern algebra on September 23, 2008, 02:43:46 PM
Ah, yes you are correct

Thanks for pointing it out
Title: Re: Enemy Stat Variance
Post by: Rukaroa on September 25, 2008, 04:10:51 AM
Can you add an option that allows you to use percentages in addition to the current script for variance?
Title: Re: Enemy Stat Variance
Post by: modern algebra on September 26, 2008, 02:42:11 PM
Sure. Give me a second.

EDIT::

After class - I got distracted. I will write the extension for you in an hour or two.
Title: Re: Enemy Stat Variance
Post by: Rukaroa on September 27, 2008, 06:26:51 AM
Thanks =D
Title: Re: Enemy Stat Variance
Post by: modern algebra on September 27, 2008, 03:07:00 PM
oh, and it's done. I forgot to announce that  :-X
Title: Re: Enemy Stat Variance
Post by: Razielboy on October 04, 2008, 10:36:05 PM
Awesome script. ;)
Title: Re: Enemy Stat Variance
Post by: wsensor on October 07, 2008, 07:55:30 AM
Umm you used the SP instead of MP again
[spoiler]
#==============================================================================
#  Enemy Stat Variance
#  Version: 1.1
#  Author: modern algebra
#  Date: September 26, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Instructions:
#    Just place the code for each of the stat variances you want into the notes
#   box of the Enemy. The possible codes are:

#      \variance_hp[x]
#      \variance_mp[x]
#      \variance_atk[x]
#      \variance_def[x]
#      \variance_spi[x]
#      \variance_agi[x]
#      \variance_hp%[x]
#      \variance_mp%[x]
#      \variance_atk%[x]
#      \variance_def%[x]
#      \variance_spi%[x]
#      \variance_agi%[x]
#
#    Each of the codes will give a variance of x to the stat chosen. A variance
#   x means that the enemy will have a random number between 0 and x added to
#   its base stat. So, if the base stat set in the database is 120, and x is
#   set to 30, then that stat will be between 120 and 150 for any instance of
#   that enemy. So, if you are fighting two slimes, then one of them could have
#   that stat be 127 while the other has it at 142, for example.
#
#   If the codes have a percentage to them, then it will take a random number
#  between 0 and x and add that percentage of the stat to the enemy's stat. So,
#  if an enemy's max HP is 200 and you set \variance_hp%[10], then the script
#  will choose a random number between 0 and 10. In this case, let's say it
#  chooses 6, then .06*200 will be added to the enemy's HP, resulting in that
#  enemy having 212 HP
#==============================================================================
# ** Game_Enemy
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased method - initialize
#==============================================================================

class Game_Enemy < Game_Battler
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_varystat_enmy_init_9hd4 initialize
  def initialize (index, enemy_id)
    modalg_varystat_enmy_init_9hd4 (index, enemy_id)
    # Add to stats according to variance in notes
    text = enemy.note.dup
    # Dissect Note
    while text[/\\variance_.*\[\d+\]/i]
      text.sub!(/\\variance_(.*)\[(\d+)\]/i) { "" }
      random_num = rand ($2.to_i)
      case $1.to_s
      when /HP%/i then @maxhp_plus += ((random_num.to_f / 100.0)*self.maxhp).to_i
      when /MP%/i then @maxmp_plus += ((random_num.to_f / 100.0)*self.maxmp).to_i
      when /ATK%/i then @atk_plus += ((random_num.to_f / 100.0)*self.atk).to_i
      when /DEF%/i then @def_plus += ((random_num.to_f / 100.0)*self.def).to_i
      when /SPI%/i then @spi_plus += ((random_num.to_f / 100.0)*self.spi).to_i
      when /AGI%/i then @agi_plus += ((random_num.to_f / 100.0)*self.agi).to_i
      when /HP/i then @maxhp_plus += random_num
      when /MP/i then @maxmp_plus += random_num
      when /ATK/i then @atk_plus += random_num
      when /DEF/i then @def_plus += random_num
      when /SPI/i then @spi_plus += random_num
      when /AGI/i then @agi_plus += random_num
      end
    end
    @hp = maxhp
    @mp = maxmp
  end
end


[/spoiler]
I just changed all the sp to mp XD
Title: Re: Enemy Stat Variance
Post by: modern algebra on October 07, 2008, 03:21:47 PM
You're right. I'm too stuck in RMXP :(
Title: Re: Enemy Stat Variance
Post by: Selacius on October 08, 2008, 01:01:38 AM
Can we get this to work with gold and experience from the enemy?
Title: Re: Enemy Stat Variance
Post by: modern algebra on October 08, 2008, 01:59:22 AM
It would be very easy, but for exp it might not be prudent, as it possibly results in harder enemies giving less exp and easy enemies giving more. It might make more sense to develop an algorithm based on the pluses given.