RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

Help with this simple script

Started by DarthVollis, September 24, 2013, 03:39:46 AM

0 Members and 1 Guest are viewing this topic.

DarthVollis

I am test playing a modification to a script I have that creates a help HUD for an ABS. The unmodded scripts works great, but the modded version I created (to add a HUD for MP as well) as soon as I click new game crashes and gives me RGSS3 player has stopped working. I will post my modded script here and see if you can get it working please. It is a simple script.

Here is the unmodded script. Can someone help me get this to include a MP HUD as well done just as the heart system is.
[spoiler]
module Cache
  #--------------------------------------------------------------------------
  # * Get Hud Graphic
  #--------------------------------------------------------------------------
  def self.hud(filename, hue=0)
    load_bitmap("Graphics/System/Hud/", filename, hue)
  end
end

class ZeldaHearts < Window_Base
  #--------------------------------------------------------------------------
  # * Changeable Area
  #--------------------------------------------------------------------------
  def switch
    90
  end
 
  def hud_x
    0
  end
 
  def hud_y
    0
  end
 
  def hud_width
    400
  end
 
  def hud_height
    240
  end
 
  def heart_file
    "hearts"
  end
 
  def heart_width
    24
  end
 
  def heart_padding
    -10
  end
 
  def heart_rowheight
    -10
  end
 
  def heart_row
    10
  end
 
  def hp_per_heart
    4
  end
 
  def heart_pieces
    4
  end
 
  #--------------------------------------------------------------------------
  # * Fixed Area
  #--------------------------------------------------------------------------
  def initialize
    super(hud_x, hud_y, hud_width, hud_height)
    self.windowskin = nil
    @bitmap = Cache.hud(heart_file)
    @switch = $game_switches[switch]
    if @switch
      draw_hearts
    end
  end
 
  def draw_hearts
    @lhearts = @hearts
    @lmaxHearts = @maxHearts
    @hearts = calc_hearts(get_hp)
    @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     
        if i < fullHearts
          get_heart_image(i, heart_pieces)
        elsif i == fullHearts
          get_heart_image(i, (partHearts*heart_pieces).round(0))
        else
          get_heart_image(i,0)
        end
      end
    end
  end
 
  def get_heart_image(heartIndex, fileIndex)   
    rect = Rect.new(fileIndex * heart_width, 0, @bitmap.width/(heart_pieces+1), @bitmap.height)
    contents.blt(heartIndex.modulo(heart_row)*(heart_width+heart_padding), (heartIndex/heart_row)*(@bitmap.height+heart_rowheight), @bitmap, rect, 255)
  end
 
  def get_hp
    $game_party.members[0].hp
  end
 
  def get_maxhp
    $game_party.members[0].mhp
  end
 
  def calc_hearts(hp)
    Float hearts = hp.to_f / hp_per_heart
    hearts.round(2)
  end
 
  def refresh
    self.contents.clear
    contents.clear
    draw_hearts
  end
  def update
    super   
    if @switch
      refresh
    end
  end
 
  def change 
    if @switch != $game_switches[switch]
      if $game_switches[switch]
        update
      else
        contents.clear
        self.contents.clear
      end
      @switch = $game_switches[switch]
    end
    if @lhearts == @hearts && @lmaxHearts == @maxHearts
      return
    else
      update
    end
  end
 
  def dispose
    super
    @bitmap.dispose
  end
end

class Scene_Map < Scene_Base
  alias start_window start
  alias term_window terminate
  alias update_window update
 
  def start
    start_window
    @hearthud = ZeldaHearts.new 
    update
  end

  def terminate
    @hearthud.dispose
    term_window
  end

  def update
    update_window
    @hearthud.change
  end
end
[/spoiler]

&&&&&&&&&&&&&

#1
i can give it a shot lol :D :D ;D
check back in a lttle bit :D ^_^ :0

EDIT: I can't even try to help. The reason for this, is that I can't even get the script to work unmodified without the required images.

Please upload the images, or post a link to the original script.
&&&&&&&&&&&&&&&&

Jester

I have created a quick solution for DarthVollis, after he has pm'd me.  :)

Just in case (unpolished version):
[spoiler]module Cache
  #--------------------------------------------------------------------------
  # * Get Hud Graphic
  #--------------------------------------------------------------------------
  def self.hud(filename, hue=0)
    load_bitmap("Graphics/System/Hud/", filename, hue)
  end
end


