=begin #=============================================================================== Title: Random Encounter Events Author: Hime Date: Jul 12, 2015 URL: http://himeworks.com/2015/01/random-encounter-events/ -------------------------------------------------------------------------------- ** Change log Jul 12, 2015 - copy screen tone after common nevent is run Jan 24, 2015 - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script allows you to run a common event when you encounter an enemy through "random encounter". When the common event finishes executing, the random encounter battle will begin. In this common event, you have the opportunity to run some extra logic before the battle occurs. The enemy troop that you will battle is available, and you can use this information in your event. For example, you may choose to display a message if a certain troop is encountered. This script provides a special command that allows you to "cancel" the encounter, allowing you to create mechanics that allow players to skip encounters if they do not wish to battle. -------------------------------------------------------------------------------- ** Installation In the script editor, place this script below Materials and above Main -------------------------------------------------------------------------------- ** Usage In the configuration, you can choose a variable that you will use to determine which common event to run. This allows you to change the common event during the game if necessary. The enemy troop that is encountered can be accessed using script calls in your conditional branch or sript call box by referencing $game_troop If you would like to cancel the random encounter, use the script call cancel_encounter And the encounter will be canceled #=============================================================================== =end $imported = {} if $imported.nil? $imported[:TH_RandomEncounterEvents] = true #=============================================================================== # ** Configuration #=============================================================================== module TH module Random_Encounter_Events # The number stored in this variable is the ID of the common event that # will run when you encounter an enemy. Variable = 1 end end #=============================================================================== # ** Rest of the script #=============================================================================== class Scene_Map < Scene_Base alias :th_random_encounter_events_update_encounter :update_encounter def update_encounter if $game_player.encounter && !$game_player.pending_encounter $game_player.pending_encounter = true $game_temp.reserve_common_event($game_variables[TH::Random_Encounter_Events::Variable]) $game_map.setup_starting_event update while $game_map.interpreter.running? $game_troop.init_screen_tone th_random_encounter_events_update_encounter $game_player.pending_encounter = false end end end class Game_Player < Game_Character attr_accessor :pending_encounter alias :th_random_encounter_events_initialize :initialize def initialize th_random_encounter_events_initialize @pending_encounter = false end alias :th_random_encounter_events_encounter :encounter def encounter return true if $game_player.pending_encounter th_random_encounter_events_encounter end end class Game_Interpreter def cancel_encounter $game_player.pending_encounter = false end end