Custom Message Script by Hodgeelmf

Started by Shalaren, August 12, 2013, 12:35:01 pm

Previous topic - Next topic

Shalaren

August 12, 2013, 12:35:01 pm Last Edit: August 12, 2013, 07:40:14 pm by KK20
Hey guys! I really like this Custom Message Script by Hodgeelmf, its small simple and animated and is just really pleasant to use. you can try it and you'll see what I mean. however it wont work with Blizz-ABS :( is there anyway to fix it? maybe anyway to disable blizz abs anytime the message script is acitve? its similar to ForeverZer0 CMS, its just that this one has a smoother feel and the chat bubble is a lot smaller making it very nice visually for cutscenes.
Spoiler: ShowHide



EDIT: Because of the character limit, the following script could not be fully displayed and had to be deleted. It would be best to either provide the link to the script itself or post it into something like Pastebin. -KK20

LiTTleDRAgo

August 12, 2013, 06:34:58 pm #1 Last Edit: August 13, 2013, 01:21:08 am by LiTTleDRAgo
first, find this line in BABS Part 3

alias reset_window_blizzabs_later reset_window


change it to

alias reset_window_blizzabs_later reset_window if method_defined?(:reset_window)


then place this script below BABS

#--------------------------------------------------------------------------
# * BlizzABS Check
#--------------------------------------------------------------------------
if $BlizzABS
#============================================================================
# BlizzABS::Controller
#----------------------------------------------------------------------------
#  This class is a special controller that controls the party leader.  Some
#  input is processed instantly, while some is converted into commands to be
#  given to the player character.
#============================================================================
module BlizzABS
  class Controller
    #--------------------------------------------------------------------------
    # * update_moving
    #--------------------------------------------------------------------------
    def update_moving(data)
      if data != nil
        moved, x, y = data
        if player.real_y > y && player.real_y - $game_map.display_y > CY
          $game_map.scroll_down(player.real_y - y)
        end
        if player.real_x < x && player.real_x - $game_map.display_x < CX
          $game_map.scroll_left(x - player.real_x)
        end
        if player.real_x > x && player.real_x - $game_map.display_x > CX
          $game_map.scroll_right(player.real_x - x)
        end
        if player.real_y < y && player.real_y - $game_map.display_y < CY
          $game_map.scroll_up(y - player.real_y)
        end
        unless player.moving?
          if moved && !check_event_trigger_here(Cache::TouchTrigger) &&
              !($DEBUG && Input.press?(Input::CTRL)) && @encounter_count > 0
            @encounter_count -= 2 ** (5 - $game_system.pixel_rate)
            @encounter_count = 0 if @encounter_count < 0
          end
          if Input.trigger?(Input::C) && $game_temp.message_text == nil
            check_event_trigger_here(Cache::PressTrigger)
            check_event_trigger_there(Cache::BasicTrigger)
          end
        end
      end
      ($BlizzABS.battlers - [player]).each {|actor| actor.update}
    end
  end
end
#==============================================================================
# Control_Sprite_Character
#------------------------------------------------------------------------------
#  This class is an interception class for Sprite_Character. It substitutes its
#  instances everywhere and handles them. It provides ABSEAL limitation
#  control, damage sprite control and enemy fade_in/dying animations.
#  It disposes sprites out of the ABSEAL range immediately.
#==============================================================================
class Control_Sprite_Character
  #--------------------------------------------------------------------------
  # * src_rect
  #--------------------------------------------------------------------------
  def src_rect
    @sprite.src_rect
  end
end
#--------------------------------------------------------------------------
# * End Script
#--------------------------------------------------------------------------
end

Shalaren

Thanks for the reply :)
I tried it and the game crashes when moving, with the error of

Script "BlizzABS Check - Zer0" line 32 NameError occurred.
uninitialized constant BlizzABS::Controller::Cache


Shalaren

August 13, 2013, 01:44:36 am #4 Last Edit: August 13, 2013, 01:45:50 am by Shalaren
awesome thanks :) lv*

tho I found an annoying thing this does.
with the Babs caterpillar script the bubble appears on the 4th actor instead on the one you are controlling. (and even if you only have 1 person in your party, it shows the bubble over where the 4th character would of been if there was one, so it wont be over the main character regardless) is there a way to fix that? (as long as the bubble is on top of the main character, although it would of been cool if it would be possible to choose which character the bubble should appear on top of)

LiTTleDRAgo

August 13, 2013, 03:02:01 am #5 Last Edit: August 13, 2013, 03:07:09 am by LiTTleDRAgo
* edited because annoying character limit *

http://pastebin.com/fHLU6nbp

changed :

\e[-1] : above player
\e[0] : above current event (default)
\e[<Integer>] : above event ID


Shalaren


Shalaren

When I call the
$game_system.message_text_mode = 
TEXT_MODE_INVISIBLE
script call (for a cutscene) I get an error with this line
   
y = @text_y + (@text_height * @y) + @bubble_correction_y + y_correction

did I do something wrong is that with the script?

LiTTleDRAgo

it's a bug from original script,
I don't know what TEXT_MODE_INVISIBLE do but I updated the script to make things work

http://pastebin.com/fHLU6nbp

Shalaren

August 17, 2013, 01:18:09 am #9 Last Edit: August 18, 2013, 01:44:35 pm by Shalaren
What invisible does is its besically a script call for hiding the window skin, since changing text options through events doesn't work. but the script call works very nicely now :) Thanks Drago.

Shalaren

I have another weird bug S: when I try to show an icon by writing
\I[x]
before the message with this command appears in the game, the game freezes and then crashes with the error saying "Script is hanging" and nothing else. whats that mean when it says that?

KK20

August 18, 2013, 02:16:33 pm #11 Last Edit: August 18, 2013, 02:38:26 pm by KK20
Whenever the "Script is Hanging" it usually means an infinite loop. Or rather, Graphics.update is not called within a certain period of time.
Quote from: Help FileIf this method is not called in 10 seconds or more, the program will view the script as having run out of control and will force a quit.

Unfortunately, I cannot see what the problem is right off the bat. I'd have to test out the script myself.

EDIT: What's the exact message you are using? Because just doing a "Hi. \i[2]" works fine for me.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Shalaren

Yeah what you typed worked for me too,
I don't understand this then, if anyone could explain.

it shows icons by numbers so \I[5] will work,
I thought that you can put the icon's name like \I[Money] (which caused a crash)
so if I want to use an icon how do I know what number it is?

KK20

August 18, 2013, 05:03:10 pm #13 Last Edit: August 18, 2013, 05:27:09 pm by KK20
Yeah, I think that was pretty stupid to do in design. I understand the purpose (try to use less character space in your message box) but it's pretty inconvenient. The edits would have to be made to

     when "\014"  
       @text.slice!(/\014\[([0-9]+)\]/)
       icon = Sprite.new
       icon.opacity = 0
       icon.bitmap = Bitmap.new("Graphics/Icons/#{Icons[$1.to_i]}")
       true_y = @text_y + (@y * @text_height) + y_correction #+ y + @face_extension_y - (@text_rect.height + 25)
       @message.bitmap.blt(offset+@x+@face_extension_x,true_y,icon.bitmap,Rect.new(0,0,24,24))
       @x += 24

