Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: elmangakac on April 06, 2011, 03:04:41 am

Title: [XP] Clive's Hero Database
Post by: elmangakac on April 06, 2011, 03:04:41 am
Clive's Hero Database
Authors: SephirothSpawn
Version: 1.0
Type: Hero Database
Key Term: Misc System



Introduction

This script shows a full data of the actors of the game, and if the actors dont appear shows like a "unknow" one



Features




Screenshots

(http://i172.photobucket.com/albums/w12/cesarperry/Sinttulo.png)



Demo

Just test it


Script


Spoiler: ShowHide
 

#==============================================================================
# Clive's Hero Database
#==============================================================================
# SephirothSpawn
# Version 1
# 22.02.06
#==============================================================================
# Instructions:
#   ~ Setting Up Hero's Bio
#         Find the line HERO_BIO = {
#         Below That, have a x=>[] for each actor in your database
#         Withing the array, have up to 3 lines of 'text'
#   ~ Calling the Scene
#         Use: $scene = Scene_Hero_DataBase.new
#==============================================================================
#==============================================================================
# ** Window_Clive_HeroStatus
#==============================================================================
class Window_Clive_HeroStatus < Window_Base
  #--------------------------------------------------------------------------
  # * Hero Biography Constant
  #--------------------------------------------------------------------------
  HERO_BIO = {
    1=>["Here's a neat fact:", 'Arshes is the most used sprite in the rmxp community'],
    2=>['I thought Basil was something for cooking?'],
    3=>['I am thor!', 'Fear My Axe!'],
    4=>['Watch out fellas,', 'She will steal your hearts', '[/chessy]'],
    5=>['I still do not understant', 'whats up with the end of here bow...'],
    6=>['Bang Bang!'],
    7=>['Only for healing...'],
    8=>['Woot Woot!', 'Kill those Ghost with Fire', 'The secret to beat Sephs Demos']
    }
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor, index)
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    @actor, @index, @frame = actor, index, 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    # Information Arrays
    main_info = ['Name:', 'Class:', 'Level:', 'Experience:', 'Next Level:']
    stat_info = ['hp', 'sp', 'str', 'dex', 'agi', 'int'].collect! {|x| (eval "$data_system.words.#{x}") + ':'}
    stat_info.push('Evasion:', 'Hit %:')
    equip_info = ['atk', 'pdef', 'mdef'].collect! {|x| (eval "$data_system.words.#{x}") + ':'}
    # Draws Page
    self.contents.font.color = system_color
    self.contents.draw_text(192, 0, 224, 24, "Page : #{@index} / #{$data_actors.size - 1}", 1)
    # Draws Stat Words
    for i in 0...stat_info.size
      self.contents.draw_text(4, 144 + i * 24, 284, 24, stat_info[i])
    end
    # Draws Equipment Words
    for i in 0...equip_info.size
      self.contents.draw_text(324, 144 + i * 24, 284, 24, equip_info[i])
    end
    # Draws Biography Heading
    self.contents.font.color = @actor.nil? ? disabled_color : normal_color
    self.contents.draw_text(20, 336, contents.width, 24, 'Biography:')
    # If Actor isn't nil
    unless @actor.nil?
      # Draws Actor Sprite
      refresh_sprite
      # Draws Actor Battler
      self.contents.scale_blt(Rect.new(400, 0, 192, 144),
        bitmap = RPG::Cache.battler(@actor.battler_name, @actor.battler_hue),
        Rect.new(0, 0, bitmap.width, bitmap.height))     
      # Gets Actor Main Information
      info = ['name', 'class_name', 'level', 'exp', 'next_rest_exp_s'].collect! {|x| eval "@actor.#{x}"}
      # Draws Main Information
      self.contents.font.color = system_color
      for i in 0...info.size
        self.contents.draw_text(192, (i + 1) * 24, 224, 24, "#{main_info[i]} #{info[i]}", 1)
      end
      # Gets Acor Stat Information
      info = ["#{@actor.hp} / #{@actor.maxhp}", "#{@actor.sp} / #{@actor.maxsp}"]
      info << ['str', 'dex', 'agi', 'int', 'eva', 'hit'].collect! {|x| eval "@actor.#{x}"}
      # Draws Actor Stat Information
      self.contents.font.color = normal_color
      for i in 0...info.flatten!.size
        self.contents.draw_text(- 4, 144 + i * 24, 284, 24, info[i].to_s, 2)
      end
      # Gets Actor Base Equip Information
      info = ['atk', 'pdef', 'mdef'].collect! {|x| eval "@actor.#{x}"}
      for i in 0..info.size
        self.contents.draw_text(316, 144 + i * 24, 284, 24, info[i].to_s, 2)
      end
      # Gets Equipment IDs
      equipment = ['weapon_id', 'armor1_id', 'armor2_id', 'armor3_id', 'armor4_id'].collect! {|x| eval "@actor.#{x}"}
      # Gets Equipment
      for i in 0..4
        equipment[i] = i == 0 ? $data_weapons[equipment[i]] : $data_armors[equipment[i]]
      end
      # Draws Equipment
      for i in 0..4
        draw_equipment(equipment[i], 324, 216 + i * 24, 284, 1, i)
      end
      # Gets Bio
      bio = HERO_BIO[@index]
      # Draws bio
      self.contents.font.color = normal_color
      for i in 0...bio.size
        self.contents.draw_text(36, 336 + (i + 1) * 24, contents.width - 72, 24, bio[i], 1)
      end
    # If Actor is nil
    else
      # Draws Main Information
      self.contents.font.color = system_color
      for i in 0..4
        self.contents.draw_text(192, (i + 1) * 24, 224, 24, "#{main_info[i]} ??????", 1)
      end
      # Draws Actor Stat Information
      self.contents.font.color = normal_color
      for i in 0..7
        text = i == 0 ? '???? / ????' : i == 1 ? '??? / ???' : '???'
        self.contents.draw_text(- 4, 144 + i * 24, 284, 24, text, 2)
      end
      # Gets Actor Base Equip Information
      for i in 0..2
        self.contents.draw_text(316, 144 + i * 24, 284, 24, '???', 2)
      end
      # Draws Equipment
      for i in 0..4
        draw_equipment(nil, 324, 216 + i * 24, 284, 1, i, false)
      end
      # Draws Empty Bio
      self.contents.font.color = disabled_color
      self.contents.draw_text(36, 360, contents.width - 72, 24, 'Unknown Bio', 1)
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh Sprite
  #--------------------------------------------------------------------------
  def refresh_sprite
    # Clears Bitmap Area
    self.contents.fill_rect(Rect.new(0, 0, 192, 144), Color.new(0, 0, 0, 0))
    # Draws Actor Sprite
    draw_sprite(0, 0, 192, 144, @actor.character_name, @actor.character_hue, 0, @frame)
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    super
    # Checks to Refresh Sprite
    if Graphics.frame_count % 10 == 0
      @frame == 3 ? @frame = 0 : @frame += 1
      refresh_sprite unless @actor.nil?
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Equipment
  #     item : item
  #     x    : draw spot x-coordinate
  #     y    : draw spot y-coordinate
  #     width : draw text width
  #     align  : text align
  #--------------------------------------------------------------------------
  def draw_equipment(item, x, y, width = 212, align = 0, type = 0, unknown = true)
    if item.nil?
      case type
      when 0  # Weapon
        bitmap = RPG::Cache.icon("001-Weapon01")
      when 1  # Shield
        bitmap = RPG::Cache.icon("009-Shield01")
      when 2  # Helmet
        bitmap = RPG::Cache.icon("010-Head01")
      when 3  # Armor
        bitmap = RPG::Cache.icon("014-Body02")
      when 4  # Accessory
        bitmap = RPG::Cache.icon("016-Accessory01")
      end
      contents.font.color, alpha = disabled_color, disabled_color.alpha
      txt = unknown ? 'Nothing' : 'Unknown'
    else
      bitmap = RPG::Cache.icon(item.icon_name)
      contents.font.color, alpha, txt = normal_color, 255, item.name
    end
    # Draws Icon
    self.contents.blt(x, y, bitmap, Rect.new(0, 0, 24, 24), alpha)
    self.contents.draw_text(x + 28, y, width - 28, 24, txt, align)
  end
  #--------------------------------------------------------------------------
  # * Draw Sprite
  #--------------------------------------------------------------------------
  def draw_sprite(x, y, w, h, name, hue, stance, frame)
    # Gets Bitmap
    bitmap = RPG::Cache.character(name, hue)
    # Bitmap Division
    cw, ch = bitmap.width / 4,  bitmap.height / 4
    # Gets Animation Offsets
    x_off, y_off = cw * frame, ch * stance
    # Draws Bitmap
    self.contents.scale_blt(Rect.new(x, y, w, h), bitmap, Rect.new(x_off, y_off, cw, ch))
  end
