Enemy Challenge for Experience

DerVVulfman

Resident Werewolf
Veteran
Joined
Jun 26, 2012
Messages
315
Reaction score
154
First Language
English
Primarily Uses
RMXP
Enemy Challenge for Experience
Version: 1.0​



Introduction

Tired of letting gamers grind away hours fighting weaker monsters so they can level themselves up? Do you want to make sure they may only increase their character's levels by fighting monsters tough enough to give them a real threat? Then this script is for you.

Inspired by a feature from iishenron's RPGMaker 2000 game "Three the Hard Way", this system calculates the combined statistics of every enemy in a troop to that of the heroes in the party. And as long as the enemy is not too weak, the party gets experience for the enemy's defeat.

VANCE*: "But if I decide to spend the next two years fighting slimes to build myself up..."
* The main hero of "Three the Hard Way"

Clearly, this is not going to happen with this script.



Script
Code:
#==============================================================================
# ** Enemy Challenge for Experience
#------------------------------------------------------------------------------
#    version 1.0
#    by DerVVulfman
#    11-24-2019 (MM-DD-YYYY)
#    RGSS / RPGMaker XP
#=============================================================================
#
#  INTRODUCTION:
#
#    Tired of letting gamers grind away hours fighting weaker monsters so they
#    can level themselves up?  Do you want to make sure they may only increase
#    their character's levels by fighting monsters tough enough to give them a
#    real threat?  Then this script is for you.
#
#    Inspired by a feature from iishenron's RPGMaker 2000 game "Three the Hard
#    Way", this system calculates  the combined statistics of every enemy in a
#    troop to that  of the heroes in the party.  And as long  as the enemy  is
#    not too weak, the party gets experience for the enemy's defeat.
#
#    VANCE*:  "But if I decide  to spend the next two years fighting slimes to
#             build myself up..."
#             *The main hero of "Three the Hard Way"
#
#    Clearly, this is not going to happen with this script.
#
#------------------------------------------------------------------------------
#
#  INSTALLATION:
#
#    If you are not using a custom battlesystem or script that alters the main
#    method of  Scene_Battle,  paste this script  below Scene_Debug  and above
#    main.  And then paste the example 'patch' below this script.
#
#    If you are using a custom battlesystem  or you have  a script that alters
#    Scene_Battle,  place this script  and the patch  below the custom battle-
#    system script.
#
#    Please note that the fore-mentioned  'patch'  is a copy of Scene_Battle's
#    own 'start_phase5' method with the simplest of edits.   There is only one
#    added line within the patch (not including the comments).   This one line
#    eliminates any exp point gain if the troop isn't enough of a challenge.
#
#    If it is not possible to use this patch because your custom battlesystem
#    alters this method,  just insert the below code  into your custom battle-
#    system script  after the point  where the enemy's experience point s have
#    been totaled, but before the heroes gain the experience:
#
#        # Erase Exp Gain if not a challenge
#        exp = 0 unless @e_stat_challenge == true
#
#    This would be the only direct edit you would need.
#
#=============================================================================
#
#  USAGE
#
#    The system is based heavily upon automation.  In that, it is designed to
#    calculate the stats of your enemies and party members  without any inter-
#    ference.  With this, only the configuration values may come into play.
#
#    You can have pre-defined enemy stat scores  rather than have the figures
#    be calculated.   This is done by adding a comment into the first page of
#    your enemy troop. The comment is the letters 'EC' followed by the score.
#    As an example, a comment of EC5300 sets the troop's stat total to 5300.
#
#    If it is not possible to use this patch because your custom battlesystem
#    Finally you can disable the system for any troop, this done by using the
#    same comment system.  A comment of EC-1  sets the troop stat total to -1
#    and thus tells the system to ignore stat comparisons.
#
#
#=============================================================================
#
#  CONFIGURATION
#
#    The 'EChallenge' module has the values which you would need to alter
#    to suit your tastes.
#
#    * DEBUG_SHOW:       This basically  just turns  on/off  a pop-up  window
#                        showing your party's  accumulated stat score  versus
#                        the stat score of the enemy encountered.
#
#    * SKILLS:           This enables/disables  the system that determines if
#                        enemy and actor skills are used in the calculations.
#
#    * MULTIPLIER:       This allows you  to increase the enemy's accumulated
#                        stat score befor it is compared to the actor's. This
#                        way, weaker enemies may still be viable for exp point
#                        gain.  DEFAULT set to 1.5
#    * ENEMY_SKILL_MULT: This  allows you  to increase  the calculated  skill
#                        power score  for your enemies before it is  added to
#                        their total accumulated score.
#
#    * ACTOR_SKILL_MULT: This  allows you  to increase  the calculated  skill
#                        power score  for your actors  before it is  added to
#                        their total accumulated score.
#
#
#=============================================================================
#
#  CREDITS AND THANKS
#
#    Thanks to iishenron for the inspiration for this system.
#
#=============================================================================
#
#  TERMS AND CONDITIONS
#
#    Free for use, even within commercial products. Due credit is required.
#
#=============================================================================