and

   while @text.slice(/\\[Ii]/) != nil
     @text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\014[#{$1}]" }
   end

Looks easy. Give a minute.

EDIT: This change will make it so that you have to do \i[filename] instead of an integer (filename does not need to be surrounded with quotes).
Spoiler: ShowHide

#==============================================================================
# ** Custom Message Script by Hodgeelmf **
#
#     Version 1.4
#
#       Version History
#         1.0.0 - Basic functionality
#         1.1.0 - Fixed issue with bubble size and bolded text
#               Modified gold window
#               Added /q function
#         1.2.0 - Added Icon display
#               Added Face Graphics
#               Fixed Gold command iteration error (This is what formerly broke
#                                                   the script)
#               Added use of Windowskin Graphic
#               Fixed sub window termination to be more natural
#         1.3.0 - Added thought indicater option
#               Added emotion colors
#         1.4.0 - Fixed glitch when switching from Windowskin to Bubble mode
#               Added function to disable bubble bouncing
#         1.4.1 - Fixed text drawing issue when choices displayed without
#               preceding message text
#                 Created \nc command
#
#       **************UPDATE NOTE*******************
#         This script displays all choices immediately after the text
#         which precedes them.  I have added a command to prevent this
#         should you elect to do so:
#
#               \nc
#
#           I see no reason to turn this into a toggle currently unless
#           there were significant push for it
#
#
#     Necessary updates
#
#       -Add other various functions like display hp, quest, etc.
#
#==============================================================================
=begin

Welcome to the Custom Message script!

Installation instructions:

1.  Install this script above Main, preferrably directly above
2.  Download attached graphics (message_bubble and pointer2)
    and place in Graphics/Pictures
3.  That's it!

Message commands:

\e[x]   Display message over a map event

    By default, bubble messages display over the player's sprite.  Values
    outside of the map events range will display over the player as well.

\c[x]   Change message text color (0-8)

\n[x]   Insert actor name

\v[x]   Insert variable value

\b      Toggle bold text

\w[x]   Wait control (0-999)

    Wait values are determined by frame.  40 FPS is the script rate.

\p      Pause control

    Forces the player to press enter before continuing.

\q      Forced ending

    Forces the message winddow to close once the character is encountered.
    Typically best to use directly after a wait timer.
   
\f      Force position

    Forces a specific position for the message bubble.
   
    0 - Upper right of the sprite
    1 - Upper left of the sprite
    2 - Lower right of the sprite
    3 - Lower left of the sprite
   
\g      Displays gold window

    Fades in the gold window to the bottom right corner of the screen.  To keep
    it displayed after current message, add \g into the next master message.

\i[x]   Display icon

    Displays an icon from the "Icons" folder.  A constant array, Icons, is
    compiled at runtime to store imported icon names in addition to RTP.
   
\z[x]   Display face graphic (found in Graphics/Faces - you may have to create this
                                                        folder)

    Displays a face graphic on the left of the message.  Currently this script
    only supports images with one face (as opposed to a whole faceset).

\t     Thought Bubble

        Uses thought indicater (ie two dots instead of mouth opening style)
       
\m[x]   Mood Coloring

        Changes bubble color to indicate speakers/thinkers mood (0-4)
       
\nc     Do not Display Choices

        Keeps choices from being appended to the text preceding them
   
\h[x]  Display Hp

    Not functioning at this point

\s[x]   Sub window controls (explained below)


  Master - the message which controls sub windows
  Sub - any message that displays as a part of a master
   
    1. The master message always has a higher z value than any sub messages
    2. Sub message must immediately follow the master message and be in
        consecutive order (ex. sub 0 must be the next event command after
        the master message, sub 1 must be the next event command after
        sub 0, etc.)
    3. Sub messagge numbers do not reset after a master message.  For
        example, if the first master messsage contains two sub messages,
        the second master message with sub messages must begin with sub
        message number 3, and so on.
    4. Use \s[x] where x is the number of the sub message to indicate that
        a particular message is a sub message
    5. Call sub messages in a master message with \s[x] where x is the
        number of the sub message.
    6. There is no limit to the number of sub messages, but since text is
        drawn one letter at a time, too many messages may cause lag.
       
  ***NOTE***
      If any of these commands seem bulky, it is because there is a glitch in
      the run script command in the event editor which does not allow for
      single lines changing global variables to function properly.
       
Script commands (from the Event Editor):

  1. Choose message style (bubble, windowskin or invisible)
     
      ***** If you do not have the correct images in Graphics/Pictures
      ***** the script will automatically change to WINDOWSKIN mode and
      ***** change the default text color to white

      $game_system.message_text_mode = x
     
      TEXT_MODE_BUBBLE
      TEXT_MODE_INVISIBLE
      TEXT_MODE_WINDOWSKIN
     
  2. Enable or disable bubble bouncing (only applies when in TEXT_MODE_BUBBLE)

      $game_system.message_bubble_bounce = x
     
      BUBBLE_BOUNCE_ON
      BUBBLE_BOUNCE_OFF
     
  2. Change position of invisible text

      $game_system.invisible_position = x
     
      INVISIBLE_POSITION_TOP
      INVISIBLE_POSITION_MIDDLE
      INVISIBLE_POSITION_BOTTOM
      INVISIBLE_POSITION_BOOK(arbitrary value from one of my projects)
     
  3. Change outline text options

      $game_system.message_text_outline = x
     
      TEXT_NORMAL
      TEXT_OUTLINE
     
  4. Change text speed

      $game_system.message_text_speed = x
     
      TEXT_SPEED_SLOW
      TEXT_SPEED_MEDIUM
      TEXT_SPEED_FAST

  5. Change text skip rate (one letter per frame up to all at once)
     
      $game_system.message_text_skip = x

      TEXT_SKIP_NORMAL  (1)
      TEXT_SKIP_DOUBLE  (2)
      TEXT_SKIP_TRIPLE  (3)
      TEXT_SKIP_FULL

     
  5. Change text size

      $game_system.message_text_size = x
     
      TEXT_SIZE_SMALL
      TEXT_SIZE_MEDIUM
      TEXT_SIZE_LARGE
      TEXT_SIZE_JUMBO
     
  6. Change text font

      $game_system.message_text_font = x
     
      TEXT_FONT_DEFAULT
      TEXT_FONT_CORSIVA
     
  7. Color Constants

      TEXT_COLOR_BLACK
      TEXT_COLOR_WHITE
     
  8. Face Graphic Functions

      $game_system.face_graphic_type = x
     
  9. Face Graphic Constants

      FACE_GRAPHIC_FULL - typically a bust which looks better offset to the left
                          and extending abovve the bubble
      FACE_GRAPHIC_BOX -  traditional boxed in face graphics which need to be
                          encased by the bubble to look correct
     
  10. Global Methods (for ease of access)

      message(string) - place in script box in event processing
     
      ***** Only place this command once per Event Script Box *****
     
      You may wish to have dialogue or entries that are longer than three
      lines.  This global method allows you to supply a string to
      $game_temp.message_text manually.  The best way to do so is to store
      a message in a variable and pass it to the method.  In this example
      script there is a Game_Messages class which has public methods that
      assign a message to a variable.  For full games, it would be better
      to create a text file to load from.  The best formatter to use is
      %q (ex @message = %q(lots of text...can be multiple lines).  The
      %q formatter mimicks the event dialogue box text editing format
      so you can use single "\" characters instead of using "\\" or not
      being able to use special characters at all.
     
      default_color(x) - set message default color
     
      Input either a number 0 through 8 or a Color object.
     
      face(string) - set default face graphic
     
      Use this method to supply a default face graphic for messages.  This graphic
      has secondary priority to one explicitly declared in a message, so is useful
      for largely unbroken monologues.
     
      clear_face - clears the default face graphic
     
      small_text
      medium_text   - Shortcut methods to change $game_system.message_text_size
      large_text
      jumbo_text
     
      slow_text
      fast_text     - Shortcut methods to change $game_system.messge_text_speed
     
           
     
                                      Enjoy! And remember to credit!

=end

#========================================================================
#   Game_Messages
#       You can easily create messages to display of any length using this
#       Class or a similar one of your creation.
#========================================================================

class Game_Messages

  # This message is obviously far too long for a bubble message, but it looks
  # quite good with a darkened screen tone

  # When loaded into a global variable, these class methods can be called to
  # the event editor with two lines of code.  For your own projects, you will
  # probably want a more sophisticated heirarchy.
  def message_1
    @message = "  \c[0]\bMessage commands:\b

\c[6]\b\\e[x]\c[0]     Display message over a map event\b
                   By default, bubble messages display over the player's sprite.  Values
                   outside of the map events range will display over the player as well.
\c[6]\b\\c[x]\c[0]     Change message text color (0-8)\b
\c[6]\b\\n[x]\c[0]     Insert actor name\b
\c[6]\b\\v[x]\c[0]     Insert variable value\b
\c[6]\b\\b\c[0]        Toggle bold text\b
\c[6]\b\\w[x]\c[0]     Wait control (0-999)\b
                   Wait values are determined by frame.  40 FPS is the script rate.
\c[6]\b\\p\c[0]        Pause control\b
                   Forces the player to press enter before continuing.
\c[6]\b\\q\c[0]        Forced ending\b
                   Forces the message winddow to close once the character is encountered.
                   Typically best to use directly after a wait timer.
\c[6]\b\\f[x]\c[0]      Force position\b
                   Forces a specific position for the message bubble.

                   \b0\b - Upper right of the sprite
                   \b1\b - Upper left of the sprite
                   \b2\b - Lower right of the sprite
                   \b3\b - Lower left of the sprite
\c[6]\b\\g\c[0]        Displays gold window\b
                    Fades in the gold window to the bottom right corner of the screen.  To keep
                    it displayed after current message, add \\\\g into the next master message.
\c[6]\b\\i[x]\c[0]      Displays an icon from Graphics/Icons\b
\c[6]\b\\z[x]\c[0]      Displays a face graphic from Graphics/Faces\b
                    References an array compiled at runtime from Graphics/Faces.  You will have
                    to create this folder and manually install files.                   
\c[6]\b\\s[x]\c[0]     Sub window controls\b (see documentation for full instructions)"
  end

  def message_2
    @message = %q(          \c[6]\b$game_system Properties\b\c[0]
   
              Change these properties in the Event Editor by using the Script command.  Begin with
              $game_system, then add a "." followed by the property you wish to alter.  In the
              Script command you will need to use two lines.  For example:
             
                          $game_system.message_text_speed =\
                          TEXT_SPEED_FAST
           
          The properties are listed below with available values to the right.  For full
          documentation, refer to the script instructions.
         
              \c[6]\bmessage_text_mode\b\c[0]             TEXT_MODE_INVISIBLE,TEXT_MODE_BUBBLE,TEXT_MODE_WINDOWSKIN
              \c[6]\binvisible_position\b\c[0]                    INVISIBLE_POSITION_TOP,INVISIBLE_POSITION_MIDDLE,
                                                                   INVISIBLE_POSITION_BOTTOM
              \c[6]\bmessage_text_outline\b\c[0]          TEXT_NORMAL,TEXT_OUTLINE
              \c[6]\bmessage_text_speed\b\c[0]           TEXT_SPEED_SLOW,TEXT_SPEED_MEDIUM,TEXT_SPEED_FAST
              \c[6]\bmessage_text_size\b\c[0]               TEXT_SIZE_SMALL,TEXT_SIZE_MEDIUM,TEXT_SIZE_LARGE,
                                                                  TEXT_SIZE_JUMBO
              \c[6]\bmessage_text_font\b\c[0]               TEXT_FONT_DEFAULT, whatever constant you would
                                                                   like to create
              \c[6]\bmessage_text_skip\b\c[0]               TEXT_SKIP_NORMAL,TEXT_SKIP_DOUBLE,TEXT_SKIP_TRIPLE,
                                                                  TEXT_SKIP_QUAD,
                                                                  TEXT_SKIP_QUIN,TEXT_SKIP_FULL
              \c[6]\bmessage_skip_disabled\b\c[0]       true,false
              \c[6]\bface_graphic_type\b\c[0]                  FACE_GRAPHIC_BOX,FACE_GRAPHIC_FULL
              \c[6]\bface_graphic_name\b\c[0]                file name of graphic - without folders
              \c[6]\bdefault_color\b\c[0]                            any Color object
              \c[6]\bmessage_text_outline_color\b\c[0]  any Color object)

  end
   
end

#========================================================================
#   Global Variables - simplest way to create communication between
#                       Interpreter and Window_Message
#========================================================================

$separate_choices = false

#========================================================================
#   Constant Declaration
#========================================================================

# Stores the class methods for quick custom message access
$game_messages = Game_Messages.new

BUBBLE_BOUNCE_ON = 1
BUBBLE_BOUNCE_OFF = 0

BUBBLE_UPPER_LEFT = Rect.new(0,0,13,10)
BUBBLE_LOWER_LEFT = Rect.new(0,10,13,9)
BUBBLE_UPPER_RIGHT = Rect.new(13,0,12,10)
BUBBLE_LOWER_RIGHT = Rect.new(13,10,12,9)

SKIN_UPPER_LEFT = Rect.new(128,0,10,10)
SKIN_LOWER_LEFT = Rect.new(128,54,10,10)
SKIN_UPPER_RIGHT = Rect.new(182,0,10,10)
SKIN_LOWER_RIGHT = Rect.new(182,54,10,10)

TEXT_MODE_BUBBLE = 0
TEXT_MODE_INVISIBLE = 1
TEXT_MODE_WINDOWSKIN = 2

INVISIBLE_POSITION_TOP = [320,0]
INVISIBLE_POSITION_MIDDLE = [320,240]
INVISIBLE_POSITION_BOTTOM = [320,480]
INVISIBLE_POSITION_BOOK = [460,35]

TEXT_NORMAL = 0
TEXT_OUTLINE = 1

TEXT_SPEED_SLOW = 2
TEXT_SPEED_MEDIUM = 1
TEXT_SPEED_FAST = 0

TEXT_SKIP_NORMAL = 1
TEXT_SKIP_DOUBLE = 2
TEXT_SKIP_TRIPLE = 3
TEXT_SKIP_QUAD = 4
TEXT_SKIP_QUIN = 5
TEXT_SKIP_FULL = 6

TEXT_SIZE_SMALL = 14
TEXT_SIZE_MEDIUM = 16
TEXT_SIZE_LARGE = 18
TEXT_SIZE_JUMBO = 28

# Remember to set a common default or fallback font since some users won't have
# them all
TEXT_FONT_DEFAULT = "Arial"
TEXT_FONT_CORSIVA = ["Monotype Corsiva", "Arial"]
TEXT_FONT_BOLI = ["MV Boli", "Arial"]
TEXT_FONT_COMICSANS = ["Comic Sans MS", "Arial"]

TEXT_COLOR_BLACK = Color.new(0,0,0)
TEXT_COLOR_WHITE = Color.new(250,250,250)

FACE_GRAPHIC_FULL = 0
FACE_GRAPHIC_BOX = 1

=begin
# Compile Icon array
# RTP icons are best stored manually
Icons = ['001-Weapon01','002-Weapon02','003-Weapon03','004-Weapon04'\
,'005-Weapon05','006-Weapon06','007-Weapon07','008-Weapon08'\
,'009-Shield01','010-Head01','011-Head02','012-Head03','013-Body01'\
,'014-Body02','015-Body03','016-Accessory01','017-Accessory02'\
,'018-Accessory03','019-Accessory04','020-Accessory05'\
,'021-Potion01','022-Potion02','023-Potion03','024-Potion04'\
,'025-Herb01','026-Herb02','027-Herb03','028-Herb04'\
,'029-Key01','030-Key02','031-Key03','032-Item01'\
,'033-Item02','034-Item03','035-Item04','036-Item05'\
,'037-Item06','038-Item07','039-Item08','040-Item09'\
,'041-Item10','042-Item11','043-Item12','044-Skill01'\
,'045-Skill02','046-Skill03','047-Skill04','048-Skill05'\
,'049-Skill06','050-Skill07']

# All icons in the icon folder are dynamically added at runtime
ICON_FOLDER_PATH = Dir::getwd + "/Graphics/Icons/"
dir = Dir.new(ICON_FOLDER_PATH)
dir.each { |file|
  if file != "." && file != ".."
    Icons.push file
  end
}
=end

# Compile Face array
if File.directory? Dir::getwd + "/Graphics/Faces/"
  Faces = []
  FACE_FOLDER_PATH = Dir::getwd + "/Graphics/Faces/"
  dir = Dir.new(FACE_FOLDER_PATH)
  dir.each { |file|
    if file != "." && file != ".."
      Faces.push file
    end
  }
end

#========================================================================
#   Global Methods
#       Use these methods to quickly modify basic settings or set text
#       to $game_temp.message_text manually
#========================================================================

def message(text)
  $game_system.map_interpreter.message_waiting = true
  $game_temp.message_proc = Proc.new { @message_waiting = false }
  $game_temp.message_text = text
end

def default_color(color)
  # If an integer passed to the method
  if color.class == Fixnum
    case color
    when 0
      $game_system.default_color = TEXT_COLOR_BLACK
    when 1
      $game_system.default_color = Color.new(128, 128, 255, 255)
    when 2
      $game_system.default_color = Color.new(255, 128, 128, 255)
    when 3
      $game_system.default_color = Color.new(128, 255, 128, 255)
    when 4
      $game_system.default_color = Color.new(128, 255, 255, 255)
    when 5
      $game_system.default_color = Color.new(255, 128, 255, 255)
    when 6
      $game_system.default_color = Color.new(255, 255, 128, 255)
    when 7
      $game_system.default_color = Color.new(192, 192, 192, 255)
    when 8
      $game_system.default_color = TEXT_COLOR_WHITE
    else
      $game_system.default_color = TEXT_COLOR_BLACK
    end
  # If a Color class value is passed to the method
  elsif color.class == Color
    $game_sytem.default_color = color
  end

  return true
end

def mood_color(color)
  case color
  when 0
    return Color.new(70,130,180,190)
  when 1
    return Color.new(178,34,34,190)
  when 2
    return Color.new(238,174,238,190)
  when 3
    return Color.new(139,136,120,180)
  when 4
    return Color.new(255,215,0,190)
  end
end

def face(name)
  $game_system.face_graphic_name = name
end

def clear_face
  $game_system.face_graphic_name = nil
end

def small_text
  $game_system.message_text_size == TEXT_SIZE_SMALL
end

def medium_text
  $game_system.message_text_size == TEXT_SIZE_MEDIUM
end

def large_text
  $game_system.message_text_size == TEXT_SIZE_LARGE
end

def jumbo_text
  $game_system.message_text_size == TEXT_SIZE_JUMBO
end

def slow_text
  $game_system.message_text_speed == TEXT_SPEED_SLOW
end

def fast_text
  $game_system.message_text_speed == TEXT_SPEED_FAST
end

#========================================================================
#   Game Temp
#
#       @current_event - tracks the current game event for ease of access
#========================================================================

class Game_Temp

  attr_accessor :current_event
  attr_accessor :consecutive_gold_window

  alias old_initialize initialize

  def initialize
    old_initialize
    @current_event = nil
    @consecutive_gold_window = false
  end

end

#========================================================================
#   Game System
#
#       Stores message text options
#       Use $game_system to view and change values
#========================================================================

class Game_System
  attr_accessor :message_text_mode
  attr_accessor :message_bubble_bounce
  attr_accessor :invisible_position
  attr_accessor :message_text_outline
  attr_accessor :message_text_speed
  attr_accessor :message_text_size
  attr_accessor :message_text_font
  attr_accessor :message_skip_disabled
  attr_accessor :face_graphic_type
  attr_accessor :face_graphic_name
  attr_accessor :message_text_skip
  attr_accessor :default_color
  attr_accessor :message_text_outline_color

  alias old_initialize initialize

  def initialize
    old_initialize
    @message_text_mode = TEXT_MODE_BUBBLE
    @message_bubble_bounce = BUBBLE_BOUNCE_ON
    @invisible_position = INVISIBLE_POSITION_TOP
    @message_text_outline = TEXT_NORMAL
    @message_text_speed = TEXT_SPEED_FAST
    @message_text_size = TEXT_SIZE_SMALL
    @message_text_font = TEXT_FONT_DEFAULT
    @message_text_skip = TEXT_SKIP_NORMAL
    @message_skip_disabled = false
    @face_graphic_type = FACE_GRAPHIC_BOX
    @face_graphic_name = nil
    @default_color = TEXT_COLOR_BLACK
    @message_text_outline_color = TEXT_COLOR_WHITE
   
  end

end

#========================================================================
#   Game Player
#
#        The only change is in the condition --if Input.trigger?(Input::C)--
#        The change allows for $game_temp.message text to be manually
#          altered and still function properly
#========================================================================

class Game_Player
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Remember whether or not moving in local variables
    last_moving = moving?
    # If moving, event running, move route forcing, and message window
    # display are all not occurring
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      # Move player in the direction the directional button is being pressed
      case Input.dir4
      when 2
        move_down
      when 4
        move_left
      when 6
        move_right
      when 8
        move_up
      end
    end
    # Remember coordinates in local variables
    last_real_x = @real_x
    last_real_y = @real_y
    super
    # If character moves down and is positioned lower than the center
    # of the screen
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # Scroll map down
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # If character moves left and is positioned more let on-screen than
    # center
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # Scroll map left
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # If character moves right and is positioned more right on-screen than
    # center
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # Scroll map right
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # If character moves up and is positioned higher than the center
    # of the screen
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # Scroll map up
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # If not moving
    unless moving?
      # If player was moving last time
      if last_moving
        # Event determinant is via touch of same position event
        result = check_event_trigger_here([1,2])
        # If event which started does not exist
        if result == false
          # Disregard if debug mode is ON and ctrl key was pressed
          unless $DEBUG and Input.press?(Input::CTRL)
            # Encounter countdown
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      #-----------------------------------------------------------------
      #  Allows messages to display without interruption when directly
      #  assigned to $game_temp.message_text
      #-----------------------------------------------------------------
      # If C button was pressed
      if Input.trigger?(Input::C) && $game_temp.message_text == nil
        # Same position and front event determinant
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end

#========================================================================
#   Interpreter
#
#       Edit forces the interpreter to wait to update until all messages
#         currently on screen have finished writing
#========================================================================


class Interpreter

  attr_accessor :list
  attr_accessor :index
  attr_accessor :message_waiting

  alias old_update update

  def update
   
    #if $scene.message_window != nil && $scene.message_window.finished != nil
    if $game_temp.message_text != nil
      return
    else
      old_update
      $game_temp.current_event = @event_id
    end
  end

  def command_101
    # If other text has been set to message_text
    if $game_temp.message_text != nil
      # End
      return false
    end
    # Check for consecutive gold window calls
    temp_index = @index+1
    loop do
      case @list[temp_index].code
      when 401
        temp_index += 1
      when 101
        break
      else
        break
      end
    end
   
    # Search for consecutive message window with /g formatter
    text = nil
   
    # Iterate through max possible message size
    for i in 0...3
      # Check for existence of list element before checking code
      if @list[temp_index+i] != nil
        # Search for /g
        if @list[temp_index+i].code == 101 or @list[temp_index+i].code == 401
          text = @list[temp_index+i].parameters[0].slice(/\\[Gg]/)
          if text != nil
            # Allows for gold window to continue after first message
            $game_temp.consecutive_gold_window = true
            break
          end
        end
      end
    end
    # Turns consecutive flag off if need be
    if $game_temp.consecutive_gold_window == true && text == nil
      $game_temp.consecutive_gold_window = false
    end
    # Set message end waiting flag and callback
    @message_waiting = true
    $game_temp.message_proc = Proc.new { @message_waiting = false }
    # Set message text on first line
    $game_temp.message_text = @list[@index].parameters[0] + "\n"
    line_count = 1
    # Loop
    loop do
      # If next event command text is on the second line or after
      if @list[@index+1].code == 401
        # Add the second line or after to message_text
        $game_temp.message_text += @list[@index+1].parameters[0] + "\n"
        line_count += 1
      # If event command is not on the second line or after
      else       
        # If next event command is show choices
        if @list[@index+1].code == 102
          # Make sure choice appellation is allowed
          for choice in @list[@index+1].parameters[0]
            if choice.slice(/\\[Nn][Cc]/)
              $separate_choices = true
              break
            end
          end
          if $separate_choices == true
            return
          end
          # Advance index
          @index += 1
          # Choices setup
          $game_temp.choice_start = line_count
          #Insert 5 spaces for indenting choices
          for i in 0...@list[@index].parameters[0].size
            if @list[@index].parameters[0][i].slice(0,5) != '     '
              @list[@index].parameters[0][i].insert(0,'     ')
            end
          end
          setup_choices(@list[@index].parameters)
        # If next event command is input number
        elsif @list[@index+1].code == 103
          # If number input window fits on screen
          if line_count < 4
            # Advance index
            @index += 1
            # Number input setup
            $game_temp.num_input_start = line_count
            $game_temp.num_input_variable_id = @list[@index].parameters[0]
            $game_temp.num_input_digits_max = @list[@index].parameters[1]
          end
        end
        # Continue
        return true
      end
      # Advance index
      @index += 1
    end
  end
end

#========================================================================
#   Spriteset Map
#
#       Edit allows access to the character_sprites variable
#       Use $game_map.character_sprites to access
#========================================================================

class Spriteset_Map

  attr_accessor :character_sprites 

end

class Scene_Map

  attr_accessor :spriteset
  attr_accessor :message_window

end

#========================================================================
#   Window Base
#
#       Edit allows for color 8 (black)
#========================================================================

class Window_Base < Window

  #--------------------------------------------------------------------------
  # * Get Text Color
  #     n : text color number (0-7)
  #--------------------------------------------------------------------------
  def text_color(n)
    case n
    when 0
      return Color.new(250, 250, 250, 255)
    when 1
      return Color.new(45, 45, 255, 255)
    when 2
      return Color.new(255, 45, 45, 255)
    when 3
      return Color.new(45, 255, 45, 255)
    when 4
      return Color.new(45, 215, 215, 255)
    when 5
      return Color.new(255, 45, 255, 255)
    when 6
      return Color.new(230, 230, 15, 255)
    when 7
      return Color.new(125, 125, 125, 255)
    when 8
      return Color.new(0, 0, 0)
    else
      normal_color
    end
  end

end

#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  The gold window has been modified to use an icon and some outlined text
#==============================================================================

class Window_Gold_New < Window_Base
  def initialize
    @current_gold = $game_party.gold
   
    @icon = Sprite.new
    @icon.opacity = 0
    @icon.bitmap = Bitmap.new('Graphics/Icons/032-Item01')
    @icon.ox = @icon.bitmap.width/2
    @icon.oy = @icon.bitmap.height/2
    @icon.x,@icon.y = 624,460
   
    draw_gold
  end

  def update
    refresh
    @icon.opacity += 12 if @icon.opacity < 192
    @gold.opacity += 12 if @gold.opacity < 192
  end

  def refresh
    if @current_gold != $game_party.gold
      @current_gold = $game_party.gold
      @gold.bitmap.clear
      draw_gold
    end
  end

  def draw_gold
    @gold = Sprite.new
    @gold.opacity = 0
    @gold.bitmap = Bitmap.new(100,32)
    @gold.ox,@gold.oy = @gold.bitmap.width/2,@gold.bitmap.height/2
    @gold.x = 560
    @gold.y = 465
    @gold.z = 50
    @gold.bitmap.font.size = 18
    @gold.bitmap.font.bold = true
    @gold.bitmap.font.color = text_color(8)
    @gold.bitmap.draw_text(22,0,75,30,$game_party.gold.to_s,2)
    @gold.bitmap.draw_text(22,2,75,30,$game_party.gold.to_s,2)
    @gold.bitmap.draw_text(21,1,75,30,$game_party.gold.to_s,2)
    @gold.bitmap.draw_text(23,1,75,30,$game_party.gold.to_s,2)
    @gold.bitmap.font.color = text_color(6)
    @gold.bitmap.draw_text(22,1,75,30,@current_gold.to_s,2)
  end

  def fade_out
    @icon.opacity -= 48
    @gold.opacity -= 48
  end

  def dispose
    @icon.bitmap.dispose
    @icon.dispose
    @gold.bitmap.dispose
    @gold.dispose
  end

end

#==============================================================================
# ** Window_InputNumber
#------------------------------------------------------------------------------
#  This window is for inputting numbers, and is used within the
#  message window.
#==============================================================================

class Window_InputNumber < Window_Base

  attr_accessor :x
  attr_accessor :y

  #--------------------------------------------------------------------------
  # * Object Initialization
  #     digits_max : digit count
  #--------------------------------------------------------------------------
  def initialize(digits_max,x=0,y=0,indent=0)
    @digits_max = digits_max
    @number = 0
    @x = x
    @y = y
    @indent = indent
    @count = 0
    @move_right = true
    # Calculate character width for drawing and tracking cursor movement
    dummy_bitmap = Bitmap.new(32, 32)
    dummy_bitmap.font.size = $game_system.message_text_size
    dummy_bitmap.font.name = $game_system.message_text_font
    @width = (dummy_bitmap.text_size('0').width\
        + dummy_bitmap.text_size(' ').width)
    @x = @x - (@width*@digits_max)
    dummy_bitmap.dispose
    @index = 0
    # Create number display bitmap
    @number_window = Sprite.new
    @number_window.x = @x
    @number_window.y = @y
    @number_window.z = 15
    @number_window.bitmap = Bitmap.new(@width*@digits_max, 40)
    @number_window.bitmap.font.color = TEXT_COLOR_BLACK
    @number_window.bitmap.font.size = $game_system.message_text_size
    @number_window.bitmap.font.name = $game_system.message_text_font
    # Create the cursor to track input position
    create_cursor
  end
  #--------------------------------------------------------------------------
  # * Get Number
  #--------------------------------------------------------------------------
  def number
    return @number
  end
  #--------------------------------------------------------------------------
  # * Set Number
  #     number : new number
  #--------------------------------------------------------------------------
  def number=(number)
    @number = [[number, 0].max, 10 ** @digits_max - 1].min
    refresh
  end
  #--------------------------------------------------------------------------
  # * Create Cursor
  #--------------------------------------------------------------------------
  def create_cursor
    @cursor = Sprite.new
    @cursor.bitmap = Bitmap.new(32,5)
    @cursor.x = @number_window.x
    @cursor.y = @number_window.y\
              + @number_window.bitmap.text_size('0').height + 3
    @cursor.z = 16
    @cursor.opacity = 185
    width = @number_window.bitmap.text_size('0').width + 2
    @cursor.bitmap.fill_rect(0,0,width,2,text_color(1))
  end
  #--------------------------------------------------------------------------
  # * Cursor Update
  #--------------------------------------------------------------------------
  def update_cursor
    @count += 1
    if @count % 10 == 0
      if @move_right == true
        @cursor.x += 1
      else
        @cursor.x -= 1
      end
      if @count == 20
        if @move_right == true
          @move_right = false
        else
          @move_right = true
        end
        @count = 0
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    update_position
    # If up or down directional button was pressed
    if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
      $game_system.se_play($data_system.cursor_se)
      # Get current place number and change it to 0
      place = 10 ** (@digits_max - 1 - @index)
      n = @number / place % 10
      @number -= n * place
      # If up add 1, if down substract 1
      n = (n + 1) % 10 if Input.repeat?(Input::UP)
      n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
      # Reset current place number
      @number += n * place
      refresh
    end
    # Cursor right
    if Input.repeat?(Input::RIGHT)
      if @digits_max >= 2
        $game_system.se_play($data_system.cursor_se)
        @index = (@index + 1) % @digits_max
        @cursor.x += @width
        if @index == 0
          @cursor.x = @number_window.x
        end
      end
    end
    # Cursor left
    if Input.repeat?(Input::LEFT)
      if @digits_max >= 2
        $game_system.se_play($data_system.cursor_se)
        @index = (@index + @digits_max - 1) % @digits_max
        @cursor.x -= @width
        if @index == @digits_max - 1
          @cursor.x += @width * @digits_max
        end
      end
    end
    update_cursor
  end

  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------

  def dispose
    @number_window.bitmap.clear
    @number_window = nil
    @cursor.bitmap.clear
    @cursor = nil
  end

  #--------------------------------------------------------------------------
  # * Update Position for Bubble Movement
  #--------------------------------------------------------------------------

  def update_position
    if @number_window.x != @x
      @number_window.x = @x
      @cursor.x = @number_window.x + (@index * @width)
    end
    if @number_window.y != @y
      @number_window.y = @y
      @cursor.y = @number_window.y\
                + @number_window.bitmap.text_size('0').height + 3
    end   
  end

  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    @number_window.bitmap.clear
    s = sprintf("%0*d", @digits_max, @number)
    for i in 0...@digits_max
      @number_window.bitmap.draw_text(i * @width, 0, 32, 32, s[i,1])
    end
  end
end

#========================================================================
#   Window Message
#
#       Controls message displayed from the show text event command
#
#       This modified version also allows for a message to be displayed
#         from a script.  Simply change $game_temp.message_text to
#         whatever text you want to display.  Remember that outside
#         of the message entry box in the event commands, you will have
#         to manuall insert the newline character "\n".)
#========================================================================

class Window_Message < Window_Base

  attr_accessor :contents_showing
  attr_accessor :finished
  attr_accessor :fade_in
  attr_accessor :fade_out
  attr_accessor :message
  attr_accessor :enter_pressed

  #--------------------------------------------------------------------------
  # * Object Initialization
  #
  #       Prepare message variables, then wait for re_initialize
  #--------------------------------------------------------------------------
  def initialize(sub=false, text=nil)
    # Bubble message variables
    @enter_pressed = false
    @text_height = 0
    @fade_in = false
    @event = 0
    @contents_showing = false
    @finished = nil
    @position = ''
    @active = false
    @lines = 0
    @up = 0
    @count = 0
    @cursor_count = 0
    @cursor_move_right = nil
    @wait = 0
    @wait_add = 0
    @pause = false
    @index = 0
    @sub = sub
    @face = nil
    @face_extension_x = 0
    @face_extension_y = 0
    @thought = false
    @bubble_color = nil
    @hp = nil
    if @sub == false
      @sub_number = nil
      @sub_windows = []
    end
    @indent = false
    @text = text
  end
  #--------------------------------------------------------------------------
  # * Re_Initialize
  #
  #       Call when actual text processing occurs
  #--------------------------------------------------------------------------
    def re_initialize
     
      if $game_temp.message_text != nil
        # Prevent improper cursor indention on choices
        @indent = false
        if $game_system.face_graphic_name != nil
          @face = $game_system.face_graphic_name
        else
          @face = nil
        end
        @face_extension_x = 0
        @face_extension_y = 0
       
        temp = Sprite.new
        temp = Bitmap.new(32,32)
        # Set @text to whatever text will display
        # For sub messages this will already be set
        if @text == nil
          @text = $game_temp.message_text
        end
       
        # Change \ escaped characters to character codes for processing
        prep_text
       
        # Determine number of lines in the message
        @lines = 0
        @text.each_line {|line|
          @lines += 1
        }
       
        temp_text = @text.clone
        # Get rid of any non displayed elements to determine the
        #   appropriate message box size
       
        def get_digits(integer)
          if integer < 10
            return 1
          elsif integer >= 10
            return 2
          elsif integer >= 100
            return 3
          end
        end
       
        while temp_text.slice(/\001\[([0-9]+)\]/)
          temp_text.slice!(/\001\[([0-9]+)\]/)
        end
       
        while temp_text.slice(/\002/)
          temp_text.slice!(/\002/)
        end
       
        while temp_text.slice(/\004\[([0-9]+)\]/)
          temp_text.slice!(/\004\[([0-9]+)\]/)
        end
       
        while temp_text.slice(/\005\[([0-9]+)\]/) != nil
          temp_text.slice!(/\005\[([0-9]+)\]/)
        end
       
        while temp_text.slice(/\006/)
          temp_text.slice!(/\006/)
        end
       
        while temp_text.slice(/\007\[([0-9]+)\]/)
          temp_text.slice!(/\007\[([0-9]+)\]/)
        end
       
        while temp_text.slice(/\011/) != nil
          temp_text.slice!(/\011/)
        end
               
        while temp_text.slice(/\015\[([0-9]+)\]/)
          temp_text.slice!(/\015\[([0-9]+)\]/)
          @face = Faces[$1.to_i]
        end
       
        # Make sure @thought is false unless specified true
        @thought = false
        while temp_text.slice(/\017/)
          temp_text.slice!(/\017/)
          @thought = true
          @text.slice!(/\017/)
        end
       
        # Change @bubble_color to keep default color unless specified other color
        @bubble_color = nil
        while temp_text.slice(/\018\[([0-9]+)\]/)
          temp_text.slice!(/\018\[([0-9]+)\]/)
          @bubble_color = mood_color($1.to_i)
          @text.slice!(/\018\[([0-9]+)\]/)
        end
       
        # Determine message bubble size
        bitmap = Sprite.new
        bitmap.bitmap = Bitmap.new(32,32)
        bitmap.bitmap.font.name = $game_system.message_text_font
        bitmap.bitmap.font.size = $game_system.message_text_size
        @text_rect = Rect.new(0,0,0,0)
        @line_width = []
        i = 0
        temp_text.each_line {|line|
          temp = bitmap.bitmap.text_size(line)
          @line_width[i] = temp.width
          if temp.width > @text_rect.width
            @text_rect.width = temp.width
          end
          @text_height = temp.height
          i += 1
        }
       
        # Add space for number input if necessary
        if $game_temp.num_input_variable_id > 0 && @sub == false
          @lines += 1
        end

        @text_rect.height = @text_height * @lines
       
        total_size = 0
        longest_line = 0
        current_line_height = @text_height
        @line_height_correction = [0,0,0,0]
        line = 0
        skip = 0
       
        for i in 0...temp_text.size
          # Check for bold toggling and icon insertion
          if temp_text[i] == 3
            bitmap.bitmap.font.bold == false ? bitmap.bitmap.font.bold = true : bitmap.bitmap.font.bold = false
          end
          # Check for icon insertion and add 24 pixels to this line's width
          if temp_text[i] == 12
            # Add sufficient width for an icon to be inserted in the text
            total_size += 24
            # Adjust the height of the text box if necessary
            if current_line_height < 24
              current_line_height = 24
              @text_rect.height += (24 - @text_height)
              @line_height_correction[line] = (24 - @text_height)
            end
            # Set variable to skip over icon text in sizing operations
            skip = 4
          end
          # Check for face graphic
          if temp_text[i] == 13
            temp_text.slice(/\015\[([0-9]+)\]/)
            skip = 4
            @face = Faces[$1.to_i]
          end
          # Check for new line character
          if temp_text[i] == 10
            total_size = 0
            current_line_height = @text_height
            line += 1
          end
          # Do not size characters relating to an icon
          if skip == 0
            total_size += bitmap.bitmap.text_size(temp_text.slice(i,1)).width
          else
            skip -= 1
          end
          # Make sure longest line sets the bubble width value
          longest_line = total_size if total_size > longest_line
        end
       
        # Insert facce graphic name if none explicit in message and
        # one is stored in $game_system
        if $game_system.face_graphic_name != nil && temp_text.slice(/\015\[([0-9]+)\]/) == nil
          @face = $game_system.face_graphic_name
        end
        # Account for face graphic in message box graphic
        if @face != nil
          determine_face_extension
        else
          @face_extension_x = 0
          @face_extension_y = 0
        end
       
        if $game_system.face_graphic_type == FACE_GRAPHIC_FULL
          @text_rect.width = longest_line
        else
          @text_rect.width = longest_line + @face_extension_x
        end

        # Set start values for text drawing
        @x=@y=0
        # Determine message position and create the message bubble
        #(only if $game_system.message_text_mode == TEXT_MODE_BUBBLE       
        if $game_system.message_text_mode != TEXT_MODE_INVISIBLE
          # Check for existence of necessary Bubble files if mode is set to Bubble
          if $game_system.message_text_mode == TEXT_MODE_BUBBLE
            # Correct text mode if files do not exist
            if File.exist?("Graphics/Pictures/Message_Bubble.png") == false || \
              File.exist?("Graphics/Pictures/Pointer2.png") == false
              $game_system.message_text_mode = TEXT_MODE_WINDOWSKIN
              default_color(8)
            end
          end           
          determine_position
          create_bubble
        else
          @bubble_correction_y = 0
          @message_box = Sprite.new
          @message_box.bitmap = Bitmap.new(@text_rect.width+25, @text_rect.height+26)
          @message_box.ox = @message_box.bitmap.width/2
          @message_box.oy = @message_box.bitmap.height/2
          @message_box.x = $game_system.invisible_position[0]
          @message_box.y = $game_system.invisible_position[1]
          if @message_box.y - @message_box.bitmap.height/2 < 0
            @message_box.y += @message_box.bitmap.height/2
          elsif @message_box.y + @message_box.bitmap.height/2 > 480
            @message_box.y -= @message_box.bitmap.height/2
          end
        end
        # Create message sprite for drawing actual text
        @message = Sprite.new
        @message.x = @message_box.x
        @message.y = @message_box.y
        if @sub == false
          @message.z += 1
        end
        @message.ox = @message_box.ox
        @message.oy = @message_box.oy
        @message.bitmap = \
          Bitmap.new(@message_box.bitmap.width,@message_box.bitmap.height)
        @message.bitmap.font.size = $game_system.message_text_size
        @message.bitmap.font.color = TEXT_COLOR_BLACK
        @speed = $game_system.message_text_speed
        @text_color = $game_system.default_color
      end
    end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    terminate_message
    $game_temp.message_window_showing = false
    if @input_number_window != nil
      @input_number_window.dispose
    end
  end

  #--------------------------------------------------------------------------
  # * Subs Finished?
  #
  #       Checks to see if all sub messages have finished writing
  #--------------------------------------------------------------------------
  def subs_finished?
    abort_flag = true
    count = 0
    for sub in @sub_windows
      count += 1 if (sub.finished == true && sub.enter_pressed == false)
      if sub.finished && sub.enter_pressed
        sub.enter_pressed = false
      end
    end
    abort_flag = false if count == @sub_windows.size
    if abort_flag == true
      return false
    else
      return true
    end
  end

  #--------------------------------------------------------------------------
  # * Erase Subs
  #
  #       Erases any existing subb messages
  #--------------------------------------------------------------------------
  def erase_subs
    if @sub_windows != nil
      for sub in @sub_windows
        sub.fade_out = true
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Terminate Message
  #--------------------------------------------------------------------------
  def terminate_message
    # Call message callback
    if @message != nil
      @message_box.bitmap.clear
      @message.z -= 1
      @message.bitmap.clear
    end
    if @cursor != nil
      @cursor.bitmap.clear
      @cursor.dispose
      @cursor = nil
    end
    if $game_temp.message_proc != nil
      $game_temp.message_proc.call
    end
    # Clear variables related to text, choices, and number input
    $game_temp.message_text = nil
    $game_temp.message_proc = nil
    $game_temp.choice_start = 99
    $game_temp.choice_max = 0
    $game_temp.choice_cancel_type = 0
    $game_temp.choice_proc = nil
    $game_temp.num_input_start = 99
    $game_temp.num_input_variable_id = 0
    $game_temp.num_input_digits_max = 0
    # Dispose of gold window
    if @gold_window != nil && $game_temp.consecutive_gold_window == false
      @gold_window.dispose
      @gold_window = nil
    end
    @contents_showing = false
    @finished = nil
    @active = false
    $game_temp.message_window_showing = false
    @text = nil
    if @sub == false
      erase_subs
      temp = subs_finished?
      if temp == true
        for i in 0...@sub_windows.size
          @sub_windows[i] = nil
        end
        @sub_windows = []
      end
    end
    @sub_number = nil
  end
  #--------------------------------------------------------------------------
  # * Draw_Message
  #--------------------------------------------------------------------------
  def draw_message
    return if @pause == true
    return if @text == nil
    # Indent if choice and following message text
    index = $game_system.map_interpreter.index - 2
    code = $game_system.map_interpreter.list[index].code

    # Check for choice following a line of text
    if @y == $game_temp.choice_start && (code == 101 || code == 401) \
      && @indent == false && $separate_choices == false
      @indent = true
      #@x = 16 + @face_extension_x
    end
   
    if @wait == 0

      # Set correction for icon insertion
      y_correction = 0
      for i in 0..@y
        if @line_height_correction[i] != nil
          y_correction += @line_height_correction[i]
        end
      end
      # Set offset value dependant on text mode
      if $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
        offset = 10
      elsif $game_system.message_text_mode == TEXT_MODE_BUBBLE
        offset = 13
      else
        offset = 0
      end

      if @face != nil
        if $game_system.face_graphic_type == FACE_GRAPHIC_FULL
          base_y = (@face_extension_y + @text_rect.height) - (@text_rect.height + 20)
        else
          base_y = @bubble_correction_y
        end
      else
        base_y = @bubble_correction_y
      end
      @text_y ||= base_y
      y = @text_y + (@text_height * @y) + @bubble_correction_y + y_correction
     
      # Insert face graphic if included
      if @text.slice!(/\015\[([0-9]+)\]/) || @face != nil
        draw_face
      end
     
      # Check for formatting options character from text
      @c = @text[0,1].slice(/./m)
      case @c
      # If \\
      when "\000"
        # Return to original text
        @c = "\\"
        @text.sub!("\000") {"\\"}
        return
      # If \C[n]
      when "\001"
        # Change text color
        @text.sub!(/\[([0-9]+)\]/, "")
        color = $1.to_i
        if color >= 0 and color <= 8
          @message.bitmap.font.color = text_color(color)
          @text_color = text_color(color)
        end
        @text.slice!("\001")
        # go to next text
        return
      # If \G
      when "\002"
        # Make gold window
        if @gold_window == nil
          @gold_window = Window_Gold_New.new
          #@gold_window.x = 560 - @gold_window.width
          if $game_temp.in_battle
          #  @gold_window.y = 192
          else
          #  @gold_window.y = 0
          end
          #@gold_window.opacity = @message.opacity
          #@gold_window.back_opacity = 200
        end
        @text.slice!("\002")
        # go to next text
        return
      # If \B
      when "\003"
        if @message.bitmap.font.bold == false
          @message.bitmap.font.bold = true
        else
          @message.bitmap.font.bold = false
        end
        @text.slice!("\003")
        return
      # If sub window is being called
      when "\004"
        @text.slice!("\004")
        @text.sub!(/\[([0-9]+)\]/, "")
        if @sub == false
          @sub_number = $1
          event_key = $game_temp.current_event
          # Find the cooresponding slave window
          # Must immediately follow master window and be
          # in consecutive order
          num = 0
          index = 0
          if $game_system.map_interpreter.list[$game_system.map_interpreter.index].code == 101 \
            && num != @sub_number.to_i
            for i in $game_system.map_interpreter.index\
              ...$game_system.map_interpreter.list.size
              if $game_system.map_interpreter.list[i].code == 101
                num = $game_system.map_interpreter.list[i].parameters[0].slice(/\\[Ss]\[([0-9]+)\]/)
                num = num.slice(/([0-9]+)/).to_i if num!= nil
                if num != nil
                  if num != @sub_number.to_i
                    num += 1
                  end
                  index = i
                end
                if num == @sub_number.to_i
                  break
                end
              end
            end
          else
            index = $game_system.map_interpreter.index
          end
          $game_system.map_interpreter.index = index
          # Save original index value for later
          original_index = $game_system.map_interpreter.index
          lines = 1
          if $game_system.map_interpreter.list[index].code == 101
            # Loop until the cooresponding \s[x] character is found
            loop do
              # Break if there is nothing more to sort through
              if $game_system.map_interpreter.list[index] == nil
                break
              end
              # Check the \s[x] for a match with the initial match in master message
              temp = $game_system.map_interpreter.list[index].parameters.clone
              number = temp[0].slice(/\\[Ss]\[([0-9]+)\]/)
              if number != nil
                number = number.slice(/[0-9]+/)
              end
              # If the proper match is found, create sub window
              if number == @sub_number
                # Create message text for sub message
                # Make sure sub message begins at first line
                while $game_system.map_interpreter.list[index].code != 101
                  index -= 1
                end
                text = $game_system.map_interpreter.list[index].parameters[0].clone
                if $game_system.map_interpreter.list[index+1].code == 401
                  text = text + "\n"
                  lines += 1
                end
                # Continue to add text if there is something to be added
                if $game_system.map_interpreter.list[index+1].code == 401
                  # Loop until all sub message text is added
                  loop do
                    index += 1
                    text = text + $game_system.map_interpreter.list[index].parameters[0].clone
                    if $game_system.map_interpreter.list[index+1].code == 401
                      text = text + "\n"
                      lines += 1
                    else
                      break
                    end
                  end
                end
                # If last sub window, set event index
                if @text.slice("\004") == nil
                  $game_system.map_interpreter.index = index + 1
                end
                # Create actual sub window object and place it into
                # @sub_windows array for update and disposal
                sub = Window_Message.new(true,text)
                @sub_windows.push sub
                break
              else
                index += 1
              end
            end # end loop
          return
          end # end if code == 101
        end
      # When \w[x]
      when "\005"
        @text.slice!(/\005\[([0-9]+)\]/)
        @wait_add = $1.to_i
        @wait += @wait_add
        @wait_add = 0
        return
      # When \p
      when "\006"
        @text.slice!("\006")
        if @enter_pressed == false
          @pause = true
        end
        return
      # When \q
      when "\011"
        terminate_message
        return
      # When \i[x]
      when "\014" 
        #@text.slice!(/\014\[([0-9]+)\]/)
        @text.slice!(/\014\[([0-9A-Za-z_\-]+)\]/)
        icon = Sprite.new
        icon.opacity = 0
        icon.bitmap = RPG::Cache.icon($1)
        true_y = @text_y + (@y * @text_height) + y_correction #+ y + @face_extension_y - (@text_rect.height + 25)
        @message.bitmap.blt(offset+@x+@face_extension_x,true_y,icon.bitmap,Rect.new(0,0,24,24))
        @x += 24
      # When \h[x]
      when "\016"
        @text.slice!(/\016\[([0-9]+)\]/)
        @hp = $game_party.actors[$1.to_i].hp
      end
     
      # Get 1 character from text
      @c = @text.slice!(/./m)

      if @c == nil
        @finished = true
        if $game_temp.choice_max > 0
          @cursor_move_right = true
          @index = 0
          create_cursor
          $separate_choices = false
        elsif $game_temp.num_input_variable_id > 0 && @sub == false
          digits_max = $game_temp.num_input_digits_max
          number = $game_variables[$game_temp.num_input_variable_id]
          x = @message.x + @message.bitmap.width/2 - 13
          y = @message.y - @message.bitmap.height/2\
              + @text_height * (@y) + @bubble_correction_y
          @input_number_window = Window_InputNumber.new(digits_max,x,y,@face_extension_x)
          @input_number_window.number = number
        end
        return
      end
      # If new line text
      if @c == "\n"
        # Add 1 to y
        @y += 1
        @x = 0
        # Indent if choice
        if @y >= $game_temp.choice_start
          @x = 0
        end
        # go to next text
        return
      end
      # Draw text   
      @message.bitmap.font.name = $game_system.message_text_font
      # Set exact y value for drawing
      if @face_extension_y != 0
        true_y = y + @face_extension_y - (@text_rect.height + 25)
      else
        true_y = y
      end
     
      true_y = @text_y + @y*@text_height + y_correction
     
      if $game_system.message_text_outline == TEXT_OUTLINE
        if $game_system.message_text_outline == TEXT_OUTLINE
          @message.bitmap.font.color = $game_system.message_text_outline_color
        elsif @message.bitmap.font.color != $game_system.default_color
          @message.bitmap.font.color = $game_system.default_color
        end
        # Correct character writing position for lower case "f"
        # due to Monotype Corsiva text writing glitch
        temp = @x
        if  @c == 'f' && $game_system.message_text_font == TEXT_FONT_CORSIVA
          @x -= 2
        end
        @message.bitmap.draw_text(offset+@x+@face_extension_x+1,true_y,40,32,@c)
        @message.bitmap.draw_text(offset+@x+@face_extension_x-1,true_y,40,32,@c)
        @message.bitmap.draw_text(offset+@x+@face_extension_x,true_y+1,40,32,@c)
        @message.bitmap.draw_text(offset+@x+@face_extension_x,true_y-1,40,32,@c)
       
        # Correct any change made to @x so that text is written
        # in the proper place
        if  @x != temp
          @x = temp
        end
       
      end
     
      @message.bitmap.font.color = @text_color
     
      # Correct character writing position for lower case "f"
      # due to Monotype Corsiva text writing glitch
      temp = @x
      if @c == 'f' && $game_system.message_text_font == TEXT_FONT_CORSIVA
        @x -= 2
      end
      @message.bitmap.draw_text(offset+@x+@face_extension_x,true_y,40,32,@c)
      # Correct any change made to @x so that text is written
      # in the proper place
      if @x != temp && $game_system.message_text_font == TEXT_FONT_CORSIVA
        @x = temp
      end
      # Add x to drawn text width
      @x += @message.bitmap.text_size(@c).width
      @wait = $game_system.message_text_speed
      @wait_add = 0
    else
      @wait -= 1
    end
  end

  #--------------------------------------------------------------------------
  # * Determine Face Extension
  #     This method determines how much distance needs to be added to the
  #     face graphic
  #--------------------------------------------------------------------------
  def determine_face_extension
    sprite = Sprite.new
    sprite.opacity = 0
    sprite.bitmap = Bitmap.new("Graphics/Faces/#{@face}")
    # Set extension value in horizontal direction
    if @face != nil
      @face_extension_x = sprite.bitmap.width
      if $game_system.face_graphic_type == FACE_GRAPHIC_BOX
        @face_extension_x += 5
      end
      if sprite.bitmap.height > @text_rect.height
        @face_extension_y = sprite.bitmap.height - @text_rect.height
      end
    end
    sprite.bitmap.dispose
    sprite = nil
  end

  #--------------------------------------------------------------------------
  # * Draw Face Graphics
  #--------------------------------------------------------------------------
  def draw_face
    sprite = Sprite.new
    sprite.opacity = 0
    sprite.bitmap = Bitmap.new("Graphics/Faces/#{@face}")
    rect = Rect.new(0,0,sprite.bitmap.width,sprite.bitmap.height)
    if $game_system.face_graphic_type == FACE_GRAPHIC_FULL
      @message.bitmap.blt(0,0,sprite.bitmap,rect)
    else
      y = @text_y + 10
      @message.bitmap.blt(13,y,sprite.bitmap,rect)
    end
    sprite.bitmap.dispose
    sprite = nil
  end

  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if @pause == false
      if Input.trigger?(Input::C) && $game_system.message_skip_disabled == false
        @enter_pressed = true
        until @c == nil || @text == nil
          draw_message
        end
        @enter_pressed = false if @sub == false
      else
        if $game_system.message_text_skip != TEXT_SKIP_FULL
          count = $game_system.message_text_skip
          for i in 0...count
            draw_message if (@c != nil || @text != nil)
          end
        else
          if @c == nil && @text != nil
            draw_message
          end
          until @c == nil || @text == nil
            draw_message
          end
        end
      end
    else
      if Input.trigger?(Input::C)
        temp = subs_finished?
        if temp == true
          erase_subs
          @pause = false
        end
      end
      draw_message
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update sub messages if they exist
    if @sub_windows != nil
      for i in 0...@sub_windows.size
        @sub_windows[i].update
      end
    end
    # Update gold window if it exists
    if @gold_window != nil
      @gold_window.update
    end
    # Update bubble graphic
    if @active == true && ($game_system.message_text_mode == TEXT_MODE_BUBBLE \
      || $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN)
      update_bubble
    end
    # If fade in
    if @fade_in
      if $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
        max_opacity = 192
      else
        max_opacity = 255
      end
      @message_box.opacity += 24
      if @input_number_window != nil
        @input_number_window.contents_opacity += 24
      end
      if @message_box.opacity == max_opacity
        @fade_in = false
      end
      return
    end
   
    # If fade out
    if @fade_out
      @message_box.opacity -= 48
      @message.opacity -= 48
      if @cursor != nil
        @cursor.opacity -= 48
      end
      if @input_number_window != nil
        @input_number_window.contents_opacity -= 24
      end
      if @gold_window != nil && $game_temp.consecutive_gold_window == false
        @gold_window.fade_out
      end
      if @message_box.opacity == 0 && @message.opacity == 0
        @fade_out = false
        terminate_message if @sub == false
      end
      return
    end
   
    # If inputting number
    if @input_number_window != nil
      @input_number_window.update
      # Confirm
      if Input.trigger?(Input::C)
        $game_system.se_play($data_system.decision_se)
        $game_variables[$game_temp.num_input_variable_id] =
          @input_number_window.number
        $game_map.need_refresh = true
        # Dispose of number input window
        @input_number_window.dispose
        @input_number_window = nil
       
        if @sub_windows != nil
          temp = subs_finished?
          if temp == true
            @fade_out = true
            erase_subs
          end
        end
      end
      return
    end
    # If message is being displayed
    if @contents_showing && @finished == true
      # If choice isn't being displayed, show pause sign
      if $game_temp.choice_max == 0
        @active = true
      else
        update_cursor
      end
      # Cancel
      if Input.trigger?(Input::B)
        if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
          $game_system.se_play($data_system.cancel_se)
          $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
          terminate_message
        end
      end
      # Confirm
      if Input.trigger?(Input::C)
        if $game_temp.choice_max > 0
          $game_system.se_play($data_system.decision_se)
          $game_temp.choice_proc.call(@index)
        end
        if @sub_windows != nil
          temp = subs_finished?
          if temp == true
            @fade_out = true
            erase_subs
          end
        end
      end
      return
    end
    # If display wait message or choice exists when not fading out
    if $game_temp.message_text != nil && @finished == nil
      @contents_showing = true
      $game_temp.message_window_showing = true
      @finished = false
      re_initialize
      Graphics.frame_reset
      if @input_number_window != nil
        @input_number_window.contents_opacity = 0
      end
      @fade_in = true
      return
    elsif @finished == false
      refresh
      return
    end
  end

  def interpreter
    $scene.is_a?(Scene_Map) ?
    $game_system.map_interpreter :
    $game_system.battle_interpreter
  end

  def sprite_event(id)
    sprites = $scene.spriteset.character_sprites
    event = sprites.select do |s|
      s.character == interpreter.get_character(id)
    end
    return event.first
  end
  #--------------------------------------------------------------------------
  # Create Message Bubble
  #--------------------------------------------------------------------------
  # Remember! The bubble will currently display based on the src_rect of
  # the $character_sprite bitmap...need to work on this...

  def create_bubble # Text can be multiple lines
    sprites = $scene.spriteset.character_sprites
    @event_x = sprite_event(@event).x
    @event_y = sprite_event(@event).y
    # Draw bubble bitmap to blt from
    bubble = Sprite.new
    if @position.include?('Flipped_Down')
      @bubble_correction_y = 7
    else
      @bubble_correction_y = 0
    end
    # Set basic x and y values for bubble drawing
    # If a face graphic will be drawn
    if @face != nil
      # If face graphic drawn outside bubble
      if $game_system.face_graphic_type == FACE_GRAPHIC_FULL
        base_y = (@face_extension_y + @text_rect.height) - (@text_rect.height + 20)
        # If bubble is flipped horizontally
        if @position.include?('Mirror')
          base_x = 0
        else
          base_x = @face_extension_x
        end
        # If bubble is not flipped vertically
        if not @position.include?('Flipped_Down')
          base_y -= 6
        end
        base_height = @text_rect.height
        height_extension = @face_extension_y
        if $game_system.message_text_mode == TEXT_MODE_BUBBLE
          width_extension = @face_extension_x + 25
        elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
          width_extension = @face_extension_x + 20
        elsif $game_system.message_text_mode == TEXT_MODE_INVISIBLE
          width_extension = @face_extension_x + 20
        end
      # If face graphic drawn inside bubble
      else
        base_x = 0
        base_y = @bubble_correction_y
        base_height = @face_extension_y + @text_rect.height
        if $game_system.message_text_mode == TEXT_MODE_BUBBLE
          width_extension = 25
          height_extension = 20 + 6
        elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
          width_extension = 20
          height_extension = 20
        elsif $game_system.message_text_mode == TEXT_MODE_INVISIBLE
          width_extension = 20
          height_extension = 20
        end
      end
    else
      base_x = 0
      base_y = @bubble_correction_y
      base_height = @text_rect.height
      if $game_system.message_text_mode == TEXT_MODE_BUBBLE
        height_extension = 20 + 7
        width_extension = 25
      elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
        height_extension = 20
        width_extension = 20
      elsif $game_system.message_text_mode == TEXT_MODE_INVISIBLE
        height_extension = 20
        width_extension = 20
      end
    end
    base_width = @text_rect.width
   
    # Set text drawing starting coordinates
    @text_y = base_y
   
    if $game_system.message_text_mode == TEXT_MODE_BUBBLE
      bubble.bitmap = Bitmap.new("Graphics/Pictures/Message_Bubble")
    elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
      bubble.bitmap = Bitmap.new("Graphics/Windowskins/"+$data_system.windowskin_name)
    elsif $game_system.message_text_mode == TEXT_MODE_INVISIBLE
      bubble.bitmap = Bitmap.new(32,32)
    end
   
    # Make the bubble bitmap the appropriate size
    @message_box = Sprite.new
       
    true_width = base_width + width_extension
    true_height = base_height + height_extension
    @message_box.bitmap = Bitmap.new(true_width,true_height)
    @message_box.ox = @message_box.bitmap.width/2
    @message_box.oy = @message_box.bitmap.height/2
    @message_box.x = sprite_event(@event).x\
      + @message_box.bitmap.width/2\
      + sprite_event(@event).src_rect.width/2 - 15
    if $game_system.face_graphic_type == FACE_GRAPHIC_FULL
      @message_box.x -= @face_extension_x
    end
    @message_box.y = sprite_event(@event).y\
      - ((sprite_event(@event).src_rect.height/3)*2)\
      - @message_box.oy
    if $game_system.face_graphic_type == FACE_GRAPHIC_FULL \
      && @position.include?('Flipped_Down')
      @message_box.y -= @face_extension_y
    end
    if @sub == false
      @message_box.z += 1
    end
   
    # Set rectangles for graphic block transfers
    if $game_system.message_text_mode == TEXT_MODE_BUBBLE
      upper_left = BUBBLE_UPPER_LEFT
      lower_left = BUBBLE_LOWER_LEFT
      upper_right = BUBBLE_UPPER_RIGHT
      lower_right = BUBBLE_LOWER_RIGHT
     
    elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
      background = Rect.new(base_x+1,base_y+1,base_width+20-2,base_height+20-2)
      source_rect = Rect.new(0,0,128,128)
      @message_box.bitmap.stretch_blt(background,bubble.bitmap,source_rect)
      upper_left = SKIN_UPPER_LEFT
      lower_left = SKIN_LOWER_LEFT
      upper_right = SKIN_UPPER_RIGHT
      lower_right = SKIN_LOWER_RIGHT
    end
    unless $game_system.message_text_mode == TEXT_MODE_INVISIBLE
      # Blt the upper left quadrant of the bubble
      rect = Rect.new(0,0,13,10)   
      @message_box.bitmap.blt(base_x,base_y,bubble.bitmap,upper_left)
     
      # Blt the lower left quadrant of the bubble
      rect.set(0,10,13,9)
      y = base_y + base_height + lower_left.height
      @message_box.bitmap.blt(base_x,y,bubble.bitmap,lower_left)
     
      # Blt the upper right quadrant of the bubble
      rect.set(13,0,12,10)
      x = base_x + base_width + upper_right.width
      @message_box.bitmap.blt(x,base_y,bubble.bitmap,upper_right)
     
      # Blt the lower right quadrant of the bubble
      rect.set(13,10,12,9)
      x = base_x + base_width + lower_right.width
      y = base_y + base_height + upper_right.height
      @message_box.bitmap.blt(x,y,bubble.bitmap,lower_right)
    end
    if $game_system.message_text_mode == TEXT_MODE_BUBBLE
      # Fill in the left side gap
      rect.set(0,8,13,1)   
      x = base_x
      y = base_y + upper_left.height
      rect2 = Rect.new(x,y,13,base_height)
      @message_box.bitmap.stretch_blt(rect2,bubble.bitmap,rect)
       
      # Fill in the right side gap
      rect.set(13,8,12,1)
      x = base_x + base_width + upper_right.width
      y = base_y + upper_right.height
      rect2 = Rect.new(x,y,13,base_height)
      @message_box.bitmap.stretch_blt(rect2,bubble.bitmap,rect)
     
      # Fill in the middle gap   
      x = base_x + upper_left.width - 1
      y = base_y
      width = base_width
      height = base_height + upper_left.height + lower_left.height
      rect.set(x,y,1,height)
      rect2.set(x,y,base_width,height)
      @message_box.bitmap.stretch_blt(rect2,@message_box.bitmap,rect)
   
      # Place character pointer either below or above bubble
      if @position.include?('Flipped_Down')
        if @thought == false
          rect.set(15,19,10,8)
        else
          rect.set(25,8,10,8)
        end
        x = base_x + 9
        y = base_y - @bubble_correction_y
        @message_box.bitmap.blt(x,y,bubble.bitmap,rect)
        @message_box.y = sprite_event(@event).y\
          - ((sprite_event(@event).src_rect.height/3)*2)\
          + @message_box.oy - @face_extension_y#- (offset_y-@text_rect.height-20)
      else
        if @thought == false
          rect.set(0,19,10,8)
        else
          rect.set(25,0,10,8)
        end
        x = base_x + 9
        y = base_y + base_height + 17
        @message_box.bitmap.blt(x,y,bubble.bitmap,rect)
      end
      if @position.include?('Mirror')
        @message_box.mirror = true
        @message_box.x = sprite_event(@event).x\
          - sprite_event(@event).src_rect.width/2\
          - @message_box.bitmap.width/2 + 15 + base_x #+offset_x
      end
    # Fill in rim of a windowskin box
    elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
     
      # Top rim
      dest_rect = Rect.new(base_x+10,base_y,base_width,10)
      source_rect = Rect.new(148,0,24,10)
      @message_box.bitmap.stretch_blt(dest_rect,bubble.bitmap,source_rect)
     
      # Bottom rim
      dest_rect = Rect.new(base_x+10,base_y+base_height+20-10,base_width,10)
      source_rect = Rect.new(148,54,24,10)
      @message_box.bitmap.stretch_blt(dest_rect,bubble.bitmap,source_rect)
     
      # Left rim
      dest_rect = Rect.new(base_x,base_y+10,10,base_height)
      source_rect = Rect.new(128,10,10,44)
      @message_box.bitmap.stretch_blt(dest_rect,bubble.bitmap,source_rect)
     
      # Right rim
      dest_rect = Rect.new(base_x+base_width+20-10,base_y+10,10,base_height)
      source_rect = Rect.new(182,10,10,44)
      @message_box.bitmap.stretch_blt(dest_rect,bubble.bitmap,source_rect)
     
    end
    # Prepare bubble for up/down animation
    @up = true
    @message_box.opacity = 0
    @fade_in = true
    # Dispose of the blted bubble
    bubble.bitmap.dispose
    bubble = nil
    @contents_showing = true
    @active = true
   
    if @bubble_color.class == Color
      @message_box.color = @bubble_color
    end

  end
  #--------------------------------------------------------------------------
  # * Determine Bubble Position
  #--------------------------------------------------------------------------
  def determine_position(no_text=false)
   
    sprites = $scene.spriteset.character_sprites
    @position = ''
    # Check upper screen boundary
    temp = @text_rect.height + 25 + sprite_event(@event).src_rect.height
    if sprite_event(@event).y - temp < 0
      @position += 'Flipped_Down'
    end
    temp = @text_rect.width + 45
    if sprite_event(@event).x\
      + sprite_event(@event).src_rect.width/2 + temp > 640
      @position += 'Mirror'
    end
    if no_text == false
      if @text.slice(/\007\[([0-9]+)\]/)
        #c = @text.slice(/[0-9]+/).to_i
        @text.slice!(/\007\[([0-9]+)\]/)
        c = $1.to_i
        @position = ''
        if c == 0
          @position = ''
        elsif c == 1
          @position = 'Flipped_Down'
        elsif c == 2
          @position = 'Mirror'
        elsif c == 3
          @position = 'Flipped_Down Mirror'
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Bubble Graphic Update
  #--------------------------------------------------------------------------
  def update_bubble
   
    # Create an easier to use access point to the screen sprites
    sprites = $scene.spriteset.character_sprites
   
    # Bounce bubble
    if $game_system.message_text_mode == TEXT_MODE_BUBBLE \
        && $game_system.message_bubble_bounce == BUBBLE_BOUNCE_ON
     
      @count += 1
     
      if @count % 10 == 0 && @up == true
        @message_box.y -= 1
        if @input_number_window != nil
          @input_number_window.y -= 1
        end
        if @cursor != nil
          @cursor.y -= 1
        end
        if @count == 20
          @count = 0
          @up = false
        end
      elsif @count % 10 == 0 && @up == false
        @message_box.y += 1
        if @input_number_window != nil
          @input_number_window.y += 1
        end
        if @cursor != nil
          @cursor.y += 1
        end
        if @count == 20
          @count = 0
          @up = true
        end
      end
    end
       
    x = @event_x
    y = @event_y
   
    @event_x = sprite_event(@event).x
    @event_y = sprite_event(@event).y
   
    if @event_x != x || @event_y != y
           
      if @event_x != x
        @message_box.x = @message_box.x + (@event_x - x)
        if @input_number_window != nil
          @input_number_window.x = @input_number_window.x + (@event_x-x)
        end
        if @cursor != nil
          @cursor.x = @cursor.x + (@event_x - x)
        end
      end
     
      if @event_y - @face_extension_y != y
        @message_box.y = @message_box.y + (@event_y - y)
        if @input_number_window != nil
          @input_number_window.y = @input_number_window.y + (@event_y-y)
        end
        if @cursor != nil
          @cursor.y = @cursor.y + (@event_y - y)
        end
      end
         
      change = false
      # Check upper screen boundary
      temp = @message_box.y - @message_box.bitmap.height/2
      if temp < 0 && (@position.include?('Flipped_Down') == false)
        change = true
      end
      # Check lower screen boundary
      temp = @message_box.y + @message_box.bitmap.height/2
      if temp > 480
        change = true
      end
      # Check right screen boundary
      temp = @message_box.x + @message_box.bitmap.width/2
      if temp > 640
        change = true
      end
      # Check left screen boundary
      temp = @message_box.x - @message_box.bitmap.width/2
      if temp < 0
        change = true
      end
     
      if change == true
        @message_box.bitmap.clear
        determine_position(true)
        create_bubble
        if @cursor != nil
          reset_cursor
        end
        if @position.include?('Flipped_Down')
          get_text
        end
        @message_box.z -= 1
      end
       

    end
   
    @message.y = @message_box.y
    @message.x = @message_box.x     

  end

  #--------------------------------------------------------------------------
  # * Get Message Text
  #--------------------------------------------------------------------------

  def get_text
   
    index = $game_system.map_interpreter.index - 1
    until $game_system.map_interpreter.list[index].code == 101
      index -= 1
    end
    old_text = @text.clone
    @text = ""
    @lines.times do
      if $game_system.map_interpreter.list[index].code == 102 \
        || $game_system.map_interpreter.list[index].code == 402
        for i in 0...$game_system.map_interpreter.list[index].parameters.size
          if $game_system.map_interpreter.list[index].parameters[0][i].class == String
            @text = @text + $game_system.map_interpreter.list[index].parameters[0][i].clone + "\n"
          end
        end
      else       
        @text = @text + $game_system.map_interpreter.list[index].parameters[0].clone + "\n"
      end
      index += 1
    end
   
    prep_text
    @message.bitmap.clear
    @x = 0
    @x += 10 if $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
    @y = 0
    begin
      draw_message
    end until @text == old_text
  end

  #--------------------------------------------------------------------------
  # * Prepare Text for processing
  #--------------------------------------------------------------------------

  def prep_text
    # Determine what event the message will be over
    if @text.slice!(/\\E?\[(.(\d+)|(\d+))\]/i) == nil
      @event = 0 # Default to current event
    else
      @event = $1.to_i
    end
    # Control text processing
    begin
      @last_text = @text.clone
      @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
    end until @text == @last_text
    @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
      $game_actors[$1.to_i] != nil ? "#{$game_actors[$1.to_i].name}:"+"\n" : ""
    end
    # Change "\\\\" to "\000" for convenience
    @text.gsub!(/\\\\/) { "\000" }
    # Change "\\C" to "\001" and "\\G" to "\002"
    #   and "\\B" to "\003" and "\\S" to "\004"
    #   and "\\W" to "\005" and "\\p" to "\006"
    #   and "\\F" to "\007" and "\\q" to "\011"
    #   and "\\I" to "\014  and "\\z" to "\015"
    #   and "\\T" to "\017  and "\\m" to "\018"

    while @text.slice(/\\[Cc]\[([0-9]+)\]/) != nil
      @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
    end
    @text.gsub!(/\\[Gg]/) { "\002" }
    @text.gsub!(/\\[Bb]/) { "\003" }
    @text.gsub!(/\\[Ss]/) { "\004" }
    while @text.slice(/\\[Ww]\[([0-9]+)\]/) != nil
      @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\005[#{$1}]" }
    end       
    while @text.slice(/\\[Pp]/) != nil
      @text.gsub!(/\\[Pp]/) { "\006" }
    end
    while @text.slice(/\\[Ii]/) != nil
      @text.gsub!(/\\[Ii]\[([0-9A-Za-z_\-]+)\]/) { "\014[#{$1}]" }
    end
   # while @text.slice(/\\[Ii]/) != nil
   #   @text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\014[#{$1}]" }
   # end
    while @text.slice(/\\[Zz]/) != nil
      # Check for face directory existence
      if File.directory? Dir::getwd + "/Graphics/Faces/"
        @text.slice(/\\[Zz]\[([0-9]+)\]/)
        # Check for file existence
        if Faces[$1.to_i] != nil
          @text.gsub!(/\\[Zz]\[([0-9]+)\]/) { "\015[#{$1}]" }
        else
          @text.gsub!(/\\[Zz]\[([0-9]+)\]/) { "" }
        end
      else
        @text.gsub!(/\\[Zz]\[([0-9]+)\]/) { "" }
      end
    end
    while @text.slice(/\\[Hh]/) != nil
      @text.gsub!(/\\[Hh]\[([0-9]+)\]/) { "\016[#{$1}]" }
    end
    @text.gsub!(/\\[Ff]/) { "\007" }
    @text.gsub!(/\\[Qq]/) { "\011" }
    @text.gsub!(/\\[Tt]/) { "\017" }
    while @text.slice(/\\[Mm]\[([0-9]+)]/)
      @text.gsub!(/\\[Mm]\[([0-9]+)]/) { "\018[#{$1}]" }
    end
    @text.slice!(/\\[Nn][Cc]/)
  end
  #--------------------------------------------------------------------------
  # * Create cursor graphic
  #--------------------------------------------------------------------------
  def create_cursor
   
    if $game_system.message_text_mode == TEXT_MODE_BUBBLE or
      $game_system.message_text_mode == TEXT_MODE_INVISIBLE
      @cursor = Sprite.new
      @cursor.bitmap = Bitmap.new("Graphics/Pictures/Pointer2")
      @cursor.ox = @cursor.bitmap.width
      if $separate_choices == false
        indent = @message.bitmap.text_size("    ").width
      else
        indent = @message.bitmap.text_size("    ").width
      end
     
    elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
      template = Sprite.new
      template.opacity = 0
      template.bitmap = Bitmap.new("Graphics/Windowskins/"+$data_system.windowskin_name)
      source_rect = Rect.new(128,64,32,32)
      # Set width of the cursor rectangle
      width = @line_width[@lines-$game_temp.choice_max+@index]
      # Correct for added spaces in choices following main text
      width -= @message.bitmap.text_size('     ').width if @indent == true
      dest_rect = Rect.new(0,0,width,@text_height)
      if @cursor == nil
        @cursor = Sprite.new
      else
        @cursor.bitmap.clear
        @cursor.bitmap.dispose
      end
      @cursor.opacity = 255
      @cursor.bitmap = Bitmap.new(width,@text_height)
      # Upper left
      source_rect = Rect.new(128,64,3,3)
      @cursor.bitmap.blt(0,0,template.bitmap,source_rect)
      # Upper right
      source_rect = Rect.new(157,64,3,3)
      @cursor.bitmap.blt(width-3,0,template.bitmap,source_rect)
      # Lower left
      source_rect = Rect.new(128,93,3,3)
      @cursor.bitmap.blt(0,@text_height-3,template.bitmap,source_rect)
      # Lower right
      source_rect = Rect.new(157,93,3,3)
      @cursor.bitmap.blt(width-3,@text_height-3,template.bitmap,source_rect)
      # Top fill in
      source_rect = Rect.new(131,64,26,3)
      dest_rect = Rect.new(3,0,width-6,3)
      @cursor.bitmap.stretch_blt(dest_rect,template.bitmap,source_rect)
      # Bottom fill in
      source_rect = Rect.new(131,93,26,3)
      dest_rect = Rect.new(3,@text_height-3,width-6,3)
      @cursor.bitmap.stretch_blt(dest_rect,template.bitmap,source_rect)
      # Left fill in
      source_rect = Rect.new(128,67,3,@text_height-6)
      dest_rect = Rect.new(0,3,3,@text_height-6)
      @cursor.bitmap.stretch_blt(dest_rect,template.bitmap,source_rect)
      # Right fill in
      source_rect = Rect.new(157,67,3,@text_height-6)
      dest_rect = Rect.new(width-3,3,3,@text_height-6)
      @cursor.bitmap.stretch_blt(dest_rect,template.bitmap,source_rect)
      # Center fill in
      source_rect = Rect.new(131,67,26,26)
      dest_rect = Rect.new(3,3,width-6,@text_height-6)
      @cursor.bitmap.stretch_blt(dest_rect,template.bitmap,source_rect)
     
      @cursor.ox = 0
      template.bitmap.clear
      template = nil
      indent = @message.bitmap.text_size("  ").width
    end
    return if @cursor.nil?
      @cursor.oy = @cursor.bitmap.height/2
     
      if @indent == true
        @cursor.x = @message.x - @message.ox + 14 + @face_extension_x + indent
      else
        @cursor.x = @message.x - @message.ox + @face_extension_x + indent
      end

      y_correction = 0
      @line_height_correction.each { |number|
          y_correction += number
      }
     
      @cursor.y = @message.y - @message.oy + @bubble_correction_y \
        + 10 + @text_height/2 + ((@lines-$game_temp.choice_max+@index)*@text_height)\
        + y_correction
      @cursor.z += 5
      # More accurately place windowskin rectangle
      if $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
        @cursor.y -= 1
      end
      # Correct for bad sizing of bitmap draw_text method
      if $game_system.message_text_size == TEXT_SIZE_LARGE
        @cursor.y -= 2
      elsif
        $game_system.message_text_size == TEXT_SIZE_JUMBO
        @cursor.y -= 6
      end
   
  end 
  #--------------------------------------------------------------------------
  # * Reset cursor graphic
  #--------------------------------------------------------------------------

  def reset_cursor
   
    @cursor.x = @message_box.x - @message_box.ox + 16
    @cursor.y = @message_box.y - @message_box.oy\
      + ((@lines-$game_temp.choice_max + 1)*@text_height)\
      + @bubble_correction_y
  end

  #--------------------------------------------------------------------------
  # * Update cursor graphic
  #--------------------------------------------------------------------------
  def update_cursor
    if $game_system.message_text_mode == TEXT_MODE_BUBBLE
      modulus = 10
    elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
      modulus = 3
    else
      modulus = 6
    end
    return if @cursor.nil?
    @cursor_count += 1
    if @cursor_count % modulus  == 0 && @cursor_move_right == true
      if $game_system.message_text_mode == TEXT_MODE_BUBBLE
        @cursor.x += 1
      elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
        @cursor.opacity -= 10
      end
      if @cursor_count == modulus * 5
        @cursor_count = 0
        @cursor_move_right = false
      end
     
    elsif @cursor_count % modulus == 0 && @cursor_move_right == false
      if $game_system.message_text_mode == TEXT_MODE_BUBBLE
        @cursor.x -= 1
      elsif $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
        @cursor.opacity += 10
      end
     if @cursor_count == modulus * 5
        @cursor_count = 0
        @cursor_move_right = true
      end
    end
   
    if Input.trigger?(Input::UP)
      if @index != 0
        @cursor.y -= @text_height
        @index -= 1
      else
        @cursor.y += @text_height * ($game_temp.choice_max-1)
        @index = $game_temp.choice_max-1
      end
      if $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
        create_cursor
      end
    elsif Input.trigger?(Input::DOWN)
      if @index != $game_temp.choice_max-1
        @cursor.y += @text_height
        @index += 1
      else
        @cursor.y -= @text_height * ($game_temp.choice_max-1)
        @index = 0
      end
      if $game_system.message_text_mode == TEXT_MODE_WINDOWSKIN
        create_cursor
      end
    end
  end 

end

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Shalaren

August 19, 2013, 02:57:13 am #14 Last Edit: August 19, 2013, 03:22:38 am by Shalaren
 Another bug,
it crashes when you show text through a parallel process event.
Error with this line
temp = @text_rect.height + 25 + sprite_event(@event).src_rect.height

KK20

August 19, 2013, 07:40:34 pm #15 Last Edit: August 19, 2013, 08:03:38 pm by KK20
The problem is due to the inability to figure out which event to draw the message window over. You can specify which event to draw over with \e[id]. But doing that will just cause another error: it's trying to find the next event code in an event that doesn't exist in $game_system.map_interpreter. In other words, I don't think this script was built with parallel processing messages to exist. This is also over my head at the moment since it does not look like an easy fix.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Shalaren

September 13, 2013, 04:13:09 pm #16 Last Edit: September 13, 2013, 06:23:48 pm by Shalaren
So I've been running into a lot of trouble not being able to use the script in parralel events.
I'm using Even range condition By F0, and I wanna make it so when the character is away from an event it will tell it to come back,
...
and if I would make it an autorun event the game will just get stuck,
is there any way at all to make this work somehow? I don't want the text showing and the character being able to move anyway, Just that it will be able to show the text as if it was an autorun or a normal event.

I really like this script because it looks great.
Spoiler: ShowHide

The bubbles don't have that much of an unnecessary space in them like
Spoiler: ShowHide


so I'm just wondering if there is any way around this,
if there isn't then as much as I'd hate to, I will just use another CMS  :>.<:

Edit: EVEN if it would mean to disable the script when its on parrallel event, where it would show the normal windowskin styled message system.

KK20

I can't remember, but does the script have difficulty displaying messages in an auto-run event (since we have already established the fact that parallel process doesn't work)? If it works fine, you can turn a switch on when the player is too far away that will change an on-map event to another page. On this new page, make it an auto-run, display message, move the player, then turn the switch off.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!