end

#==============================================================================
# ** Bitmap
#==============================================================================
class Bitmap
  #--------------------------------------------------------------------------
  # * Scale Blt
  #--------------------------------------------------------------------------
  def scale_blt(dest_rect, src_bitmap, src_rect, opacity = 255)
    w, h = src_rect.width, src_rect.height
    scale = [w / dest_rect.width.to_f, h / dest_rect.height.to_f].max
    ow, oh = (w / scale).to_i, (h / scale).to_i
    ox, oy = (dest_rect.width - ow) / 2, (dest_rect.height - oh) / 2
    stretch_blt(Rect.new(ox + dest_rect.x, oy + dest_rect.y, ow, oh),
      src_bitmap, src_rect )
  end
end

#==============================================================================
# ** Game_Actors
#==============================================================================
class Game_Actors
  #--------------------------------------------------------------------------
  # * Public Instance Variabeles
  #--------------------------------------------------------------------------
  attr_reader :data
end

#==============================================================================
# ** Scene_Hero_DataBase
#==============================================================================
class Scene_Hero_DataBase
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor_index = 1)
    @actor_index = actor_index
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Sets Actor
    @actor = $game_actors.data[@actor_index].nil? ? nil : @actor = $game_actors[@actor_index]
    # Creates Database Profile Window
    @actor_profile_window = Window_Clive_HeroStatus.new(@actor, @actor_index)
    # Draws Blank Sprites if Actor isn't in you actors database
    if @actor.nil?
      # Starts Frame Count
      @frame = 0
      # Creates Actor Character Sprite
      @actor_c_sprite = Sprite.new
        @actor_c_sprite.x, @actor_c_sprite.y = 16, 16
        @actor_c_sprite.z, @actor_c_sprite.opacity = 999, 160
      # Refreshes Sprite
      refresh_character_sprite
      # Creates Actor Battle Sprite
      @actor_b_sprite = Sprite.new
        @actor_b_sprite.x, @actor_b_sprite.y = 416, 16
        @actor_b_sprite.z, @actor_b_sprite.opacity = 999, 160
        @actor_b_sprite.bitmap = Bitmap.new(192, 144)
        actor = $data_actors[@actor_index]
        bitmap = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
        @actor_b_sprite.bitmap.scale_blt(Rect.new(0, 0, 192, 144), bitmap,
          Rect.new(0, 0, bitmap.width, bitmap.height))
        @actor_b_sprite.tone = Tone.new(- 255, - 255, - 255, 160)
    end
    # Execute transition
    Graphics.transition
    # Main loop
    while $scene == self
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of Database Profile Window
    @actor_profile_window.dispose
    # Disposes nil actor sprites
    if @actor.nil?
      @actor_c_sprite.dispose
      @actor_b_sprite.dispose
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update Profile Window
    @actor_profile_window.update
    # If L button is pressed
    if Input.trigger?(Input::L)
      # Play Cursor SE
      $game_system.se_play($data_system.cursor_se)
      # Changes Index
      @actor_index == 1 ? @actor_index = $data_actors.size - 1 : @actor_index -= 1
      # Changes Actor
      $scene = Scene_Hero_DataBase.new(@actor_index)
    end
    # If R button is pressed
    if Input.trigger?(Input::R)
      # Play Cursor SE
      $game_system.se_play($data_system.cursor_se)
      # Changes Index
      @actor_index == $data_actors.size - 1 ? @actor_index = 1 : @actor_index += 1
      # Changes Actor
      $scene = Scene_Hero_DataBase.new(@actor_index)
    end
    # If b button is pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Proceeds to Menu Screen
      $scene = Scene_Menu.new
    end
    # If nil actor
    if @actor.nil?
      # Checks to Refresh Contents
      if Graphics.frame_count % 10 == 0
        @frame == 3 ? @frame = 0 : @frame += 1
        refresh_character_sprite
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh Character Sprite
  #--------------------------------------------------------------------------
  def refresh_character_sprite
    # Sets Blank Bitmap
    @actor_c_sprite.bitmap = Bitmap.new(192, 144)
    # Gets Actor
    actor = $data_actors[@actor_index]
    # Gets Bitmap
    bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
    # Draws Bitmap
    @actor_c_sprite.bitmap.scale_blt(Rect.new(0, 0, 192, 144),
      bitmap,
      Rect.new(bitmap.width / 4 * @frame, 0, bitmap.width / 4, bitmap.height / 4))
    # Adjust Sprite Tone
    @actor_c_sprite.tone = Tone.new(- 255, - 255, - 255, 160)
  end
