Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Preemptive-Surprise Event Battle
- # by: Jeneeus Guruman
- #------------------------------------------------------------------------------
- # This script allows to make evented encounters have preemptive and
- # surprise encounters.
- #
- # How to use:
- #
- # * Plug-n-play
- # * Place this below default and most non-aliased scripts.
- # * Not compatible and has problems with the following:
- # - Any 8-directional movement scripts
- # - Any pixel movement scripts
- # * Not recommended if followers are shown.
- # * "Encounter Half" and "Encounter None" party abilities do not work for
- # evented encounters but "Raise Preemptive" and "Cancel Surprise" does work.
- #
- #==============================================================================
- module Jene
- #--------------------------------------------------------------------------
- # * PREEMPTIVE_SIDE_CHANCE
- # The percent chance of having a preemtive encounter occured when
- # going to the evented enemy's side. Putting any negative number will use
- # the default formula for preemptive attack.
- #--------------------------------------------------------------------------
- PREEMPTIVE_SIDE_CHANCE = -1
- #--------------------------------------------------------------------------
- # * SURPRISE_SIDE_CHANCE
- # The percent chance of having a surprised encounter occured when enemies
- # are going to the character's side. Putting any negative number will use
- # the default formula for surprise attack.
- #--------------------------------------------------------------------------
- SURPRISE_SIDE_CHANCE = -1
- #--------------------------------------------------------------------------
- # * PREEMPTIVE_SURPRISE_SWITCH
- # The switch that will enable to use the preemptive-surprise function.
- # Making the value 0 will make it always enabled. Making the value negative
- # will disable it instead when turning on.
- #--------------------------------------------------------------------------
- PREEMPTIVE_SURPRISE_SWITCH = 0
- #--------------------------------------------------------------------------
- # * PREEMPTIVE_SURPRISE_AFFIX
- # The affix name of the event that will enable to use the
- # preemptive-surprise function.
- #--------------------------------------------------------------------------
- PREEMPTIVE_SURPRISE_AFFIX = "[enemy]"
- #--------------------------------------------------------------------------
- # * PREEMPTIVE_SURPRISE_TANKENTAI
- # Always enable this if you are using the Tankentai Ace script and
- # always disable this if otherwise. Not doing so will cause problems.
- #--------------------------------------------------------------------------
- PREEMPTIVE_SURPRISE_TANKENTAI = false
- end
- #----------------------------------------------------------------------------
- # * Do not edit anything below here. Or else, evil errors will be released
- # from the other dimension of evil.
- #----------------------------------------------------------------------------
- #==============================================================================
- # ** BattleManager
- #------------------------------------------------------------------------------
- # This module manages battle progress.
- #==============================================================================
- module BattleManager
- class <<self
- alias jene_pseb_on_encounter on_encounter
- alias jene_pseb_battle_end battle_end
- end
- #--------------------------------------------------------------------------
- # * Processing at Encounter Time
- #--------------------------------------------------------------------------
- def self.on_encounter
- if Jene::PREEMPTIVE_SURPRISE_SWITCH > 0
- psbe_enable = $game_switches[Jene::PREEMPTIVE_SURPRISE_SWITCH]
- elsif Jene::PREEMPTIVE_SURPRISE_SWITCH < 0
- psbe_enable = !$game_switches[-Jene::PREEMPTIVE_SURPRISE_SWITCH]
- else
- psbe_enable = true
- end
- if psbe_enable
- @preemptive = $game_temp.ps_num > 0
- @surprise = $game_temp.ps_num < 0
- else
- jene_pseb_on_encounter
- end
- if Jene::PREEMPTIVE_SURPRISE_TANKENTAI
- $sv_camera.mirror = @surprise if N03::BACK_ATTACK
- end
- end
- #--------------------------------------------------------------------------
- # * End Battle
- # result : Result (0: Win 1: Escape 2: Lose)
- #--------------------------------------------------------------------------
- def self.battle_end(result)
- $game_temp.ps_num = 0
- jene_pseb_battle_end(result)
- end
- end
- #==============================================================================
- # ** Game_Temp
- #------------------------------------------------------------------------------
- # This class handles temporary data that is not included with save data.
- # The instance of this class is referenced by $game_temp.
- #==============================================================================
- class Game_Temp
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :ps_num # Number indicator for encounters
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- alias jene_pseb_temp_initialize initialize
- def initialize
- jene_pseb_temp_initialize
- @ps_num = 0
- end
- end
- #==============================================================================
- # ** Game_CharacterBase
- #------------------------------------------------------------------------------
- # This base class handles characters. It retains basic information, such as
- # coordinates and graphics, shared by all characters.
- #==============================================================================
- class Game_CharacterBase
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :prev_direction # Previous Direction
- #--------------------------------------------------------------------------
- # * Initialize Public Member Variables
- #--------------------------------------------------------------------------
- alias jene_pseb_init_public_members init_public_members
- def init_public_members
- jene_pseb_init_public_members
- @prev_direction = 2
- end
- #--------------------------------------------------------------------------
- # * Change Direction to Designated Direction
- # d : Direction (2,4,6,8)
- #--------------------------------------------------------------------------
- def set_direction(d)
- @prev_direction = @direction if !@direction_fix && @direction != 0
- @direction = d if !@direction_fix && d != 0
- @stop_count = 0
- end
- end
- #==============================================================================
- # ** Game_Event
- #------------------------------------------------------------------------------
- # This class handles events. Functions include event page switching via
- # condition determinants and running parallel process events. Used within the
- # Game_Map class.
- #==============================================================================
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :event # Event
- #--------------------------------------------------------------------------
- # alias method: update_self_movement
- #--------------------------------------------------------------------------
- alias jene_pseb_update_self_movement update_self_movement
- def update_self_movement
- return if $game_map.interpreter.running? && @event.name.include?(Jene::PREEMPTIVE_SURPRISE_AFFIX)
- jene_pseb_update_self_movement
- end
- end
- #==============================================================================
- # ** Game_Follower
- #------------------------------------------------------------------------------
- # This class handles followers. A follower is an allied character, other than
- # the front character, displayed in the party. It is referenced within the
- # Game_Followers class.
- #==============================================================================
- class Game_Follower < Game_Character
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- alias jene_pseb_follower_initialize initialize
- def initialize(member_index, preceding_character)
- jene_pseb_follower_initialize(member_index, preceding_character)
- #@priority_type = 0
- end
- end
- #==============================================================================
- # ** Game_Interpreter
- #------------------------------------------------------------------------------
- # An interpreter for executing event commands. This class is used within the
- # Game_Map, Game_Troop, and Game_Event classes.
- #==============================================================================
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # * Battle Processing
- #--------------------------------------------------------------------------
- alias jene_pseb_command_301 command_301
- def command_301
- if Jene::PREEMPTIVE_SURPRISE_SWITCH > 0
- psbe_enable = $game_switches[Jene::PREEMPTIVE_SURPRISE_SWITCH]
- elsif Jene::PREEMPTIVE_SURPRISE_SWITCH < 0
- psbe_enable = !$game_switches[-Jene::PREEMPTIVE_SURPRISE_SWITCH]
- else
- psbe_enable = true
- end
- if psbe_enable
- return if $game_party.in_battle
- if @params[0] == 0 # Direct designation
- troop_id = @params[1]
- elsif @params[0] == 1 # Designation with variables
- troop_id = $game_variables[@params[1]]
- else # Map-designated troop
- troop_id = $game_player.make_encounter_troop_id
- end
- if $data_troops[troop_id]
- preemptive_or_surprise
- BattleManager.setup(troop_id, @params[2], @params[3])
- BattleManager.event_proc = Proc.new {|n| @branch[@indent] = n }
- BattleManager.on_encounter
- $game_player.make_encounter_count
- SceneManager.call(Scene_Battle)
- end
- Fiber.yield
- else
- jene_pseb_command_301
- end
- end
- #--------------------------------------------------------------------------
- # * Battle Processing
- #--------------------------------------------------------------------------
- def preemptive_or_surprise
- enemy = get_character(0)
- player = get_character(-1)
- return unless enemy.event.name.include?(Jene::PREEMPTIVE_SURPRISE_AFFIX)
- if player.direction == enemy.prev_direction
- case player.direction
- when 2
- if player.y < enemy.y; $game_temp.ps_num = 1; end
- when 4
- if player.x > enemy.x; $game_temp.ps_num = 1; end
- when 6
- if player.x < enemy.x; $game_temp.ps_num = 1; end
- when 8
- if player.y > enemy.y; $game_temp.ps_num = 1; end
- end
- end
- if player.direction == enemy.direction && !$game_party.cancel_surprise?
- case enemy.direction
- when 2
- if enemy.y < player.y; $game_temp.ps_num = -1; end
- when 4
- if enemy.x > player.x; $game_temp.ps_num = -1; end
- when 6
- if enemy.x < player.x; $game_temp.ps_num = -1; end
- when 8
- if enemy.y > player.y; $game_temp.ps_num = -1; end
- end
- end
- if 10 - player.direction != enemy.prev_direction
- if Jene::PREEMPTIVE_SIDE_CHANCE < 0
- chance = rand < $game_party.rate_preemptive($game_troop.agi)
- else
- chance = rand < Jene::PREEMPTIVE_SIDE_CHANCE / 100.to_f
- chance *= 4 if $game_party.raise_preemptive?
- end
- case player.direction
- when 2
- if player.y < enemy.y && chance; $game_temp.ps_num = 1; end
- when 4
- if player.x > enemy.x && chance; $game_temp.ps_num = 1; end
- when 6
- if player.x < enemy.x && chance; $game_temp.ps_num = 1; end
- when 8
- if player.y > enemy.y && chance; $game_temp.ps_num = 1; end
- end
- end
- if 10 - enemy.direction != player.direction && !$game_party.cancel_surprise?
- if Jene::SURPRISE_SIDE_CHANCE < 0
- chance = rand < $game_party.rate_surprise($game_troop.agi)
- else
- chance = rand < Jene::SURPRISE_SIDE_CHANCE / 100.to_f
- end
- case enemy.direction
- when 2
- if player.y > enemy.y && chance; $game_temp.ps_num = -1; end
- return
- when 4
- if player.x < enemy.x && chance; $game_temp.ps_num = -1; end
- return
- when 6
- if player.x > enemy.x && chance; $game_temp.ps_num = -1; end
- return
- when 8
- if player.y < enemy.y && chance; $game_temp.ps_num = -1; end
- return
- end
- end
- end
- end
RAW Paste Data