Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> Background Messages, Do other things at the same time as a message!
miget man12
post Jul 27 2009, 03:26 PM
Post #1


Making a Comeback
Group Icon

Group: Revolutionary
Posts: 393
Type: Musician
RM Skill: Intermediate




Background Messages

Version 1.0b
Author: Miget man12
Release Date: July 27, 2009
Request: memorystick



Introduction
This script was requested by memorystick. It allows you to have messages be shown while other things happen. You could make it show a message and have the player move around. You can even use it to have multiple messages at the same time!

Features
-have messages that will stay open for a time limit
-have messages that do not disable the player's movement
-have other event commands be processed while message is being shown
**all features are activated by 1 switch**

Script
[Show/Hide] The Script
CODE
module Mm12
  # Turn this switch on to have messages in the background
  BG_MSG_SWITCH_ID = 1
  # This is how many frames will be waited after the message is complete
  BG_MSG_WAIT = 180
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
  alias mm12_bgmsg_com101 command_101
  #--------------------------------------------------------------------------
  # * Show Text
  #--------------------------------------------------------------------------
  def command_101
    if $game_switches[Mm12::BG_MSG_SWITCH_ID]
      unless $game_bgmessage.busy
        $game_bgmessage.close_wait = Mm12::BG_MSG_WAIT
        $game_bgmessage.face_name = @params[0]
        $game_bgmessage.face_index = @params[1]
        $game_bgmessage.background = @params[2]
        $game_bgmessage.position = @params[3]
        @index += 1
        while @list[@index].code == 401       # Text data
          $game_bgmessage.texts.push(@list[@index].parameters[0])
          @index += 1
        end
      end
      return false
    else
      mm12_bgmsg_com101
    end
  end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  alias mm12_bgmsg_scn_mp_start start
  def start
    mm12_bgmsg_scn_mp_start
    @bgmessage_window = Window_BGMessage.new
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  alias mm12_bgmsg_scn_mp_terminate terminate
  def terminate
    mm12_bgmsg_scn_mp_terminate
    @bgmessage_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias mm12_bgmsg_scn_mp_update update
  def update
    mm12_bgmsg_scn_mp_update
    @bgmessage_window.update
  end
end

class Scene_Title < Scene_Base
  alias mm12_bgmsg_scn_ttl_create_gm_objs create_game_objects
  #--------------------------------------------------------------------------
  # * Create Game Objects
  #--------------------------------------------------------------------------
  def create_game_objects
    mm12_bgmsg_scn_ttl_create_gm_objs
    $game_bgmessage = Game_BGMessage.new
  end
end
#==============================================================================
# ** Game_BGMessage
#------------------------------------------------------------------------------
#  This class handles the state of the background message window that display
# text or selections, etc. The instance of this class is referenced by
# $game_bgmessage.
#==============================================================================

class Game_BGMessage < Game_Message
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  MAX_LINE = 4                            # Maximum number of lines
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :close_wait
  #--------------------------------------------------------------------------
  # * Clear
  #--------------------------------------------------------------------------
  def clear
    super
    @close_wait = 0
  end
end
#==============================================================================
# ** Window_Message
#------------------------------------------------------------------------------
#  This message window is used to display text.
#==============================================================================

