Teleport to Visited sites

newold

Villager
Member
Joined
Oct 12, 2018
Messages
11
Reaction score
13
First Language
spanish
Primarily Uses
N/A

Script Name: TeleportToVisited

Author: Newold

Description: With this script you can make a window appear that
allows you to teleport to any map you have visited before.
You can also store different teleport points on each map.

Version: 1.4 - 10-01-2019

Credits and License: You can use this script as you want. It is free for comercial and not comercial projects. You can give me thanks in the credits of your game or not, as you wish



**************************************************************************
Installation and use
**************************************************************************
⚫ INSTALLATION

- Put this script over main

- You need to download these images and unzip them in the folder
"Graphics/Pictures"
Link: https://www.mediafire.com/file/n7bv66tbdr7cj3m/TeleportImages.rar/file] (Downloads images from mediafire)

- you can configure this script below this instructions

⚫ HOW TO USE

- When you visited a map, this map is added automatically to the
teleport's list.
If you do not want the map to be added automatically, you need
to create an empty event on that map and name it
⇒⇒⇒⇒ noAddToTeleportList ⇐⇐⇐⇐

··········································································

- To add a teleport point manually, use the command call script of
the events and inside you put this code:

add_map(ref, name, map_id, x, y, direction)

● ref ▶ Can be a number (Ex: 1), a string (Ex: "name") or
symbol :)symbol)
ref is used to identify this teleport.
● name ▶ Only can be a string (Ex: "name")
name is used to name this teleport.
● map_id ▶ it can be nil (current map) or a number.
map_id refers to the id of the map.
● x ▶ it can be nil (current position X of player)
or a number.
● y ▶ it can be nil (current position Y of player)
or a number.
● direction ▶ it can be nil (current direction of player)
or a number. (2 = Down, 4 = Left, 6 = Right, 8 = Up)

··········································································

- To modify a parameter of a teleport point already added, use the
command call script of the events and inside you put this code:

update_map_info(map_id, attr, value, ref)

● map_id ▶ it is a number. map_id refers to the id of the map.
● attr ▶ name of the parameter to modify
(including the two points)
attr only can be :x, :y, :direction or :map_name
● :x ▶ Use :x to modify the
X coordinate of teleport
● :y ▶ Use :y to modify the
Y coordinate of teleport
● :direction ▶ Use :direction to modify where
the character will look when
teleporting
● :map_name ▶ Use :map_name to change the name
of teleport
● value ▶ It must be a text between quotation marks to modify
the value of :map_name (example "my text") or a number
to modify the other values
● ref ▶ Can be a number (Ex: 1), a string (Ex: "name") or
symbol :)symbol)

··········································································

- To show the teleport selection window, use the command call script
of the events and inside you put this code:

open_teleport

··········································································
**************************************************************************


⚫ SCRIPT

Code:
#===============================================================================
class TeleportToVisited

=begin

      **************************************************************************
      Script Name:  TeleportToVisited
     
      Author:       Newold
     
      Description:  With this script you can make a window appear that
                    allows you to teleport to any map you have visited before.
                    You can also store different teleport points on each map.
                   
      Version:      1.4 - 10-01-2019
     
      License and   You can use this script as you want. 
      Credits       It is free for comercial and not comercial projects.
                    You can give me thanks in the credits of your game or not,
                    as you wish.
   
      History / Updates:
        ▼ 10-01-2019 - Fixed "stack to deep" bug
        ▼ 09-01-2019 - You can now to postpone teleport and do it manually.
        ▼ 09-01-2019 - You can now disable/enable last teleport used
                      (default = false)
        ▼ 08-01-2019 - Now you can add teleports to any map from any map
        ▼ 07-01-2019 - Release Day.
      **************************************************************************
   
   
      **************************************************************************
                            Installation and use
      **************************************************************************
      ⚫ INSTALLATION
     
      - Put this script over main
     
      - You need to download these images and unzip them in the folder
        "Graphics/Pictures"
        Link: Download images from mediafire (you need unzip):
          https://www.mediafire.com/file/n7bv66tbdr7cj3m/TeleportImages.rar/file
       
      - you can configure this script below this instructions
     
      ⚫ HOW TO USE
     
      - When you visited a map, this map is added automatically to the
        teleport's list.
        If you do not want the map to be added automatically, you need
        to create an empty event on that map and name it
        ⇒⇒⇒⇒              noAddToTeleportList            ⇐⇐⇐⇐
     
      ··········································································
     
      - To add a teleport point manually, use the command call script of
        the events and inside you put this code:
       
        add_map(ref, name, map_id, x, y, direction)
       
          ● ref         ▶ Can be a number (Ex: 1), a string (Ex: "name") or
                          symbol (:symbol)
                          ref is used to identify this teleport.
          ● name        ▶ Only can be a string (Ex: "name")
                          name is used to name this teleport.
          ● map_id      ▶ it can be nil (current map) or a number.
                          map_id refers to the id of the map.
          ● x           ▶ it can be nil (current position X of player)
                          or a number.
          ● y           ▶ it can be nil (current position Y of player)
                          or a number.
          ● direction   ▶ it can be nil (current direction of player)
                          or a number. (2 = Down, 4 = Left, 6 = Right, 8 = Up)
                         
      ··········································································
     
      - To modify a parameter of a teleport point already added, use the
        command call script of the events and inside you put this code:
       
        update_map_info(map_id, attr, value, ref)
       
          ● map_id      ▶ it is a number. map_id refers to the id of the map.
          ● attr        ▶ name of the parameter to modify
                          (including the two points)
                          attr only can be :x, :y, :direction or :map_name
                              ● :x          ▶ Use :x to modify the
                                              X coordinate of teleport
                              ● :y          ▶ Use :y to modify the
                                              Y coordinate of teleport
                              ● :direction  ▶ Use :direction to modify where
                                              the character will look when
                                              teleporting
                              ● :map_name   ▶ Use :map_name to change the name
                                              of teleport
          ● value       ▶ It must be a text between quotation marks to modify
                          the value of :map_name (example "my text") or a number
                          to modify the other values
          ● ref         ▶ Can be a number (Ex: 1), a string (Ex: "name") or
                          symbol (:symbol)
                         
      ··········································································
     
      - To show the teleport selection window, use the command call script
        of the events and inside you put this code:
       
        open_teleport
       
      - If you want to postpone the teleport and activate a switch instead to
        create some engine, you need put config @@config[:pospone_teleport] in
        true and define switch in @@config[:activate_switch]. Then you can
        create any engine in your game and finally teleport using the command
        call script of the events and inside you put this code:
       
        perform_teleport
       
      ··········································································
      **************************************************************************
