KMapSign RG
#1
KMapSign RG

by Kyonides


Introduction

This is just another customizable map sign script to let you pick the best way to display the current map's name and even use a customized name you set during your gameplay! Shocked 

Don't forget to follow the instructions I provided with my script. Winking

Script

Code:
# * KMapSign RG
#   Scripter : Kyonides Arkanthes
#   v1.0.0 - 2020-07-24

# This is just another Show Your Current Map's Name script.
# I do think this version of my script is highly customizable.
# You may need to change the values of the Constants found in the KMapSign
# module at any given time before playtesting your game.
# The sign might disappear immediately or after n seconds.

#* For Game Devs that prefer Custom Map Signs designed in Photoshop or GIMP *#
  # Better make Map Signs with a width and a height that are multiples of 4.
  # That is what knowledgeable scripters and programmers usually recommend.

# * Script Calls * #

# Exclude Maps that do not need any sign - IN GAME Method
#   $game_system.exclude_maps!(MapID1, etc.)

# Get a Custom Map Name! - If Any...
#   $game_system.map_name(MapID)

# Change a Map Name! - For Current Game Session or Loaded Saved Game Data
#   $game_system.change_map_name(MapID, 'New Map Name')

# Delete a Custom Map Name!
#   $game_system.delete_map_name(MapID)

# KMapSign.align = 0 or 1 or 2
# KMapSign.pos_x = :left or :right or :center
# KMapSign.pos_y = :upper or :lower or :center

# Pick the map sign's direction of its simple animation!
# Options: :left, :right, :up or :down depending on its position
#   KMapSign.direction = YourFavoriteDir

# Choose a predefined backdrop for your sign!
#   KMapSign.backdrop = name ## Name should be a 'string' or :symbol

# Should this script render the map's name for you?
#   KMapSign.render_text = true ## Or false

# Should this script show the sign after you leave any menu?
#   KMapSign.show_after_menu_exit = true ## Or false