module EChallenge


  # BASICS
    DEBUG_SHOW        = false   # If you see the comparison at battle start
    SKILLS            = true    # If actor/enemy skills are even counted
 
  # MULTIPLIERS
    MULTIPLIER        = 1.5     # Basic multiplier for enemy
    ENEMY_SKILL_MULT  = 1.5     # Increase/decrease in points for enemy skill
    ACTOR_SKILL_MULT  = 1.0     # Increase/decrease in points for actor skill


end



#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :weapon_id                # weapon ID
  attr_accessor :armor1_id                # shield ID
  attr_accessor :armor2_id                # helmet ID
  attr_accessor :armor3_id                # body armor ID
  attr_accessor :armor4_id                # accessory ID
end



#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Start After Battle Phase
  #--------------------------------------------------------------------------
  alias enemychallenge_battle_main main
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Run enemy stat comparizon
    comparative_stats
    # Perform the original call
    enemychallenge_battle_main
  end
  #--------------------------------------------------------------------------
  # * Actor / Enemy Comparative Stats
  #--------------------------------------------------------------------------
  def comparative_stats
    # Iniitalize values
    enemy_stats = 0
    actor_stats = 0
    # Acquire Troop Data
    troop_id    = $game_temp.battle_troop_id
    troop       = $data_troops[troop_id]
    # Use a comment for the stat challenge value
    page = troop.pages[0]
    list = page.list
    for items in list
      if items.code == 108
        param = items.parameters
        param_text = param[0].upcase
        if param_text.slice(0,2) == "EC"
          len = (param_text.length) - 2
          enemy_stats = (param_text.slice(2,len)).to_i
        end
      end
    end
    # If the predefined comment is -1 (the system is ignored)
    if enemy_stats == -1
      if EChallenge::DEBUG_SHOW == true
        text = "Challenge is ignored"
        print text
      end
      @e_stat_challenge = true
      return
    end
    # If no predefined comment
    if enemy_stats == 0
      skill_mult    = EChallenge::ENEMY_SKILL_MULT
      enemy_stats   = comparative_stats_enemy(troop, skill_mult)
    end
    # Acquire active/living party member stats
    skill_mult    = EChallenge::ACTOR_SKILL_MULT
    actor_stats   = comparative_stats_actor(skill_mult)
    # Display a popup showing enemy/actor points and if a challenge
    if EChallenge::DEBUG_SHOW == true
      text = "Enemy: " + (enemy_stats.to_s) + " / Actor: " + (actor_stats.to_s)
      text += "\nThis is a challenge" if enemy_stats >= actor_stats
      print text
    end
    # Now Compare stats
    @e_stat_challenge = false
    @e_stat_challenge = true    if enemy_stats >= actor_stats
  end
  #--------------------------------------------------------------------------
  # * Actor / Enemy Comparative Stats : Troop Version
  #     troop      : enemy troop
  #     skill_mult : enemy's multiplier value for skill power
  #--------------------------------------------------------------------------
  def comparative_stats_enemy(troop, skill_mult=1.0)
    total_stats = 0
    stat        = 0
    sklstat     = 0
    # Acquire troop enemy stats
    for i in 0...troop.members.size
      enemy = $data_enemies[troop.members[i].enemy_id]
      next if enemy.nil?
      stat += enemy.str
      stat += enemy.dex
      stat += enemy.agi
      stat += enemy.int
      stat += enemy.atk
      stat += enemy.pdef
      stat += enemy.mdef
      stat += enemy.maxhp
      stat += enemy.maxsp
      next unless EChallenge::ACTOR_SKILL_MULT == true
      # Special:  Acquire skill power
      for action in enemy.actions 
        next unless action.kind == 1
        skill = action.skill_id
        next if skill.nil?
        next if $data_skills[skill].nil?
        power = $data_skills[skill].power
        sklstat += power if power > 0
      end
    end
    # Multiplier for Enemy Skill Power
    sklstat *= skill_mult
    # Combine all enemy stats
    total_stats += stat + sklstat
    total_stats *= EChallenge::MULTIPLIER
    return total_stats
  end
  #--------------------------------------------------------------------------
  # * Actor / Enemy Comparative Stats : Troop Version
  #     skill_mult : enemy's multiplier value for skill power
  #--------------------------------------------------------------------------
  def comparative_stats_actor(skill_mult=1.0)
    total_stats = 0
    stat        = 0
    sklstat     = 0
    # Acquire active/living party member stats
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      next if actor.nil?
      next if actor.dead?
      # Remove equipment to compare base stats
      armor1_temp = actor.armor1_id
      armor2_temp = actor.armor2_id
      armor3_temp = actor.armor3_id
      armor4_temp = actor.armor4_id
      weapon_temp = actor.weapon_id
      actor.armor1_id = 0
      actor.armor2_id = 0
      actor.armor3_id = 0
      actor.armor4_id = 0
      actor.weapon_id = 0
      # Get base stats
      stat += actor.str
      stat += actor.dex
      stat += actor.agi
      stat += actor.int
      stat += actor.atk
      stat += actor.pdef
      stat += actor.mdef
      stat += actor.maxhp
      stat += actor.maxsp
      # Reapply equipment
      actor.armor1_id = armor1_temp
      actor.armor2_id = armor2_temp
      actor.armor3_id = armor3_temp
      actor.armor4_id = armor4_temp
      actor.weapon_id = weapon_temp
      next unless EChallenge::ACTOR_SKILL_MULT == true
      # Special:  Acquire skill power
      for skill in actor.skills
        next if skill.nil?
        next if $data_skills[skill].nil?
        power = $data_skills[skill].power
        sklstat += power if power > 0
      end
    end
    # Multiplier for Enemy Skill Power
    sklstat *= skill_mult
    # Combine all enemy stats
    total_stats += stat + sklstat
    return total_stats
  end
end

Code:
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Start After Battle Phase
  #--------------------------------------------------------------------------
  def start_phase5
    # Shift to phase 5
    @phase = 5
    # Play battle end ME
    $game_system.me_play($game_system.battle_end_me)
    # Return to BGM before battle started
    $game_system.bgm_play($game_temp.map_bgm)
    # Initialize EXP, amount of gold, and treasure
    exp = 0
    gold = 0
    treasures = []
    # Loop
    for enemy in $game_troop.enemies
      # If enemy is not hidden
      unless enemy.hidden
        # Add EXP and amount of gold obtained
        exp += enemy.exp
        gold += enemy.gold
        # Determine if treasure appears
        if rand(100) < enemy.treasure_prob
          if enemy.item_id > 0
            treasures.push($data_items[enemy.item_id])
          end
          if enemy.weapon_id > 0
            treasures.push($data_weapons[enemy.weapon_id])
          end
          if enemy.armor_id > 0
            treasures.push($data_armors[enemy.armor_id])
          end
        end
      end
    end
 
 
    # Erase Exp Gain if not a challenge
    # =================================
    exp = 0 unless @e_stat_challenge == true
 
 
    # Treasure is limited to a maximum of 6 items
    treasures = treasures[0..5]
    # Obtaining EXP
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        if actor.level > last_level
          @status_window.level_up(i)
        end
      end
    end
    # Obtaining gold
    $game_party.gain_gold(gold)
    # Obtaining treasure
    for item in treasures
      case item
      when RPG::Item
        $game_party.gain_item(item.id, 1)
      when RPG::Weapon
        $game_party.gain_weapon(item.id, 1)
      when RPG::Armor
        $game_party.gain_armor(item.id, 1)
      end
    end
    # Make battle result window
    @result_window = Window_BattleResult.new(exp, gold, treasures)
    # Set wait count
    @phase5_wait_count = 100
  end
end



Instructions
Built into the script.



FAQ
Before calculating party member stats, it removes all 'gear' from the actors. So the actor stats calculated are before adding any bonuses from armor or weapons.




Compatibility
Designed primarily for RPGMaker XP. The main script only aliases the main system. The patch alters a method in Scene_Battle. But as stated, it only adds a single functioning line which anyone can add into their own custom system.



Credits and Thanks
Thanks to iishenron for the basic concept.



Credits and Thanks
Free for use, even within commercial products. Due credit is required.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

The only upside of this remote semester was the plenty of funny photoshop material those facecams provided. Not that I would do that. Ever.
New skit is up for grid battle system. Less tactics battle engine looking battle systems, more final fantasy/breath of fire looking battle systems.

Dororo wrote on Tsukihime's profile.
For the grid battle system: a function to check if another actor is in a given range - to trigger combo actions or benefit of passive aura/morale ranges.
Uuuh I cannot find any good RPG to play
Gimme some free RPG recommendations plz
I need to consume it
I'm in a need of excitement caused by doing literally nothing on my laptop and then thinking I did something useful and then realising that I didnt and crying internally
RPG Maker Community Discussion on releasing your game

Forum statistics

Threads
100,512
Messages
976,655
Members
132,080
Latest member
nwr
Top