Random Encounter transfers player

I was wondering if its possible that when a player random encounter in a map they would transfer to another. I want it that when the player encounters enemy Slime in  map 001 they get transfered to map 002 without fighting the slime. I saw something like this

Spoiler
 class Scene_Map
  def call_battle
    # Configure here:
    mapID = 2;  mapX = 0;  mapY = 0;
    # Configure above ^^
    @spriteset.update
    Graphics.update
    Sound.play_battle_start
    $game_temp.next_scene = nil
    $game_player.reserve_transfer(mapID, mapX, mapY, 2)
  end
end
but I'm not sure how to make it work. 
I think the easiest way is to use a combination of scripting and eventing.


1) In the troop, make a troop event that stores a target map ID into a variable depending on which troop was encountered (or whatever you want as conditions)


2) In the script calculating battle aftermath and rewards, have a $Game_switch turned on for "After battle Processing"


3) Create a common event, set it to parallel process, condition it to the "After-Battle-Processing"-Switch.


4) In the event, check what the battle was, transfer the player depending on the variables set by the troop event and turn the after-battle-switch off again.


I'm assuming that you know how to find the line for 2 and script it yourself. Otherwise have someone post here where to add that line - I'm currently short on time, can't look for it myself now.
Hmm, seems fairly straightforward. I'll poke around at creating a tiny scriptlet.

EDIT : The following code should allow you to choose which enemies teleport the player to another area.

Spoiler
Code:
module Troop_Hijack    TROOPS   ={=begin#   ▄ Start Copy ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄    # Database ID of the Troop    1 => {    # Transfer Information      :map_id   => 3,    :x => 10,    :y => 10,    :direction => 2    },    ▄ End Copy ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄=end#   ▄ Troop Settings (Paste Here) ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄    # Database ID of the Troop (Example - Slime)    1 => {    # Transfer Information (Map 3 @ x10, y10 | Facing Down)      :map_id   => 3,    :x => 10,    :y => 10,    :direction => 2    },#   ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄    }    def self.transfer(troop_id)    $game_player.reserve_transfer(*TROOPS[troop_id].values)    $game_temp.fade_type   = 0    $game_map.need_refresh = true  end  end#==============================================================================# ** Game_Player#==============================================================================class Game_Player < Game_Character  #--------------------------------------------------------------------------  # * Object Initialization  #--------------------------------------------------------------------------  unless method_defined?(:ex_gp_091713_initialize)    alias_method(:ex_gp_091713_initialize, :initialize)  end    def initialize(*args, &block)    ex_gp_091713_initialize(*args, &block)        @encounter_id = 0  end    #--------------------------------------------------------------------------  # * Create Group ID for Troop Encountered  #--------------------------------------------------------------------------  unless method_defined?(:ex_gp_091713_make_encounter_troop_id)    alias_method(:ex_gp_091713_make_encounter_troop_id, :make_encounter_troop_id)  end    def make_encounter_troop_id(*args, &block)    @encounter_id = ex_gp_091713_make_encounter_troop_id(*args, &block)    @encounter_id  end    #--------------------------------------------------------------------------  # * Execute Encounter Processing  #--------------------------------------------------------------------------  unless method_defined?(:ex_gp_091713_encounter)    alias_method(:ex_gp_091713_encounter, :encounter)  end  def encounter(*args, &block)    begin      encounter_boolean = ex_gp_091713_encounter(*args, &block)    ensure      if encounter_boolean && !Troop_Hijack::TROOPS.fetch(@encounter_id, nil).nil?        (Troop_Hijack.transfer(@encounter_id); $game_troop.clear; return false)      end    end    endend
For the slime troop create an event that runs at the beginning of the battle that turns on a switch.


Then have an auto-run common event (condition on that switch) transfer the player to a particular map/position.


You can have the slime troop set some variables if you want to transfer by variable designation.

Original thread: https://forums.rpgmakerweb.com/threads/random-encounter-transfers-player.18180/