end



Instructions

-Put Above Main and call with $scene = Scene_Hero_DataBase.new


Compatibility

I dont know issues yet



Credits and Thanks




Author's Notes

Bye Bye
Title: Re: [XP] Clive's Hero Database
Post by: MindOnFire on January 03, 2012, 05:09:57 pm
I apologize for necroposting (and just appearing after being gone for a really long time just to necropost <_<) but does anyone here know of a way to get this to appear as the default status screen by going to status in the menu instead of needing an event+script reference to call it? I have it working and I vastly prefer this screen to the default one.
Title: Re: [XP] Clive's Hero Database
Post by: ForeverZer0 on January 03, 2012, 05:36:00 pm
In the update_status method of Scene_Menu (at the very bottom), change the following line:
$scene = Scene_Status.new(@status_window.index)

...to this:
actor_index = $game_party.actors[@status_window.index].id
$scene = Scene_Hero_DataBase.new(actor_index)


Also, in the bottom of the "update" method of Scene_Hero_DataBase, change the:
"$scene = Scene_Menu.new

...to:
$scene = Scene_Menu.new(3)


I didn't check any of that, but I see no reason why it should not work.
Title: Re: [XP] Clive's Hero Database
Post by: MindOnFire on January 03, 2012, 06:28:03 pm
Wow. I actually tried a strategy really similar to that before posting here, though I was trying to edit the references in Scene_Status rather than Scene_Menu (Don't worry I restored it to default). At least I know I had the right idea. XD Thanks for your help. It works perfectly.

Level up for quick help and for always helping me despite my tendency to disappear lol.