class Window_BGMessage < Window_Selectable
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  MAX_LINE = 4                            # Maximum number of lines
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 288, 544, 128)
    self.z = 200
    self.active = false
    self.index = -1
    self.openness = 0
    @opening = false            # WIndow opening flag
    @closing = false            # Window closing flag
    @text = nil                 # Remaining text to be displayed
    @contents_x = 0             # X coordinate for drawing next character
    @contents_y = 0             # Y coordinate for drawing next character
    @line_count = 0             # Line count drawn up until now
    @wait_count = 0             # Wait count
    @background = 0             # Background type
    @position = 2               # Display position
    @show_fast = false          # Fast forward flag
    @line_show_fast = false     # Fast forward by line flag
    @pause_skip = false         # Input standby omission flag
    @close_wait = $game_bgmessage.close_wait
    create_gold_window
    #create_number_input_window
    create_back_sprite
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    super
    dispose_gold_window
    #dispose_number_input_window
    dispose_back_sprite
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    update_gold_window
    #update_number_input_window
    update_back_sprite
    #update_show_fast
    unless @opening or @closing             # Window is not opening or closing
      if @wait_count > 0                    # Waiting within text
        @wait_count -= 1
      elsif self.pause                      # Waiting for text advancement
        input_pause
      elsif @text != nil                    # More text exists
        update_message                        # Update message
      elsif continue?                       # If continuing
        start_message                         # Start message
        open                                  # Open window
        $game_bgmessage.visible = true
      else                                  # If not continuing
        close                                 # Close window
        $game_bgmessage.visible = @closing
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Create Gold Window
  #--------------------------------------------------------------------------
  def create_gold_window
    @gold_window = Window_Gold.new(384, 0)
    @gold_window.openness = 0
  end
  #--------------------------------------------------------------------------
  # * Create Number Input Window
  #--------------------------------------------------------------------------
  def create_number_input_window
    @number_input_window = Window_NumberInput.new
    @number_input_window.visible = false
  end
  #--------------------------------------------------------------------------
  # * Create Background Sprite
  #--------------------------------------------------------------------------
  def create_back_sprite
    @back_sprite = Sprite.new
    @back_sprite.bitmap = Cache.system("MessageBack")
    @back_sprite.visible = (@background == 1)
    @back_sprite.z = 190
  end
  #--------------------------------------------------------------------------
  # * Dispose of Gold Window
  #--------------------------------------------------------------------------
  def dispose_gold_window
    @gold_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Dispose of Number Input Window
  #--------------------------------------------------------------------------
  def dispose_number_input_window
    @number_input_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Dispose of Background Sprite
  #--------------------------------------------------------------------------
  def dispose_back_sprite
    @back_sprite.dispose
  end
  #--------------------------------------------------------------------------
  # * Update Gold Window
  #--------------------------------------------------------------------------
  def update_gold_window
    @gold_window.update
  end
  #--------------------------------------------------------------------------
  # * Update Number Input Window
  #--------------------------------------------------------------------------
  def update_number_input_window
    @number_input_window.update
  end
  #--------------------------------------------------------------------------
  # * Update Background Sprite
  #--------------------------------------------------------------------------
  def update_back_sprite
    @back_sprite.visible = (@background == 1)
    @back_sprite.y = y - 16
    @back_sprite.opacity = openness
    @back_sprite.update
  end
  #--------------------------------------------------------------------------
  # * Update Fast Forward Flag
  #--------------------------------------------------------------------------
  def update_show_fast
    if self.pause or self.openness < 255
      @show_fast = false
    elsif Input.trigger?(Input::C) and @wait_count < 2
      @show_fast = true
    elsif not Input.press?(Input::C)
      @show_fast = false
    end
    if @show_fast and @wait_count > 0
      @wait_count -= 1
    end
  end
  #--------------------------------------------------------------------------
  # * Determine if the Next Message Should be Displayed Continuously
  #--------------------------------------------------------------------------
  def continue?
    #return true if $game_bgmessage.num_input_variable_id > 0
    return false if $game_bgmessage.texts.empty?
    if self.openness > 0 and not $game_temp.in_battle
      return false if @background != $game_bgmessage.background
      return false if @position != $game_bgmessage.position
    end
    return true
  end
  #--------------------------------------------------------------------------
  # * Start Message
  #--------------------------------------------------------------------------
  def start_message
    @text = ""
    for i in 0...$game_bgmessage.texts.size
      @text += "    " if i >= $game_bgmessage.choice_start
      @text += $game_bgmessage.texts[i].clone + "\x00"
    end
    @item_max = $game_bgmessage.choice_max
    convert_special_characters
    reset_window
    new_page
  end
  #--------------------------------------------------------------------------
  # * New Page
  #--------------------------------------------------------------------------
  def new_page
    contents.clear
    if $game_bgmessage.face_name.empty?
      @contents_x = 0
    else
      name = $game_bgmessage.face_name
      index = $game_bgmessage.face_index
      draw_face(name, index, 0, 0)
      @contents_x = 112
    end
    @contents_y = 0
    @line_count = 0
    @show_fast = false
    @line_show_fast = false
    @pause_skip = false
    contents.font.color = text_color(0)
  end
  #--------------------------------------------------------------------------
  # * New Line
  #--------------------------------------------------------------------------
  def new_line
    if $game_bgmessage.face_name.empty?
      @contents_x = 0
    else
      @contents_x = 112
    end
    @contents_y += WLH
    @line_count += 1
    @line_show_fast = false
  end
  #--------------------------------------------------------------------------
  # * Convert Special Characters
  #--------------------------------------------------------------------------
  def convert_special_characters
    @text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
    @text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
    @text.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name }
    @text.gsub!(/\\C\[([0-9]+)\]/i) { "\x01[#{$1}]" }
    @text.gsub!(/\\G/)              { "\x02" }
    @text.gsub!(/\\\./)             { "\x03" }
    @text.gsub!(/\\\|/)             { "\x04" }
    @text.gsub!(/\\!/)              { "\x05" }
    @text.gsub!(/\\>/)              { "\x06" }
    @text.gsub!(/\\</)              { "\x07" }
    @text.gsub!(/\\\^/)             { "\x08" }
    @text.gsub!(/\\\\/)             { "\\" }
  end
  #--------------------------------------------------------------------------
  # * Set Window Background and Position
  #--------------------------------------------------------------------------
  def reset_window
    @background = $game_bgmessage.background
    @position = $game_bgmessage.position
    if @background == 0   # Normal window
      self.opacity = 255
    else                  # Dim Background and Make it Transparent
      self.opacity = 0
    end
    case @position
    when 0  # Top
      self.y = 0
      @gold_window.y = 360
    when 1  # Middle
      self.y = 144
      @gold_window.y = 0
    when 2  # Bottom
      self.y = 288
      @gold_window.y = 0
    end
  end
  #--------------------------------------------------------------------------
  # * End Message
  #--------------------------------------------------------------------------
  def terminate_message
    self.active = false
    self.pause = false
    self.index = -1
    @gold_window.close
    $game_bgmessage.main_proc.call if $game_bgmessage.main_proc != nil
    $game_bgmessage.clear
  end
  #--------------------------------------------------------------------------
  # * Update Message
  #--------------------------------------------------------------------------
  def update_message
    loop do
      c = @text.slice!(/./m)            # Get next text character
      case c
      when nil                          # There is no text that must be drawn
        finish_message                  # Finish update
        break
      when "\x00"                       # New line
        new_line
        if @line_count >= MAX_LINE      # If line count is maximum
          unless @text.empty?           # If there is more
            self.pause = true           # Insert number input
            break
          end
        end
      when "\x01"                       # \C[n]  (text character color change)
        @text.sub!(/\[([0-9]+)\]/, "")
        contents.font.color = text_color($1.to_i)
        next
      when "\x02"                       # \G  (gold display)
        @gold_window.refresh
        @gold_window.open
      when "\x03"                       # \.  (wait 1/4 second)
        @wait_count = 15
        break
      when "\x04"                       # \|  (wait 1 second)
        @wait_count = 60
        break
      when "\x05"                       # \!  (Wait for input)
        self.pause = true
        break
      when "\x06"                       # \>  (Fast display ON)
        @line_show_fast = true
      when "\x07"                       # \<  (Fast display OFF)
        @line_show_fast = false
      when "\x08"                       # \^  (No wait for input)
        @pause_skip = true
      else                              # Normal text character
        contents.draw_text(@contents_x, @contents_y, 40, WLH, c)
        c_width = contents.text_size(c).width
        @contents_x += c_width
      end
      break unless @show_fast or @line_show_fast
    end
  end
  #--------------------------------------------------------------------------
  # * End Message Update
  #--------------------------------------------------------------------------
  def finish_message
    #if $game_bgmessage.choice_max > 0
      #start_choice
    #elsif $game_bgmessage.num_input_variable_id > 0
      #start_number_input
    if @pause_skip
      terminate_message
    else
      self.pause = true
    end
    @wait_count = Mm12::BG_MSG_WAIT
    @text = nil
  end
  #--------------------------------------------------------------------------
  # * Text Advancement Input
  #--------------------------------------------------------------------------
  def input_pause
    @close_wait -= 1
    if @close_wait <= 0 and @text.nil?
      terminate_message
    end
    if Input.trigger?(Input::B) or Input.trigger?(Input::C)
      self.pause = false
      if @text != nil and not @text.empty?
        new_page if @line_count >= MAX_LINE
      else
        terminate_message
      end
    end
  end
end

IF YOU ARE USING YERD MESSAGE SYSTEM THE FEATURES WILL NOT WORK UNLESS YOU USE THIS:
http://www.filefront.com/14137479/BG%20Mes...mpatibility.txt

Customization
You can set which switch enables it and how long the message windows will stay open(after message completes).

Compatibility
This does will work with Woratana's NMS, but it will not have any of NMS's features! However, this must be below the NMS to function properly.

Screenshot
I don't think a screenshot would be useful.

DEMO
http://www.mediafire.com/download.php?nnmr1onw3tq

Installation
Copy the script and place it above 'Main.'

FAQ
n/a

Terms and Conditions
Credits!

Credits
Miget man12

~Miget man12


__________________________
By the way:


I'm bored because it's summer so I decided to drop by for a bit.
Go to the top of the page
 
+Quote Post
   



Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th May 2013 - 03:09 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker