Jump to content
Paddy

Zelda Hearts System

Recommended Posts

I can't seem to get it working... :/ I start the game (with the switch off) and nothing is displayed, then turn the switch on, and nothing appears.

Share this post


Link to post
Share on other sites

Indeed, that's probably because the bitmaps are loaded only in the constructor, my bad. Try to move the "if @switch" on line 68 right above the "draw_hearts" line. The images will then be loaded into the cache so that when you activate the switch, the refresh method should actually do things.

Share this post


Link to post
Share on other sites

Erm...Still don't think that worked...I could have done it wrong though. You did mean to move line 68 to line 72, right?

Share this post


Link to post
Share on other sites

Try this version:

 

 

# By Pyro17 : http://www.rpgmakervxace.net/topic/14566-zelda-hearts-system/#entry100293
# bitmap file must placed into Graphics/System/Hud
 
module Cache
  #--------------------------------------------------------------------------
  # * Gets Gauge Graphics
  #--------------------------------------------------------------------------
  def self.hud(filename, hue=0)
    load_bitmap("Graphics/System/Hud/", filename, hue)
  end
end
 
class ZeldaHearts < Window_Base
  #--------------------------------------------------------------------------
  # * Changeable Area
  #--------------------------------------------------------------------------
 
  # Enter your switch number here
  def switch
    1
  end
 
  def hud_x
    0
  end
 
  def hud_y
    0
  end
 
  def hud_width
    400
  end
 
  def hud_height
    240
  end
 
  def heart_padding
    3
  end
 
  def heart_row
    10
  end
 
  def hp_per_heart
    4
  end
 
  def heart_pieces
    4
  end
 
  #--------------------------------------------------------------------------
  # * Fixed Area
  #--------------------------------------------------------------------------
 
  # TODO: add input arguments for coordinates (and maybe width/height ?)
  def initialize
    super(hud_x, hud_y, hud_width, hud_height)
    self.windowskin = nil
    @bitmaps = Array.new(heart_pieces + 1)
    for i in 0..heart_pieces
      @bitmaps[i] = Cache.hud("hearts" + i.to_s + ".png")
    end
    draw_hearts
  end
 
 
  def draw_hearts
    @lhearts = @hearts
    @lmaxHearts = @maxHearts
   
    # Gets the number of hearts to draw depending on the HP
    @hearts = calc_hearts(get_hp)
   
    # Gets the max number of hearts depending on the HP max
    @maxHearts = calc_hearts(get_maxhp).to_i
   
    fullHearts = @hearts.to_i
    partHearts = @hearts - fullHearts
    i = 0
   
    if fullHearts
      for i in 0..@maxHearts-1 do
        # Draws full hearts
        if i < fullHearts
          get_heart_image(i, heart_pieces)
        # Draws the pieces of he last filled heart
        elsif i == fullHearts
          get_heart_image(i, (partHearts*heart_pieces).round(0))
        # Draws empty hearts
        else
          get_heart_image(i,0)
        end
      end
    end
  end
 
  # Fills hearts piece by piece (yeah, this sounds weird)
  def get_heart_image(heartIndex, fileIndex)
    bitmap = @bitmaps[fileIndex]
    posx = heartIndex.modulo(heart_row) * (bitmap.width + heart_padding)
    posy = (heartIndex/heart_row) * (bitmap.height + heart_padding)
   
    contents.blt(posx, posy, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height), 255)
  end
 
  def get_hp
    $game_party.members[0].hp
  end
 
  def get_maxhp
    $game_party.members[0].mhp
  end
 
  # Gets the number of filled hearts based on the HP, rounded to 2 decimals.
  # e.g. if max HP is 97 and max hearts is 5, if current HP is 75 then we'll have 3.87 hearts filled (97 * 5 / 75 = 3.8659...)
  def calc_hearts(hp)
    Float hearts = hp.to_f / hp_per_heart
    hearts.round(2)
  end
 
  def refresh
    contents.clear
    draw_hearts
  end
 
  # Overrides Windows_Base's dispose. Basically destroys used resources.
  def dispose
    super
    for b in @bitmaps
      if !b.nil?
        b.dispose
      end
    end
  end
end
 
class Scene_Map < Scene_Base
  alias start_window start
  alias term_window terminate
  alias update_window update
 
  attr_reader :hearthud
 
  def start
    start_window
    @hearthud = ZeldaHearts.new
    update
  end
 
  def terminate
    @hearthud.dispose
    term_window
  end
 
  def update
    update_window
    if $game_switches[@hearthud.switch]
      @hearthud.show unless @hearthud.visible
      @hearthud.update
    else
      @hearthud.hide if @hearthud.visible
    end
  end
end
 
 
# TODO: Scene_Battle override

 

 

Edited by Gambit.

Share this post


Link to post
Share on other sites

Everything works great! Thank you guys.

 