class ZeldaHearts < Window_Base
  #--------------------------------------------------------------------------
  # * Changeable Area
  #--------------------------------------------------------------------------
  def switch
    90
  end
 
  def hud_x
    0
  end
 
  def hud_y
    0
  end
 
  def hud_width
    400
  end
 
  def hud_height
    240
  end
 
  def heart_file
    "hearts"
  end
 
  def heart_width
    24
  end
 
  def heart_padding
    -10
  end
 
  def heart_rowheight
    -10
  end
 
  def heart_row
    10
  end
 
  def hp_per_heart
    4
  end
 
  def heart_pieces
    4
  end
 
  #--------------------------------------------------------------------------
  # * Fixed Area
  #--------------------------------------------------------------------------
  def initialize
    super(hud_x, hud_y, hud_width, hud_height)
    self.windowskin = nil
    @bitmap = Cache.hud(heart_file)
    @switch = $game_switches[switch]
    if @switch
      draw_hearts
    end
  end
 
  def draw_hearts
    @lhearts = @hearts
    @lmaxHearts = @maxHearts
    @hearts = calc_hearts(get_hp)
    @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     
        if i < fullHearts
          get_heart_image(i, heart_pieces)
        elsif i == fullHearts
          get_heart_image(i, (partHearts*heart_pieces).round(0))
        else
          get_heart_image(i,0)
        end
      end
    end
  end
 
  def get_heart_image(heartIndex, fileIndex)   
    rect = Rect.new(fileIndex * heart_width, 0, @bitmap.width/(heart_pieces+1), @bitmap.height)
    contents.blt(heartIndex.modulo(heart_row)*(heart_width+heart_padding), (heartIndex/heart_row)*(@bitmap.height+heart_rowheight), @bitmap, rect, 255)
  end
 
  def get_hp
    $game_party.members[0].hp
  end
 
  def get_maxhp
    $game_party.members[0].mhp
  end
 
  def calc_hearts(hp)
    Float hearts = hp.to_f / hp_per_heart
    hearts.round(2)
  end
 
  def refresh
    self.contents.clear
    contents.clear
    draw_hearts
  end
  def update
    super   
    if @switch
      refresh
    end
  end
 
  def change 
    if @switch != $game_switches[switch]
      if $game_switches[switch]
        update
      else
        contents.clear
        self.contents.clear
      end
      @switch = $game_switches[switch]
    end
    if @lhearts == @hearts && @lmaxHearts == @maxHearts
      return
    else
      update
    end
  end
 
  def dispose
    super
    @bitmap.dispose
  end
end


class Scene_Map < Scene_Base
  alias start_window start
  alias term_window terminate
  alias update_window update
 
  def start
    start_window
    @hearthud = ZeldaHearts.new 
    @manahud = ZeldaMana.new
    update
  end


  def terminate
    @hearthud.dispose
    @manahud.dispose
    term_window
  end


  def update
    update_window
    @hearthud.change
    @manahud.change
  end
end


#~ Mana Addon:
class ZeldaMana < Window_Base
  #--------------------------------------------------------------------------
  # * Changeable Area
  #--------------------------------------------------------------------------
  def switch
    90
  end
 
  def hud_x
    0
  end
 
  def hud_y
    0
  end
 
  def hud_width
    400
  end
 
  def hud_height
    240
  end
 
  def mana_file
    "mana"
  end
 
  def mana_width
    24
  end
 
  def mana_padding
    -10
  end
 
  def mana_rowheight
    -10
  end
 
  def mana_row
    10
  end
 
  def mp_per_mana
    4
  end
 
  def mana_pieces
    4
  end
 
  #--------------------------------------------------------------------------
  # * Fixed Area
  #--------------------------------------------------------------------------
  def initialize
    super(hud_x, hud_y, hud_width, hud_height)
    self.windowskin = nil
    @bitmap = Cache.hud(mana_file)
    @switch = $game_switches[switch]
    if @switch
      draw_mana
    end
  end
 
  def draw_mana
    @lmana = @mana
    @lmaxMana = @maxMana
    @mana = calc_mana(get_mp)
    @maxMana = calc_mana(get_maxmp).to_i
   
    fullMana = @mana.to_i
    partMana = @mana - fullMana
    i = 0
    if fullMana
      for i in 0..@maxMana-1 do     
        if i < fullMana
          get_mana_image(i, mana_pieces)
        elsif i == fullMana
          get_mana_image(i, (partMana*mana_pieces).round(0))
        else
          get_mana_image(i,0)
        end
      end
    end
  end
 
  def get_mana_image(manaIndex, fileIndex)   
    rect = Rect.new(fileIndex * mana_width, 0, @bitmap.width/(mana_pieces+1), @bitmap.height)
    contents.blt(manaIndex.modulo(mana_row)*(mana_width+mana_padding), (manaIndex/mana_row)*(@bitmap.height+mana_rowheight), @bitmap, rect, 255)
  end
 
  def get_mp
    $game_party.members[0].mp
  end
 
  def get_maxmp
    $game_party.members[0].mmp
  end
 
  def calc_mana(mp)
    Float mana = mp.to_f / mp_per_mana
    mana.round(2)
  end
 
  def refresh
    self.contents.clear
    contents.clear
    draw_mana
  end
  def update
    super   
    if @switch
      refresh
    end
  end
 
  def change 
    if @switch != $game_switches[switch]
      if $game_switches[switch]
        update
      else
        contents.clear
        self.contents.clear
      end
      @switch = $game_switches[switch]
    end
    if @lmana == @mana && @lmaxMana == @maxMana
      return
    else
      update
    end
  end
 
  def dispose
    super
    @bitmap.dispose
  end
end
[/spoiler]

DarthVollis

Thanks for the help everyone! Jester solved it.