=end


   
  #=============================================================================
  #             ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼ CONFIGURATION ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  #=============================================================================
  @@config = {}
  # ············································································
  #                   images (in folder Graphics/Pictures)
  # ············································································
  # Image of cursor (hand)
  @@config[:cursor1] = "cursor001"
  # Image of cursor (selector)
  @@config[:cursor2] = "cursor002"
  # Image of cursor (current map)
  @@config[:cursor3] = "cursor003"
  # Pattern for window
  @@config[:window_pattern] = "window001"
  # ············································································
 
 
 
  # ············································································
  #                     Sounds (in folder Audio/SE)
  # ············································································
  # Cursor movement
  @@config[:cursor_se] = {
    :name     => "Cursor1",
    :volume   => 75,
    :pitch    => 100
  }
  # Decision (OK)
  @@config[:decision_se] = {
    :name     => "Decision2",
    :volume   => 75,
    :pitch    => 100
  }
  # Error (Buzzer)
  @@config[:buzzer_se] = {
    :name     => "Buzzer1",
    :volume   => 75,
    :pitch    => 100
  }
  # Cancel
  @@config[:cancel_se] = {
    :name     => "Cancel1",
    :volume   => 75,
    :pitch    => 100
  }
  # Teleport
  @@config[:teleport_se] = {
    :name     => "Teleport",
    :volume   => 75,
    :pitch    => 100
  }
  # ············································································
 
 
 
  # ············································································
  #                         Window Config
  # ············································································
  # Width window
  @@config[:window_width] = 240
  # Height window
  @@config[:window_height] = 160
  # Show displacement bar
  @@config[:show_displacement_bar] = true
  # Draw background stretched
  @@config[:stretch_background] = false
  # Config Font
  @@config[:font] = {
    :name                 => "Verdana",
    :size                 => 20,
    :color                => Color.new(255,255,255),
    :outline              => true,
    :out_color            => Color.new(0,0,0),
    :current_map_color    => Color.new(9,104,20)
  }
  # ············································································
 
    # ·········································································
    # Position Window
    # ·········································································
    # :top_left       > -------------------------------------------------------
    # :top            >
    # :top_right      >
    # :left           >
    # :screen_center  >                       screen
    # :right          >
    # :bottom_left    >
    # :bottom         >
    # :bottom_right   > -------------------------------------------------------
   
    # :center_top     > -------------------------------------------------------
    # :center_left    >
    # :center_right   >                      character
    # :center_bottom  >
    # :center         > -------------------------------------------------------
   
    # Point           > Fixed point (Point.new(x, y))
    # ·········································································
    @@config[:window_position] = :center_left
    # ·········································································
  # ············································································
 
 
   
  # ············································································
  # Other Config
  # ············································································
  # Suavize animation (show / hide window)
  @@config[:animation_suavize] = 8
  # Screen margin for window
  @@config[:screen_margin] = 10
  # Disable same teleport than current map
  # (last teleport is disabled. It enable when change teleport)
  @@config[:disable_last_teleport] = false
  # Postpone teleportation and activate switch
  @@config[:pospone_teleport] = false
  # switch to activate when success teleport. If you use
  # @@config[:pospone_teleport], this switch is activated instead of teleport
  # player. You must manually teleport the player using this command:
  # $TeleportToVisited.perform_teleport
  @@config[:activate_switch] = 100 
  # ············································································
 
 
  #=============================================================================
  #           ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲ END CONFIGURATION ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
  #=============================================================================
 
 
 
  #=============================================================================
  class Point
    attr_accessor :x, :y
    def initialize(x=0, y=0)
      @x, @y = x, y
    end
  end
  #=============================================================================
  class Data
    attr_accessor :x, :y, :direction, :map_name, :map_id, :ref
  end
  #=============================================================================
 
  #-----------------------------------------------------------------------------
  attr_reader :data
  #-----------------------------------------------------------------------------
  def initialize
    @data = []
    @drawed = []
    @current_map = nil
    @index = 0
    @cursor_animation_index = 0
    @cursor_animation = [-1, 0, 0, -1, -1, 0, 1, 0, 0, 1, 0, 0, 1]
    @arrows_animation_index = 0
    @arrows_animation = [-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0]
    @bar_displacement = 0
    @show_displacement_bar = true
    create_cursor
    create_window
  end
  #-----------------------------------------------------------------------------
  def create_cursor
    @cursor = Sprite.new
    @cursor.bitmap = Cache.picture(@@config[:cursor1])
    @cursor.z = 10000020
    @cursor.opacity = 0
    @cursor.visible = false
  end
  #-----------------------------------------------------------------------------
  def create_window
    src_rects = get_rects
   
    bitmap = Cache.picture(@@config[:window_pattern])
    transparent = Color.new(0,0,0,0)
   
    viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
    viewport.z = 500
    @window = Sprite.new(viewport)
    @window.x = 200
    @window.y = 100
    @window.bitmap = Bitmap.new(@@config[:window_width],
      @@config[:window_height])
    @window.ox = @window.width / 2
    @window.oy = @window.height / 2
    # Draw borders
    # ··············································
    # Left
    rect = src_rects[:left]
    h1 = src_rects[:top_left].height
    h2 = src_rects[:bottom_left].height
    rect2 = Rect.new(0, h1, rect.width, @window.height - h1 - h2)
    draw_window_part(bitmap, rect, rect2)
    # ··············································
    # Right
    rect = src_rects[:right]
    h1 = src_rects[:top_right].height
    h2 = src_rects[:bottom_right].height
    rect2 = Rect.new(@window.width - rect.width,
      h1, rect.width, @window.height - h1 - h2)
    draw_window_part(bitmap, rect, rect2)
    # ··············································
    # Top
    rect = src_rects[:top]
    w1 = src_rects[:top_left].width
    w2 = src_rects[:top_right].width
    rect2 = Rect.new(w1, 0, @window.width - w1 - w2, rect.height)
    draw_window_part(bitmap, rect, rect2)
    # ··············································
    # Bottom
    rect = src_rects[:bottom]
    w1 = src_rects[:bottom_left].width
    h2 = src_rects[:bottom_right].width
    rect2 = Rect.new(w1, @window.height - rect.height,
    @window.width - w1 - w2, rect.height)
    draw_window_part(bitmap, rect, rect2)
    # ··············································
    # Center and contents
    rect = src_rects[:center]
    x = src_rects[:top_left].width
    y = src_rects[:top_left].height
    w = @window.width - x - src_rects[:top_right].width
    h = @window.height - y - src_rects[:bottom_right].height
    rect2 = Rect.new(x, y, w, h)
    draw_window_part(bitmap, rect, rect2)
    # ··············································
    # Corner Top Left
    rect = src_rects[:top_left]
    x = 0
    y = 0
    draw_window_part_corner(bitmap, x, y, rect, transparent)
    # ··············································
    # Corner Top Right
    rect = src_rects[:top_right]
    x = @window.width - rect.width
    y = 0
    draw_window_part_corner(bitmap, x, y, rect, transparent)
    # ··············································
    # Corner Bottom Left
    rect = src_rects[:bottom_left]
    x = 0
    y = @window.height - rect.height
    draw_window_part_corner(bitmap, x, y, rect, transparent)
    # ··············································
    # Corner Bottom Right
    rect = src_rects[:bottom_right]
    x = @window.width - rect.width
    y = @window.height - rect.height
    draw_window_part_corner(bitmap, x, y, rect, transparent)
    # ··············································
    @window.z = 10000000
    # ··············································
   
    x = @window.x - @window.ox + src_rects[:top_left].width
    y = @window.y - @window.oy + src_rects[:top_left].height
    @viewport = Viewport.new(x, y, w, h)
    @viewport.z = 1000
   
    @contents = Sprite.new(@viewport)
    @bar_background = Sprite.new(@viewport)
    @bar_top = Sprite.new(@viewport)
    @selector = Sprite.new(@viewport)
   
    @contents.z = 100
    @selector.z = 150
    @bar_background.z = 200
    @bar_top.z = 250
   
    @arrow_top = Sprite.new
    rect = src_rects[:arrow_top]
    @arrow_top.bitmap = Bitmap.new(rect.width, rect.height)
    @arrow_top.bitmap.blt(0, 0, bitmap, rect)
    @arrow_bottom = Sprite.new
    rect = src_rects[:arrow_bottom]
    @arrow_bottom.bitmap = Bitmap.new(rect.width, rect.height)
    @arrow_bottom.bitmap.blt(0, 0, bitmap, rect)
    @arrow_top.z = 10000050
    @arrow_bottom.z = 10000050
   
    @window.visible           =         @contents.visible   =
    @bar_background.visible   =         @bar_top.visible    = false
   
    @window.opacity           =         @contents.opacity   =
    @bar_background.opacity   =         @bar_top.opacity    =
    @window.zoom_x            =         @contents.zoom_x    =
    @bar_background.zoom_x    =         @bar_top.zoom_x     =
    @window.zoom_y            =         @contents.zoom_y    =
    @bar_background.zoom_y    =         @bar_top.zoom_y     = 0

    @selector.visible = @arrow_top.visible = @arrow_bottom.visible = false
  end
  #-----------------------------------------------------------------------------
  def draw_window_part(bitmap, rect1, rect2)
    if @@config[:stretch_background] == true
      @window.bitmap.stretch_blt(rect2, bitmap, rect1)
    else
      w1 = rect1.width
      h1 = rect1.height
      w2 = rect2.width
      h2 = rect2.height
      mx = [(w2 / w1.to_f).ceil, 1].max
      my = [(h2 / h1.to_f).ceil, 1].max
      for i in 0...mx
        for j in 0...my
          x = rect2.x + i*w1
          y = rect2.y + j*h1
          @window.bitmap.blt(x, y, bitmap, rect1)
        end
      end
    end
  end
  #-----------------------------------------------------------------------------
  def draw_window_part_corner(bitmap, x, y, rect, fill_color)
    @window.bitmap.fill_rect(x, y, rect.width, rect.height, fill_color)
    @window.bitmap.blt(x, y, bitmap, rect)
  end
  #-----------------------------------------------------------------------------
  def get_rects
    rects = {
      :top_left         => Rect.new(0,0,8,8),
      :top              => Rect.new(8,0,8,8),
      :top_right        => Rect.new(16,0,8,8),
      :bottom_left      => Rect.new(0,16,8,8),
      :bottom           => Rect.new(8,16,8,8),
      :bottom_right     => Rect.new(16,16,8,8),
      :left             => Rect.new(0,8,8,8),
      :right            => Rect.new(16,8,8,8),
      :center           => Rect.new(8,8,8,8),
      :arrow_top        => Rect.new(24,0,8,4),
      :arrow_bottom     => Rect.new(24,4,8,4),
      :bar_background   => Rect.new(24,16,8,8),
      :bar_topA         => Rect.new(24,8,8,3),
      :bar_topB         => Rect.new(24,11,8,2),
      :bar_topC         => Rect.new(24,13,8,3)
    }
    rects
  end
  #-----------------------------------------------------------------------------
  def draw_displacement_bar(id)
    if @@config[:show_displacement_bar]
      bitmap = Cache.picture(@@config[:window_pattern])
      src_rects = get_rects
      case id
      when :background
        # Draw background
        unless @bar_background.bitmap.nil?
          @bar_background.bitmap.dispose
        end
        viewport = @viewport
        rect = src_rects[:bar_background]
        rect2 = Rect.new(0, 0, rect.width, viewport.rect.height)
        @bar_background.bitmap = Bitmap.new(rect2.width, rect2.height)
        ox = @bar_background.width / 2
        oy = @bar_background.height / 2
        @bar_background.ox = ox
        @bar_background.oy = oy
        @bar_background.bitmap.stretch_blt(rect2, bitmap, rect)
        @bar_background.x = viewport.rect.width - @bar_background.width + ox
        @bar_background.y = oy
      when :top
        # draw top
        unless @bar_top.bitmap.nil?
          @bar_top.bitmap.dispose
        end
        min_height = 25
        max_height = @contents.viewport.rect.height
        rows = max_height / @h
        extra_rows = @real_data.size - rows
        bar_height = (extra_rows <= 0) ? max_height :
          [[max_height / extra_rows, min_height].max, max_height].min
         
        if rows == @real_data.size-1 && bar_height == max_height
          bar_height = max_height * 0.9
        end
       
        @bar_top.bitmap = Bitmap.new(@bar_background.width, bar_height)
       
        rect1 = src_rects[:bar_topA]
        rect2 = Rect.new(0, 0, @bar_top.width, 3)
        @bar_top.bitmap.stretch_blt(rect2, bitmap, rect1)
       
        rect1 = src_rects[:bar_topB]
        rect2 = Rect.new(0, 3, @bar_top.width, bar_height - 6)
        @bar_top.bitmap.stretch_blt(rect2, bitmap, rect1)
       
        rect1 = src_rects[:bar_topC]
        rect2 = Rect.new(0, @bar_top.height - 3, @bar_top.width, 3)
        @bar_top.bitmap.fill_rect(rect2, Color.new(0,0,0,0))
        @bar_top.bitmap.stretch_blt(rect2, bitmap, rect1)
       
        @bar_top.ox, @bar_top.oy = @bar_top.width/2, @bar_top.height/2
        @bar_top.x = @bar_background.x
        @bar_top.y = @bar_background.y - @bar_background.oy + @bar_top.oy
       
        if @contents.height > @contents.viewport.rect.height
          h = extra_rows * @h.to_f
          h2 = (max_height - @bar_top.height)
          @bar_displacement = h2 / h
          @show_displacement_bar = true
        else
          @bar_displacement = 0
          @show_displacement_bar = false
        end
      end
    end
  end
  #-----------------------------------------------------------------------------
  def draw_contents(initial=false)
   
    data = []
    if initial
      @data.each{|d1|
        unless d1.nil?
          d1.each{|d2|
            unless d2.nil?
              data << d2
            end
          }
        end
      }
    else
      data = @real_data
    end
    b = Bitmap.new(1,1)
    font = Font.new
    font.name = @@config[:font][:name]
    font.size = @@config[:font][:size]
    font.outline = @@config[:font][:outline]
    font.color = @@config[:font][:color]
    font.out_color = @@config[:font][:out_color]
    b.font = font
    size = b.text_size("O")
    h = size.height * data.size
    w = @contents.viewport.rect.width
    if @show_displacement_bar == true || h > @contents.viewport.rect.height
      w -= @bar_background.width
    end
    if initial
      unless @contents.bitmap.nil?
        @contents.bitmap.dispose
      end
      @contents.bitmap = Bitmap.new(w, h)
      @contents.bitmap.font = font
      @h = size.height
    end
    iniData = @contents.viewport.oy / @h
    endData = [iniData + @contents.viewport.rect.height / @h, data.size].min
    for i in iniData..endData
      next unless @drawed[i].nil?
      d = data[i]
      break if d.nil?
      tw = @contents.bitmap.font.size
      y = i * @h
      mod = 0
      if d == @current_map && @@config[:disable_last_teleport] == true
        b2 = Cache.picture(@@config[:cursor3])
        ratio = b2.height / @h.to_f
        nw = [(b2.width * ratio).to_i,   1].max
        nh = [(b2.height * ratio).to_i,  1].max
        rect = Rect.new(w-nw, y, nw, nh)
        @contents.bitmap.stretch_blt(rect, b2, b2.rect)
        mod = rect.width
      end
      while @contents.bitmap.text_size(d.map_name).width - mod > w &&
        @contents.bitmap.font.size > 4
        @contents.bitmap.font.size -= 1
      end
      @contents.bitmap.font.color = (d == @current_map &&
        @@config[:disable_last_teleport] == true) ?
        @@config[:font][:current_map_color] : @@config[:font][:color]
      @contents.bitmap.draw_text(0, y, w, size.height, d.map_name)
      @contents.bitmap.font.size = tw
     
      @drawed[i] = true
    end
    ox = @contents.width / 2
    oy = @contents.height / 2
    @contents.ox = ox
    @contents.oy = oy
    @contents.x = ox
    @contents.y = oy
   
    if initial
      unless @selector.bitmap.nil?
        @selector.bitmap.dispose
      end
      @selector.bitmap = Bitmap.new(w, @h)
      bitmap = Cache.picture(@@config[:cursor2])
      @selector.bitmap.stretch_blt(@selector.bitmap.rect, bitmap, bitmap.rect)
      @selector.y = 0
      @selector.visible = true
      @selector.opacity = 0
      @real_data = data
    end
  end
  #-----------------------------------------------------------------------------
  def add_map(map_id, ref=nil, name=nil, x=nil, y=nil, direction=nil)
    if !FileTest.exist?(sprintf("Data/Map%03d.rvdata2", map_id))
      return
    end
    x = x.nil? ? $game_player.x : x.to_i rescue 0
    y = y.nil? ? $game_player.y : y.to_i rescue 0
    direction = direction.nil? ? $game_player.direction : direction.to_i rescue 0
    name = name.nil? ? $data_mapinfos[map_id].name : name.to_s
    if @data[map_id].nil?
      @data[map_id] ||= []
      data            = Data.new
      data.x          = x
      data.y          = y
      data.direction  = direction
      data.map_name   = name
      data.map_id     = map_id
      data.ref = ref
      @data[map_id] << data
      @current_map = data
    else
      add = true
      @data[map_id].each{|data|
        if data.ref == ref
          add = false
          break
        end
      }
      if add
        data            = Data.new
        data.x          = x
        data.y          = y
        data.direction  = direction
        data.map_name   = name
        data.map_id     = map_id
        data.ref = ref
        @data[map_id] << data
        @current_map = data
      end
    end
  end
  #-----------------------------------------------------------------------------
  def update_map_info(map_id, attr, value, ref=nil) 
    unless @data[map_id].nil?
      data = nil
      @data[map_id].each{|data2|
        next if data2.nil? || data2.ref != ref
        data = data2
        break
      }
      unless data.nil?
        begin
          eval("data.#{attr} = value")
        rescue
        end
      end
    end
  end
  #-----------------------------------------------------------------------------
  def show_window(x=0, y=0)
    if @window.disposed?
      dispose
      create_cursor
      create_window
    end
    @drawed.clear
    draw_displacement_bar(:background)
    draw_contents(true)
    draw_displacement_bar(:top)
    fix_position(x, y)
    mod = @@config[:animation_suavize]
    opacity = 255.0 / mod
    zoom = 1.0 / mod
    @viewport.ox = @viewport.oy = @index = 0
    update_index(0)
    data1 = [@cursor, @selector, @arrow_top, @arrow_bottom]
    data2 = [@window, @contents, @bar_background, @bar_top]
    data2.each{|s| s.visible = true}
    if !@show_displacement_bar
      @bar_background.visible = @bar_top.visible = false
    end
    while mod > 0
      data2.each{|s|
        s.opacity += opacity
        s.zoom_x += zoom
        s.zoom_y += zoom
      }
      Graphics.update
      mod -= 1
    end
    data1.each{|s|
      s.visible = true
      s.opacity = 255
    }
    update_pos_cursor
    @index = 0
    @cursor_animation_index = 0
    main
  end
  #-----------------------------------------------------------------------------
  def fix_position(x, y)
    ox, oy, w, h = @window.ox, @window.oy, @window.width, @window.height
    smx, smy = Graphics.width / 2, Graphics.height / 2
    margin = @@config[:screen_margin]
    case @@config[:window_position]
    when :top_left
      @window.x = margin + ox
      @window.y = margin + oy
    when :top
      @window.x = smx - w/2 + ox
      @window.y = margin + oy
    when :top_right
      @window.x = Graphics.width - margin - w + ox
      @window.y = margin + @window.oy
    when :left
      @window.x = margin + ox
      @window.y = smy - h/2 + oy
    when :screen_center
      @window.x = smx - w/2 + ox
      @window.y = smy - h/2 + oy
    when :right
      @window.x = Graphics.width - margin - w + ox
      @window.y = smy - h/2 + oy
    when :bottom_left
      @window.x = margin + ox
      @window.y = Graphics.height - margin - h + oy
    when :bottom
      @window.x = smx - w/2 + ox
      @window.y = Graphics.height - margin - h + oy
    when :bottom_right
      @window.x = Graphics.width - margin - w + ox
      @window.y = Graphics.height - margin - h + oy
    when :center_top
      @window.x = x
      @window.y = y - h + oy - 32
    when :center_bottom
      @window.x = x
      @window.y = y + oy
    when :center_left
      @window.x = x - w + ox - 16
      @window.y = y - 13
    when :center_right
      @window.x = x + ox + 16
      @window.y = y - 13
    when Point
      @window.x = @@config[:window_position].x + ox
      @window.y = @@config[:window_position].y + oy
    else
      @window.x = x + 16
      @window.y = y - 13
    end
    if @window.x - ox < @@config[:screen_margin]
      @window.x = @@config[:screen_margin] + ox
    end
    if @window.y - oy < @@config[:screen_margin]
      @window.y = @@config[:screen_margin] + oy
    end
    if @window.x + ox > Graphics.width - @@config[:screen_margin]
      @window.x = Graphics.width - @@config[:screen_margin] - w + ox
    end
    if @window.y + oy > Graphics.height - @@config[:screen_margin]
      @window.y = Graphics.height - @@config[:screen_margin] - h + oy
    end
    src_rects = get_rects
    x = @window.x - @window.ox + src_rects[:top_left].width
    y = @window.y - @window.oy + src_rects[:top_left].height
    @viewport.rect.x = x
    @viewport.rect.y = y
    x = @window.x - @window.ox
    y = @window.y - @window.oy
    @arrow_top.x = (x + @window.width / 2) - (@arrow_top.width / 2)
    @arrow_top.y = y + (@arrow_top.height / 2)
    @arrow_bottom.x = (x + @window.width / 2) - (@arrow_bottom.width / 2)
    @arrow_bottom.y = y + @window.height - (@arrow_top.height / 2)
  end
  #-----------------------------------------------------------------------------
  def hide(skip_animation=false)
    mod = @@config[:animation_suavize]
    opacity = 255.0 / mod
    zoom = 1.0 / mod
    data1 = [@cursor, @selector, @arrow_top, @arrow_bottom]
    data2 = [@window, @contents, @bar_background, @bar_top]
    while mod > 0 && !skip_animation
      data1.each{|s| s.opacity -= opacity}
      data2.each{|s|
        s.opacity -= opacity
        s.zoom_x -= zoom
        s.zoom_y -= zoom
      }
      Graphics.update
      mod -= 1
    end
    data1.each{|s|
      s.visible = false
      s.opacity = 0
    }
    data2.each{|s|
      s.visible = false
      s.opacity = s.zoom_x = s.zoom_y = 0
    }
    @exit = true
  end
  #-----------------------------------------------------------------------------
  def main
    @exit = false
    @action = false
    while !@exit 
      Graphics.update
      Input.update
      update
      update_cursor_animation
      update_arrows_animation
      break if @exit
    end
    if @action
      if @@config[:pospone_teleport] == true
        id = [[@@config[:activate_switch].to_i, 1].max, 9999].min
        $game_switches[id] = true
      else
        perform_teleport
      end
    end
  end
  #-----------------------------------------------------------------------------
  def perform_teleport
    $game_map.interpreter.clear
    play_fx(:decision_se)
    play_fx(:teleport_se)
    SceneManager.scene.pre_transfer
    data = @real_data[@index]
    $game_player.reserve_transfer(data.map_id, data.x, data.y, data.direction)
    $game_player.perform_transfer
    $game_map.update
    SceneManager.scene.post_transfer
    if @@config[:pospone_teleport] == true
      id = [[@@config[:activate_switch].to_i, 1].max, 9999].min
      $game_switches[id] = false
    end
  end
  #-----------------------------------------------------------------------------
  def update
    if Input.repeat?(Input::DOWN)
      update_index(1)
    elsif Input.repeat?(Input::UP)
      update_index(-1)
    end
    if Input.repeat?(Input::LEFT) || Input.repeat?(Input::L)
      update_index(-(@contents.viewport.rect.height / @h))
    elsif Input.repeat?(Input::RIGHT) || Input.repeat?(Input::R)
      update_index(@contents.viewport.rect.height / @h)
    end
    if Input.trigger?(Input::B)
      play_fx(:cancel_se)
      hide
    end
    if Input.trigger?(Input::C)
      if @real_data[@index] == @current_map &&
        @@config[:disable_last_teleport] == true
        cancel_action
        return
      end
      hide(true)
      @action = true
      @current_map = @real_data[@index]
    end
  end
  #-----------------------------------------------------------------------------
  def cancel_action
    play_fx(:buzzer_se)
  end
  #-----------------------------------------------------------------------------
  def play_fx(id)
    begin
      data = @@config[id]
      Audio.se_play("Audio/SE/#{data[:name]}",
        data [:volume].to_i, data[:pitch].to_i)
    rescue
    end
  end
  #-----------------------------------------------------------------------------
  def update_index(n)
    last_index = @index
    @index += n
    if @index < 0
      @index = @real_data.size - 1
    elsif @index > @real_data.size - 1
      @index = 0
    end
    @selector.y = @h * @index
    if @selector.y - @viewport.oy < 0
      n = -(@selector.y - @viewport.oy)
      @viewport.oy -= n
      @bar_background.y -= n
    elsif @selector.y + @selector.height - @viewport.oy > @viewport.rect.height
      n = (@selector.y + @selector.height - @viewport.oy) - @viewport.rect.height
      @viewport.oy += n
      @bar_background.y += n
    end
    if last_index != @index
      play_fx(:cursor_se)
      draw_contents
      if @bar_displacement != 0
        @bar_top.y = @bar_background.y - @bar_background.oy + @bar_top.oy +
          @bar_displacement * @contents.viewport.oy
      end
      if @index == @real_data.size - 1
        @bar_top.y = @bar_background.y - @bar_background.oy +
          @bar_background.height + @bar_top.oy - @bar_top.height
      end
    end
    update_pos_cursor
  end
  #-----------------------------------------------------------------------------
  def update_pos_cursor
    @cursor.x = @viewport.rect.x - @cursor.width
    @cursor.y = @selector.y + @selector.height / 2 - @cursor.height / 2 -
      @viewport.oy + @viewport.rect.y
    @cursor_animation_index = 0
  end
  #-----------------------------------------------------------------------------
  def update_cursor_animation
    @cursor.x += @cursor_animation[@cursor_animation_index]
    @cursor_animation_index += 1
    if @cursor_animation_index > @cursor_animation.size - 1
      @cursor_animation_index = 0
    end
  end
  #-----------------------------------------------------------------------------
  def update_arrows_animation
    v = @contents.viewport
    @arrow_top.visible = (v.oy != 0)
    @arrow_bottom.visible = (@contents.height - v.oy > v.rect.height)
    @arrow_top.y    += @arrows_animation[@arrows_animation_index]
    @arrow_bottom.y -= @arrows_animation[@arrows_animation_index]
    @arrows_animation_index += 1
    if @arrows_animation_index > @arrows_animation.size - 1
      @arrows_animation_index = 0
    end
  end
  #-----------------------------------------------------------------------------
  def clear(data=nil)
    @data.clear
    unless data.nil?
      @data = data
      unless @data[$game_map.map_id].nil?
        @current_map = @data[$game_map.map_id][0]
      else
        @current_map = nil
      end
    end
  end
  #-----------------------------------------------------------------------------
  def dispose
    instance_variables.each{|var|
      if var.respond_to?(:dispose)
        var.dispose rescue next
      end
    }
  end
  #-----------------------------------------------------------------------------
end
#===============================================================================

#===============================================================================
class Game_Map
  #-----------------------------------------------------------------------------
  unless method_defined?(:setup_teleport_newold)
    alias setup_teleport_newold setup
  end
  #-----------------------------------------------------------------------------
  def setup(map_id)
    setup_teleport_newold(map_id)
    add_to_teleport_list = true
    no_add_text = "noAddToTeleportList".downcase
    @map.events.each do |i, event|
      if event.name.downcase == no_add_text
        add_to_teleport_list = false
        break
      end
    end
    if add_to_teleport_list
      $TeleportToVisited.add_map(map_id)
    end
  end
  #-----------------------------------------------------------------------------
end
#===============================================================================

#===============================================================================
class Game_Player < Game_Character
  #-----------------------------------------------------------------------------
  unless method_defined?(:moveto_teleport_newold)
    alias moveto_teleport_newold moveto
  end
  #-----------------------------------------------------------------------------
  def moveto(x, y)
    if (x < 0 || x > $game_map.width - 1)
      @new_x = 0
      x = 0
    end
    if (y < 0 || y > $game_map.height - 1)
      @new_y = 0
      y = 0
    end
    moveto_teleport_newold(x, y)
    map_id = $game_map.map_id
    $TeleportToVisited.update_map_info(map_id, :x, x)
    $TeleportToVisited.update_map_info(map_id, :y, y)
    $TeleportToVisited.update_map_info(map_id, :direction, self.direction)
  end
  #-----------------------------------------------------------------------------
end
#===============================================================================

#===============================================================================
module DataManager
  #=============================================================================
  class << self
    #---------------------------------------------------------------------------
    unless method_defined?(:setup_new_game_teleport_newold)
      alias setup_new_game_teleport_newold setup_new_game
    end
    def setup_new_game
      $TeleportToVisited.clear
      setup_new_game_teleport_newold
    end
    #---------------------------------------------------------------------------
    unless method_defined?(:load_game_without_rescue_teleport_newold)
      alias load_game_without_rescue_teleport_newold load_game_without_rescue
    end
    def load_game_without_rescue(index)
      $TeleportToVisited.clear
      load_game_without_rescue_teleport_newold(index)
    end
    #---------------------------------------------------------------------------
    unless method_defined?(:make_save_contents_teleport_newold)
      alias make_save_contents_teleport_newold make_save_contents
    end
    def make_save_contents
      contents = make_save_contents_teleport_newold
      contents[:teleportToVisited] = $TeleportToVisited.data.dup
      return contents
    end
    #---------------------------------------------------------------------------
    unless method_defined?(:extract_save_contents_teleport_newold)
      alias extract_save_contents_teleport_newold extract_save_contents
    end
    def extract_save_contents(contents)
      extract_save_contents_teleport_newold(contents)
      $TeleportToVisited.clear(contents[:teleportToVisited])
    end
    #---------------------------------------------------------------------------
  end
  #============================================================================
end
#===============================================================================

#===============================================================================
class Game_Interpreter
  #-----------------------------------------------------------------------------
  def open_teleport
    x = $game_map.events[@event_id].screen_x
    y = $game_map.events[@event_id].screen_y
    $TeleportToVisited.show_window(x, y)
  end
  #-----------------------------------------------------------------------------
  def perform_teleport
    $TeleportToVisited.perform_teleport
  end
  #-----------------------------------------------------------------------------
  def update_map_info(map_id, attr, value, ref=nil)
    $TeleportToVisited.update_map_info(map_id, attr, value, ref)
  end
  #-----------------------------------------------------------------------------
  def add_map(ref=nil, name="", map_id=nil, x=nil, y=nil, direction=nil)
    map_id = map_id.nil? ? $game_map.map_id : map_id.to_i
    direction = ([nil, 2, 4, 6, 8].include?(direction)) ? direction : 2
    $TeleportToVisited.add_map(map_id, ref, name, x, y, direction)
  end
  #-----------------------------------------------------------------------------
  def run
    begin
      wait_for_message
      while @list[@index] do
        execute_command
        @index += 1
      end
    rescue
      return
    end
    Fiber.yield
    @fiber = nil
  end
  #-----------------------------------------------------------------------------
end
#===============================================================================

$TeleportToVisited = TeleportToVisited.new
 
Last edited:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,370
Reaction score
8,536
First Language
English
Primarily Uses
RMMV
@newold Please use the edit button to add it to your original post. Thanks.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,354
Members
137,801
Latest member
topsan
Top