However, if you can find the time, I would very much appreciate if this could be somehow added to Yanfly's Ace Save Engine, to display a row of hearts to the right of the character (I only have one party member). If this is too complicated or time-consuming, don't worry about it. It's just an effect. ;)

Share this post


Link to post
Share on other sites

Add this script below the YEA Save Engine and the Zelda Hearts scripts.

 

 

if $imported["YEA-SaveEngine"]
#==============================================================================
# ?! Window_FileStatus
#==============================================================================

class Window_FileStatus < Window_Base
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    reset_font_settings
    @hearthud.dispose if @hearthud
    @header = DataManager.load_header(@file_window.index)
    p @header
    if @header.nil?
      draw_empty
    else
      draw_save_contents
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_save_characters
  #--------------------------------------------------------------------------
  def draw_save_characters(dx, dy)
    return if @header[:party].nil?
    reset_font_settings
    make_font_smaller
    dw = (contents.width - dx) / @header[:party].max_battle_members
    dx += dw/2
    for member in @header[:party].battle_members
      next if member.nil?
      member = @header[:actors][member.id]
      change_color(normal_color)
      draw_actor_graphic(member, dx, dy)
      text = member.name
      draw_text(dx-dw/2, dy, dw, line_height, text, 1)
      if member.id == 1
        @hearthud = ZeldaHearts.new(member.hp, member.mhp)
        @hearthud.x = self.x + standard_padding + dx-dw/2
        @hearthud.y = self.y + standard_padding + dy + line_height / 2
      end
      text = member.level.group
      draw_text(dx-dw/2, dy-line_height, dw-4, line_height, text, 2)
      cx = text_size(text).width
      change_color(system_color)
      text = Vocab::level_a
      draw_text(dx-dw/2, dy-line_height, dw-cx-4, line_height, text, 2)
      dx += dw
    end
  end
  
  #--------------------------------------------------------------------------
  # dispose
  #--------------------------------------------------------------------------
  def dispose
    @hearthud.dispose if @hearthud
    super
  end
end # Window_FileStatus

class ZeldaHearts < Window_Base
  
  def initialize(save_hp = false, save_mhp = false)
    super(hud_x, hud_y, hud_width, hud_height)
    self.windowskin = nil
    @bitmaps = Array.new(heart_pieces + 1)
    for i in 0..heart_pieces
      @bitmaps[i] = Cache.hud("hearts" + i.to_s + ".png")
    end
    @save_hp, @save_mhp = save_hp, save_mhp
    draw_hearts
  end
  
  def get_hp
    !@save_mhp ? $game_party.members[0].hp : @save_hp
  end
 
  def get_maxhp
    !@save_mhp ? $game_party.members[0].mhp : @save_mhp
  end
end
end

 

 

Edited by Gambit.

Share this post


Link to post
Share on other sites

Wow, you're a bit awesome. :) 

I did notice that the hearts fade in with the scene, but don't fade out with the scene. Is that something you could tweak?

Share this post


Link to post
Share on other sites

That's what I get for quickly testing it without leave the scene :rolleyes:. I've updated the script add-on in my previous post.

Edited by Gambit.

Share this post


Link to post
Share on other sites

Boom! Saving the thread from the 30-day limit. 

 

So do I put the heart script under materials under "bigger" scripts (i.e. modules and more global-type effects) and that one hearts.png image in the folder and it's good? 

Share this post


Link to post
Share on other sites

How do I change the max amount of hearts? Like if I have 400 hp and i just want 4 hearts or something....

 

 

Sorry if my english words bad, Im still learning.

Share this post


Link to post
Share on other sites

Great, thanks very much,

 

Is there a way to make a script so that the hearts are updated every second or few seconds, like, if my character is hurt not in battle the hearts stay the same

as if I am full health.

Can I change this so that if im damaged the hearts show my CURRENT health?

Share this post


Link to post
Share on other sites

It does. The hearts will empty out as you take damage. I am using a modified version of this script and every time I get hurt the hearts empty out.

Share this post


Link to post
Share on other sites

With the scripts the hearts will empty out when each 100 (or whatever you made it) is dealt in damage. If something deals damage below that amount then the hearts will not go down. 

Share this post


Link to post
Share on other sites

I made it 12 hp every heart but enemies kill me and hearts don`t seem to change (it takes more than one hit to kill me)

Edited by rabid.rivas

Share this post


Link to post
Share on other sites

PM a demo and I will be happy to look at it because I am also using Falcao's Pearl and this script. My hearts do go down.

Share this post


Link to post
Share on other sites

It doesnt work! :(  Enemies hit me but hears dont go down. Would any one please change Pyro17 script so it updates every time i get hurt out of battle?Please.

I am using this script with Falcao Pearl ABS Liquid V3 that can be found here .

Edited by rabid.rivas

Share this post


Link to post
Share on other sites

I am working on it. I have had a lot of issues in my life so time is hard right now. Give me a little time please.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted