Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Character Description (Easy scripting, i think...)

It's me again...
actually, i'm looking for sth. like that:

I thought of a script, which opens a window, where you can display an image (form a character!), and then at the bottom can write a text about him... like in this drawing:


http://i32.tinypic.com/muvleu.jpg[/img]

(That way, that if have the command to open, so maybe for editing in a menu or when i speak to someone.)

THX in advance, i hope its easy for advanced scripters! ;)
 
Try this out...  instructions inside

Code:
#==============================================================================
# ** Window_CharInfo
#------------------------------------------------------------------------------
#  This window displays information about a character.
#
#  Modify the @desc hash to include your names & descriptions
#  don't forget the commas. (every line except the last)
#
#  use $scene = Scene_CharInfo.new("name")  to call from map event
#
#  For the sprite area, it looks in Graphics/Characters for <name>.png
#   if it doesn't find it, it leaves this area blank
#
#  For the name area, it looks in Graphics/Pictures for <name>.png
#   if it doesn't find it, it prints the name in larger text.
#
#  Credits:  Brewmeister, Trickster (draw_wrap_text)
#==============================================================================

class Window_CharInfo < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     actor : actor
  #--------------------------------------------------------------------------
  def initialize(character)
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    @character = character
    #------------------------------------------------
    # create a hash with the descriptions
    # enter a lower case 'p' by itself for a line break
    #------------------------------------------------
    @desc = {
    "name 1" => "Description for name 1.", 
    "name 2" => "one. p Two", 
    "name 3" => "Thank you, Trickster."
    }
    #------------------------------------------------
    # create a hash with the descriptions
    #------------------------------------------------
    @desc.default = "I couldn't find a description for that name"
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    # Draw the seperators
    black = Color.new(0,0,127,255)
    self.contents.fill_rect(95, 0, 1, 96, black)
    self.contents.fill_rect(96, 0, 1, 96, normal_color)
    self.contents.fill_rect(0, 95, 608, 1, black)
    self.contents.fill_rect(0, 96, 608, 1, normal_color)
    # Draw the character sprite
    if FileTest.exist?("Graphics/Characters/" + @character + ".png")
      cbm = RPG::Cache.character(@character, 0)
      cw = cbm.width / 4
      ch = cbm.height / 4
      src_rect = Rect.new(0, 0, cw, ch)
      self.contents.blt((88 - cw) / 2, (88 - ch) / 2, cbm, src_rect)
    end
    # Draw the name  (picture or text)
    if FileTest.exist?("Graphics/Pictures/" + @character + ".png")
      nbm = RPG::Cache.picture(@character)
      src_rect = Rect.new(0, 0, nbm.width, nbm.height)
      self.contents.blt(348 - nbm.width / 2, (88 - nbm.height) / 2, nbm, src_rect)
    else
      self.contents.font.size = 44
      self.contents.draw_text(100, 12, 504, 64, @character, 1)
    end
    # Draw the description
    text = @desc[@character]
    self.contents.font.size = 22
    self.contents.draw_wrap_text(4, 100, 600, 28, text)
  end
end

#==============================================================================
# ** Scene_CharInfo
#------------------------------------------------------------------------------
#  This class calls the Character Info Window
#==============================================================================

class Scene_CharInfo
  def initialize(character, callback = 0)
    @character = character
    @callback = callback
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make info window
    @info_window = Window_CharInfo.new(@character)
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
       Graphics.update
      # Update input information
      Input.update
      # Frame Update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of window
    @info_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If B button was pressed
    if Input.trigger?(Input::B) || Input.trigger?(Input::C)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch back to calling scene
      if @callback
        $scene = Scene_Menu.new(4)
      else
        $scene = Scene_Map.new
      end
      return
    end
  end
end

#==============================================================================
# ** Bitmap Class Add-ons from MACL 2.1
# NOTE: If you have the MACL, don't delete this.
# Make sure this is below the MACL
#------------------------------------------------------------------------------
class Bitmap
  #--------------------------------------------------------------------------
  # * Dummy Bitmap  
  #--------------------------------------------------------------------------
  @@dummy = Bitmap.new(32, 32)
  attr_accessor :dummy
  #--------------------------------------------------------------------------
  #   Name      : Text Size
  #   Info      : Gets text size based off dummy bitmap
  #   Author    : SephirothSpawn
  #   Call Info : One Argument, a String
  #--------------------------------------------------------------------------
  def Bitmap.text_size(text)
    return @@dummy.text_size(text)
  end
  #-------------------------------------------------------------------------
  #   Name      : Draw Wrapped Text
  #   Info      : Draws Text with Text Wrap
  #   Author    : Trickster
  #   Call Info : Five Arguments
  #               Integer X and Y, Define Position
  #               Integer Width, defines the width of the text rectangle
  #               Integer Height, defines the height of the text
  #               String Text, Text to be drawn
  #   Modified  : Brew.  Add 'p' for line breaks
  #-------------------------------------------------------------------------
  def draw_wrap_text(x, y, width, height, text)
    # Get Array of Text
    strings = text.split
    # Run Through Array of Strings
    strings.each do |string|
      # Get Word
      word = string + ' '
      # If p, move to next line
      if string == "p"
        x = 0
        y += height
        next
      end
      # Get Word Width
      word_width = text_size(word).width
      # If Can't Fit on Line move to next one
      x, y = 0, y + height if x + word_width > width
      # Draw Text Memory
      self.draw_text(x, y, word_width, height, word)
      # Add To X
      x += word_width
    end
  end
end

Be Well
 

Jason

Awesome Bro

Just a question, would it be possible to make this, so when it's called fromt the Menu, it displays the first party members description, if you press Q or W it goes to the next, in the same mannor as the Equip and Status menu's ?

Thankyou.
 
At the moment, it's 'dumb'

You call it with a 'name' argument, and it displays the description you have entered that
corresponds to that name.

So, if your first party member is 'Aluxes', and you have entered

"Aluxes" => "A twirpy midget with orange hair",

in the hash, it will display.  If you have a character set named "Aluxes.png", it will show the first pose in the character set, and if you have a picture named "Aluxes.png", it will show the picture for the name at the top of the window.

So, in it's current state, you could have a 'description' option on the menu, have it jump to the status window (on the right, like the equip, skill, or status functions), then choose an actor & display the description.

Let me know if you need help adding it to the menu.

Ideally, what I should do with this is make it generic, so you can show descriptions of
any object (actor, item, weapon, enemy, etc..)  Then it would be worth posting in submitted scripts for everyone to use.

Be Well
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top