Galv’s Past Encounters V.1.0

Demo – Version 1.0 >

#------------------------------------------------------------------------------#
#  Galv's Past Encounters
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.0
#  Requested by William C
#------------------------------------------------------------------------------#
#  2013-03-28 - version 1.0 - release
#------------------------------------------------------------------------------#
#  This script allows you to specify regions with random encounters that are
#  chosen from any previously defeated troop. A comment can be added to troops
#  that you do not wish to appear (such as bosses perhaps).
#------------------------------------------------------------------------------#
 
#------------------------------------------------------------------------------#
#  COMMENT - First troop event page
#------------------------------------------------------------------------------#
#
#  <no_past>   # Add a COMMENT with this tag on first troop event page if you
#              # do not wish that troop to appear in the past encounters
#
#------------------------------------------------------------------------------#
 
#------------------------------------------------------------------------------#
#  SCRIPT CALL
#------------------------------------------------------------------------------#
#
#  past_battle      # starts battle processing with a random past encounter
#
#------------------------------------------------------------------------------#
 
($imported ||= {})["Galvs_Past_Encounters"] = true
module Galv_PE
 
#------------------------------------------------------------------------------#
#  SETTINGS
#------------------------------------------------------------------------------#
 
  REGIONS = [60,61] # Regions that will encounter any previously defeated troop
 
#------------------------------------------------------------------------------#
#  END SETTINGS
#------------------------------------------------------------------------------#
 
end
 
class Game_Interpreter
  def past_battle
    return if $game_party.in_battle
    troop_id = $game_player.make_past_encounter_troop_id
    if $data_troops[troop_id]
      BattleManager.setup(troop_id, @params[2], @params[3])
      BattleManager.event_proc = Proc.new {|n| @branch[@indent] = n }
      $game_player.make_encounter_count
      SceneManager.call(Scene_Battle)
    end
    Fiber.yield
  end
end # Game_Interpreter
 
class Game_Player < Game_Character
  alias galv_past_enc_gp_make_encounter_troop_id make_encounter_troop_id
  def make_encounter_troop_id
    if Galv_PE::REGIONS.include?($game_map.region_id(@x, @y))
      return make_past_encounter_troop_id
    end
    galv_past_enc_gp_make_encounter_troop_id
  end
 
  def make_past_encounter_troop_id
    return 0 if $game_system.past_encounters.empty?
    return $game_system.past_encounters.sample
  end
end # Game_Player < Game_Character
 
class Game_System
  attr_accessor :past_encounters
 
  alias galv_past_enc_gs_initialize initialize
  def initialize
    @past_encounters = []
    galv_past_enc_gs_initialize
  end
end # Game_System
 
class Game_Troop < Game_Unit
  attr_reader :troop_id
end # Game_Troop < Game_Unit
 
module BattleManager
  class << self
    alias galv_past_enc_bm_process_victory process_victory
  end
 
  def self.process_victory
    past = true
    $data_troops[$game_troop.troop_id].pages[0].list.each { |cmd|
      if cmd.code == 108 && cmd.parameters.include?("<no_past>")
        past = false
        break
      end
    }
    if !$game_system.past_encounters.include?($game_troop.troop_id) && past
      $game_system.past_encounters << $game_troop.troop_id
    end
    galv_past_enc_bm_process_victory
  end
end # BattleManager

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s