module KMapSign
  # How long should it be visible? Use seconds, i.e. 2.5
  SLIDE_TIMER = 2
  CLOSE_TIMER = 0 # 0 seconds - Close Right Away, 1+ - gradually disappear
  SPEED_X = 4 # Multiple of 4 is preferred
  SPEED_Y = 4 # Multiple of 4 is preferred
  # This Coordinates are used in the map sign's movement section as limits.
  X = { :left => 8, :right => 512 }
  Y = { :upper => 8, :center => 8, :lower => 592 }
  # Include as many Map ID's as it pleases you or leave it empty
  EXCLUDE_MAPS = []
  # { ID => PictureFileName, etc. } where ID can be a 'string' or a :symbol
  BACKDROPS = {}
  # Select the starting picture by its ID -> nil - renders a white box
  @backdrop = nil
  @render_text = true # false if you will use pictures with custom text
  @show_after_menu_exit = false
  BACKDROP_MARGIN_X = 8 # Left or Right Margin
  BACKDROP_MARGIN_Y = 8 # Upper or Lower Margin
  # nil - default, 'Times New Roman' or "Dejavu Sans" - chosen font
  FONT_NAME = 'Verdana'
  FONT_SIZE = 19
  # Some characters might look wrong if this value isn't higher than FONT_SIZE
  # depending on the RM version and the chosen font
  FONT_BOX_HEIGHT = 24
  FONT_UPPER_MARGIN = 4 # Upper Box or Picture Font Margin
  @align = 1 # 0 - left, 1 - center, 2 - right
  @pos_x = :left  # Horizontal Position
  @pos_y = :upper # Vertical Position
  @direction = :right
  WIDTH  = 640 # Default Maker Window Width
  HEIGHT = 480 # Default Maker Window Height
  NO_CUSTOM_NAME = 'No Custom Map Name' # For Debugging Purposes
  class << self
    attr_accessor :show, :render_text, :backdrop, :pos_x, :pos_y, :direction
  end
  module_function
  def find_version
    @version = ''
    lines = File.readlines('Game.ini')
    lines.each do |line|
      next unless line =~ /library/i
      return @version = line.scan(/\d/)[0].to_i
    end
  end

  def set_timers(map_id)
    @last_map_id = map_id
    @slide_timer = Graphics.frame_rate * SLIDE_TIMER
    if CLOSE_TIMER > 0
      @close_timer = Graphics.frame_rate * CLOSE_TIMER
      @close_frames = (255 / @close_timer).round
    end
  end

  def set_mapname
    unless $game_system.map_names.include?(@last_map_id)
      mapname = NAMES[@last_map_id].name
      @mapname = mapname.gsub(/\[\w+\]|\{\w+\}|\(\w+\)/, '')
    else
      @mapname = $game_system.map_names[@last_map_id]
    end
  end

  def create_graphics
    @viewport = Viewport.new(0, 0, WIDTH, HEIGHT)
    @viewport.z = 9000
    @sign = Sprite.new(@viewport)
    back = BACKDROPS[@backdrop]
    if back == nil
      @render_text = true
      bit = Bitmap.new(240, 32)
      bit.fill_rect(bit.rect, Color.new(255, 255, 255, 128))
    else
      bit = RPG::Cache.picture(back).dup
    end
    @sign.bitmap = bit
  end

  def create(map_id)
    return if @last_map_id == map_id and !@show_after_menu_exit
    @show = !$game_system.hide_mapsign?(map_id)
    return unless @show
    set_timers(map_id)
    set_mapname
    create_graphics
    b = @sign.bitmap
    d = @direction
    if @pos_x == :left
      @sign.x = BACKDROP_MARGIN_X
      if @pos_y == :upper
        @sign.x = -b.width if d == :right
        @sign.y = d == :right ? BACKDROP_MARGIN_Y : -b.height
      elsif @pos_y == :center
        @direction = :right
        @sign.y = HEIGHT / 2 - b.height / 2
      elsif @pos_y == :lower
        @direction = :up if d != :right
        @sign.x = -b.width if d == :right
        @sign.y = d == :right ? BACKDROP_MARGIN_Y : -b.height
      end
    elsif @pos_x == :center
      @sign.x = WIDTH / 2 - b.width / 2
      if @pos_y == :upper
        @direction = :down
        @sign.y = -b.height
      elsif @pos_y == :lower
        @direction = :up
        @sign.y = HEIGHT + b.height
      end
    elsif @pos_x == :right
      @sign.x = WIDTH - BACKDROP_MARGIN_X
      if @pos_y == :upper
        @sign.x += BACKDROP_MARGIN_X if d == :left
        @sign.y = d == :left ? BACKDROP_MARGIN_Y : -b.height
      elsif @pos_y == :center
        @direction = :left
        @sign.y = HEIGHT / 2 - b.height / 2
      elsif @pos_y == :lower
        @direction = :up if d != :left
        @sign.x += BACKDROP_MARGIN_X if d == :left
        @sign.y = HEIGHT - (d == :left ? BACKDROP_MARGIN_Y : 0)
      end
    end
    return unless @render_text
    b.font.name = FONT_NAME if FONT_NAME
    height = FONT_BOX_HEIGHT
    b.draw_text(0, FONT_UPPER_MARGIN, b.width, height, @mapname, @align)
  end

  def update_show_dir
    case @direction
    when :right
      @sign.x += SPEED_X
      @show = @sign.x != X[@pos_x]
    when :down
      @sign.y += SPEED_Y
      @show = @sign.y != Y[@pos_y]
    when :left
      @sign.x -= SPEED_X
      @show = @sign.x != X[@pos_x]
    when :up
      @sign.y -= SPEED_Y
      @show = @sign.y != Y[@pos_y]
    end
  end

  def dispose
    return unless @sign
    @show = false
    @sign.visible = false
    @sign.bitmap.dispose
    @sign.dispose
    @viewport.dispose
    @sign = nil
    @viewport = nil
  end
    
  def update_sign
    return update_show_dir if @show
    return @slide_timer -= 1 if @slide_timer > 0
    if @close_timer > 0
      @sign.opacity -= @close_frames
      return @close_timer -= 1
    end
    dispose
  end

  def get_extension
    @version == 3 ? 'rvdata2' : @version == 2 ? 'rvdata' : 'rxdata'
  end

  def reset
    @last_map_id = 0
    @close_timer = 0
  end
  find_version
  NAMES = load_data('Data/MapInfos.' + get_extension)
end

class Game_System
  alias :kyon_mapsign_gm_screen_init :initialize
  def initialize
    kyon_mapsign_gm_screen_init
    KMapSign.reset
    @map_names = {}
    @map_names.default = KMapSign::NO_CUSTOM_NAME
    @exclude_maps = KMapSign::EXCLUDE_MAPS.dup
  end

  def exclude_maps!(*ids)
    @exclude_maps += ids
    @exclude_maps = @exclude_maps.uniq.sort
  end
  def map_name(map_id) @exclude_maps[map_id] end
  def change_map_name(map_id, name) @exclude_maps[map_id] = name end
  def delete_map_name(map_id) @exclude_maps.delete(map_id) end
  def hide_mapsign?(map_id) @exclude_maps.include?(map_id) end
  attr_reader :map_names, :exclude_maps
end

class Spriteset_Map
  alias :kyon_mapsign_smap_init :initialize
  alias :kyon_mapsign_smap_up :update
  alias :kyon_mapsign_smap_disp :dispose
  def initialize
    KMapSign.create($game_map.map_id)
    kyon_mapsign_smap_init
  end

  def update
    kyon_mapsign_smap_up
    KMapSign.update_sign
  end

  def dispose
    kyon_mapsign_smap_disp
    KMapSign.dispose
  end
end

Terms of Use

Free for non commercial games.
Don't forget to include my nickname in your game credits and mention this forum as well.
Give me a free copy of your completed game if you include at least 2 of my scripts! Laughing + Tongue sticking out
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }




Users browsing this thread: 2 Guest(s)