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.

Refreshing HUDs

I have this problem repeatedly, this time with compatibility between Omegazion's Roguelike Battle System and Dargor's Regeneration script.

HP regenerates on the map, but ORBS HUD doesn't pick it up. When I enter and exit the menu, it refreshes. I tried using what the menu was doing, $scene = scene_map.new, but I get an error. I can find where the HUD refreshes itself in the ORBS code, but have no idea how/if I could use it o.o
 
I was reluctant to post them since they're so long, if the answer was something obvious I didn't know, but I guess it's the only way to understand it o.O

Code:
#==============================================================================

# ** Regeneration

#------------------------------------------------------------------------------

#  © Dargor, 2008

#  04/11/08

#  Version 1.0

#  Requested by shc0023

#------------------------------------------------------------------------------

#  VERSION HISTORY:

#   - 1.0 (01/11/08), Initial release

#------------------------------------------------------------------------------

#  INTRODUCTION:

#     This script will let actors regenerate HP/MP in 3 occasions.

#     Regeneration can occur on map, when defending or at the end of 

#     a battle. This system is highly customizable. You can specify any 

#     regeneration formula you want, for any actors in any of the 3

#     occasions!

#------------------------------------------------------------------------------

#  INSTRUCTIONS:

#   1) Paste the script above main

#   2) Edit the constants in the Regeneration module

#==============================================================================

 

#==============================================================================

#  ** Regeneration Configuration Module

#==============================================================================

 

module Regeneration

  # Regenerate after battles?

  Battle_Regen = false

  # Defense Regen

  Defense_Regen = false

  # Regenerate on map?

  Map_Regen = true

  # On Map Regeneration delay (in frames)

  Map_Regen_Delay = 240

  # End battle results allowed (0: Victory, 1: Escape, 2: Defeated)

  Battle_End = [0]

  # States that prevents from regenerating after battles

  NoRegen_States = [1]

  # Play recovery SE on map?

  Map_Recovery_SE = true

  # Super Guard Regeneration Multiplier

  Super_Guard_Multiplier = 3

  # Battle Regeneration rate formula for HP/MP

  # SYNTAX: {actor_id => "formula"}

  Battle_HP_Formulas = {}

  Battle_MP_Formulas = {}

  # Default formula if none specified

  Battle_HP_Formulas.default = "(self.maxhp / 100) * 6" # 6% of maxhp

  Battle_MP_Formulas.default = "(self.maxmp / 100) * 3" # 3% of maxmp

  # Defense Regeneration rate formula for HP/MP

  # SYNTAX: {actor_id => "formula"}

  Defense_HP_Formulas = {}

  Defense_MP_Formulas = {}

  # Default formula if none specified

  Defense_HP_Formulas.default = "(self.maxhp / 100) * 2" # 2% of maxhp

  Defense_MP_Formulas.default = "(self.maxmp / 100) * 1" # 1% of maxmp

  # Map Regeneration rate formula for HP/MP

  # SYNTAX: {actor_id => "formula"}

  Map_HP_Formulas = {}

  Map_MP_Formulas = {}

  # Default formula if none specified

  Map_HP_Formulas.default = "(self.maxhp / 100) * 2" # 2% of maxhp

  Map_MP_Formulas.default = "(self.maxmp / 100) * 1" # 1% of maxmp

end

 

#==============================================================================

# ** Game_System

#------------------------------------------------------------------------------

#  This class handles system-related data. Also manages vehicles and BGM, etc.

# The instance of this class is referenced by $game_system.

#==============================================================================

 

class Game_System

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor  :map_regen

  attr_accessor  :battle_regen

  attr_accessor  :defense_regen

  #--------------------------------------------------------------------------

  # * Alias Listing

  #--------------------------------------------------------------------------

  alias dargor_vx_battle_regen_system_initialize initialize

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    # The usual

    dargor_vx_battle_regen_system_initialize

    # Map/Battle Regeneration flags

    @battle_regen = Regeneration::Battle_Regen

    @defense_regen = Regeneration::Defense_Regen

    @map_regen = Regeneration::Map_Regen

  end

end

 

#==============================================================================

# ** Game_Actor

#------------------------------------------------------------------------------

#  This class handles actors. It's used within the Game_Actors class

# ($game_actors) and referenced by the Game_Party class ($game_party).

#==============================================================================

 

class Game_Actor < Game_Battler

  

  #--------------------------------------------------------------------------

  # * Get Map HP/MP Regeneration Formulas

  #--------------------------------------------------------------------------

  def map_regen_formulas

    hp_formula = nil

    mp_formula = nil

    # Get actor's map hp regen formula

    if Regeneration::Map_HP_Formulas[@actor_id].nil?

      hp_formula = eval(Regeneration::Map_HP_Formulas.default)

    else

      hp_formula = eval(Regeneration::Map_HP_Formulas[@actor_id])

    end

    # Get actor's map mp regen formula

    if Regeneration::Map_MP_Formulas[@actor_id].nil?

      mp_formula = eval(Regeneration::Map_MP_Formulas.default)

    else

      mp_formula = eval(Regeneration::Map_MP_Formulas[@actor_id])

    end

    hp_formula = 1 if hp_formula == 0

    mp_formula = 1 if mp_formula == 0

    return [hp_formula, mp_formula]

  end

  #--------------------------------------------------------------------------

  # * Regenerate on Map

  #--------------------------------------------------------------------------

  def map_regenerate

    # Check if map regeneration is allowed

    if $game_system.map_regen

      # Make sure the actor is not in a NoRegen state

      for state_id in Regeneration::NoRegen_States

        if state?(state_id)

          # Do not regenerate

          return

        end

      end

      # Regenerate

      self.hp += map_regen_formulas[0]

      self.mp += map_regen_formulas[1]

      $scene = scene_map.new

    end

  end

  #--------------------------------------------------------------------------

  # * Get defense HP/MP Regeneration Formulas

  #--------------------------------------------------------------------------

  def defense_regen_formulas

    hp_formula = nil

    mp_formula = nil

    # Get actor's battle hp regen formula

    if Regeneration::Defense_HP_Formulas[@actor_id].nil?

      hp_formula = eval(Regeneration::Defense_HP_Formulas.default)

    else

      hp_formula = eval(Regeneration::Defense_HP_Formulas[@actor_id])

    end

    # Get actor's battle mp regen formula

    if Regeneration::Defense_HP_Formulas[@actor_id].nil?

      mp_formula = eval(Regeneration::Defense_MP_Formulas.default)

    else

      mp_formula = eval(Regeneration::Defense_MP_Formulas[@actor_id])

    end

    hp_formula = 1 if hp_formula == 0

    mp_formula = 1 if mp_formula == 0

    if super_guard

      hp_formula *= Regeneration::Super_Guard_Multiplier

      mp_formula *= Regeneration::Super_Guard_Multiplier

    end

    return [hp_formula, mp_formula]

  end

  #--------------------------------------------------------------------------

  # * Regenerate After Battles

  #--------------------------------------------------------------------------

  def defense_regenerate

    # Check if battle regeneration la allowed

    if $game_system.defense_regen

     # Make sure the actor is not in a NoRegen state

     for state_id in Regeneration::NoRegen_States

       if state?(state_id)

         # Do not regenerate

         return

       end

      end

     end

    @hp_damage = -defense_regen_formulas[0]

    @mp_damage = -defense_regen_formulas[1]

    self.hp -= @hp_damage

    self.mp -= @mp_damage

  end

  #--------------------------------------------------------------------------

  # * Get Battle HP/MP Regeneration Formulas

  #--------------------------------------------------------------------------

  def battle_regen_formulas

    hp_formula = nil

    mp_formula = nil

    # Get actor's battle hp regen formula

    if Regeneration::Battle_HP_Formulas[@actor_id].nil?

      hp_formula = eval(Regeneration::Battle_HP_Formulas.default)

    else

      hp_formula = eval(Regeneration::Battle_HP_Formulas[@actor_id])

    end

    # Get actor's battle mp regen formula

    if Regeneration::Battle_MP_Formulas[@actor_id].nil?

      mp_formula = eval(Regeneration::Battle_MP_Formulas.default)

    else

      mp_formula = eval(Regeneration::Battle_MP_Formulas[@actor_id])

    end

    hp_formula = 1 if hp_formula == 0

    mp_formula = 1 if mp_formula == 0

    return [hp_formula, mp_formula]

  end

  #--------------------------------------------------------------------------

  # * Regenerate After Battles

  #--------------------------------------------------------------------------

  def battle_regenerate

    # Check if battle regeneration is allowed

    if $game_system.battle_regen

      # Make sure the actor is not in a NoRegen state

      for state_id in Regeneration::NoRegen_States

        if state?(state_id)

          # Do not regenerate

          return

        end

      end

    end

    @hp_damage = -battle_regen_formulas[0]

    @mp_damage = -battle_regen_formulas[1]

    self.hp -= @hp_damage

    self.mp -= @mp_damage

  end

end

 

#==============================================================================

# ** Game_Party

#------------------------------------------------------------------------------

#  This class handles the party. It includes information on amount of gold

# and items. The instance of this class is referenced by $game_party.

#==============================================================================

 

class Game_Party

  #--------------------------------------------------------------------------

  # * Regenerate Party

  #--------------------------------------------------------------------------

  def regenerate

    if Graphics.frame_count % Regeneration::Map_Regen_Delay == 0

      for member in members

        total_hp = member.hp

        total_maxhp = member.maxhp

        member.map_regenerate

      end

      Sound.play_recovery unless total_hp == total_maxhp or !Regeneration::Map_Recovery_SE

    end

  end

end

 

#==============================================================================

# ** Game_Player

#------------------------------------------------------------------------------

#  This class handles maps. It includes event starting determinants and map

# scrolling functions. The instance of this class is referenced by $game_map.

#==============================================================================

 

class Game_Player < Game_Character

  #--------------------------------------------------------------------------

  # * Alias Listing

  #--------------------------------------------------------------------------

  alias dargor_vx_battle_regen_player_update update

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # If player is free to move

    if movable?

      # Regenerate

      $game_party.regenerate

    end 

    # The Usual

    dargor_vx_battle_regen_player_update

  end

end

   

#==============================================================================

# ** Scene_Battle

#------------------------------------------------------------------------------

#  This class performs battle screen processing.

#==============================================================================

 

class Scene_Battle < Scene_Base

  #--------------------------------------------------------------------------

  # * Alias Listing

  #--------------------------------------------------------------------------

  alias dargor_vx_battle_regen_battle_end battle_end

  alias dargor_vx_battle_regen_execute_action_guard execute_action_guard

  #-----------------------------------------------------------------------------

  # Execute Action_Guard

  #-----------------------------------------------------------------------------

  def execute_action_guard

    # The Usual

    dargor_vx_battle_regen_execute_action_guard

    if $game_system.defense_regen

      # Regenerate actor

      @active_battler.defense_regenerate

      # Display regeneration text

      display_hp_damage(@active_battler)

      wait(45)

      @message_window.back_one

      display_mp_damage(@active_battler)

      wait(45)

      @message_window.clear

    end

  end

  #--------------------------------------------------------------------------

  # * End Battle

  #     result : Results (0: win, 1: escape, 2:lose)

  #--------------------------------------------------------------------------

  def battle_end(result)

    # If regenerating is allowed with this battle end result

    if Regeneration::Battle_End.include?(result)

      for member in $game_party.members

        # Regenerate actor

        member.battle_regenerate

        # Display regeneration text

        Sound.play_recovery

        display_hp_regeneration(member)

        display_mp_regeneration(member)

        wait_for_message

        @message_window.clear

      end

    end

    # The usual

    dargor_vx_battle_regen_battle_end(result)

  end

  #--------------------------------------------------------------------------

  # * Show HP Regeneration

  #     target : Target

  #     obj    : Skill or item

  #--------------------------------------------------------------------------

  def display_hp_regeneration(target)

    if target.hp_damage == 0                # No damage

      fmt = target.actor? ? Vocab::ActorNoDamage : Vocab::EnemyNoDamage

      text = sprintf(fmt, target.name)

    elsif target.absorbed                   # Absorb

      fmt = target.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain

      text = sprintf(fmt, target.name, Vocab::hp, target.hp_damage)

    elsif target.hp_damage > 0              # Damage

      if target.actor?

        text = sprintf(Vocab::ActorDamage, target.name, target.hp_damage)

        Sound.play_actor_damage

        $game_troop.screen.start_shake(5, 5, 10)

      else

        text = sprintf(Vocab::EnemyDamage, target.name, target.hp_damage)

        Sound.play_enemy_damage

        target.blink = true

      end

    else                                    # Recovery

      fmt = target.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery

      text = sprintf(fmt, target.name, Vocab::hp, -target.hp_damage)

    end

    $game_message.texts.push(text)

  end

  #--------------------------------------------------------------------------

  # * Show MP Regeneration

  #     target : Target

  #     obj    : Skill or item

  #--------------------------------------------------------------------------

  def display_mp_regeneration(target)

    return if target.dead?

    return if target.mp_damage == 0

    if target.absorbed                      # Absorb

      fmt = target.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain

      text = sprintf(fmt, target.name, Vocab::mp, target.mp_damage)

    elsif target.mp_damage > 0              # Damage

      fmt = target.actor? ? Vocab::ActorLoss : Vocab::EnemyLoss

      text = sprintf(fmt, target.name, Vocab::mp, target.mp_damage)

    else                                    # Recovery

      fmt = target.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery

      text = sprintf(fmt, target.name, Vocab::mp, -target.mp_damage)

    end

    $game_message.texts.push(text)

  end 

end

It looks like the ORBS is too long to post o.O I posted the part about the HUD, anyway.
Code:
#==============================================================================

# ** ORBS::Sprite_CharacterHUD

#------------------------------------------------------------------------------

#  This sprite shows the character's HP/MP and states on the screen.

#==============================================================================

class Sprite_CharacterHUD < ::Sprite

 

  # * Public Instance Variables

  attr_reader :battler

  

  # * Object initialization

  def initialize(index, viewport = nil)

    super(viewport)

    @index = index

    @new_battler = @battler = $game_party.members[index]

    self.bitmap = Bitmap.new(134, 80)

    self.x = 1 + index * 136

    self.y = 2

    refresh

  end

  

  # * Refresh Contents

  def refresh(bitmap_only = false)

    self.bitmap.clear

    @character_sprite.dispose unless @character_sprite.nil? or bitmap_only

    return if @battler.nil? 

    self.bitmap.fill_rect(0, 0, 136, 64, Color.new(0, 0, 0, 128))

    unless bitmap_only

      @character_sprite = Sprite.new(viewport)

      @character_sprite.x = self.x + 2

      @character_sprite.y = self.y + 2

      @character_sprite.z = self.z + 2

      bmp = @character_sprite.bitmap = Cache.character(@battler.character_name)

      i = @battler.character_index

      sign = @battler.character_name[/^[\!\$]./]

      if sign != nil and sign.include?('$')

        @cs_cw = bmp.width / 3

        cs_ch = bmp.height / 4

        @offset_x = 0

        offset_y = 0

      else

        @cs_cw = bmp.width / 12

        cs_ch = bmp.height / 8

        @offset_x = (@cs_cw * 3) * (i % 4) 

        offset_y = (cs_ch * 4) * (i / 4)

      end

      @character_sprite.src_rect.set(@cs_cw + @offset_x, offset_y, @cs_cw, cs_ch)

    end

    ORBS.window.contents = self.bitmap

    ORBS.window.draw_actor_hp_gauge(@battler, 40, -6, 84)

    ORBS.window.draw_actor_mp_gauge(@battler, 40, 4, 84)

    ORBS.window.draw_actor_state(@battler, 3, 37, 120)

    ORBS.window.contents = nil

  end

  

  # * Set Viewport

  def viewport=(viewport)

    super

    @character_sprite.viewport = viewport unless @character_sprite.nil?

  end

  

  # * Dispose method

  def dispose

    @character_sprite.dispose unless @character_sprite.nil?

    super

  end

  

  # * Set Visibility - Change visibility of the character sprite as well

  def visible=(visibility)

    super(visibility)

    @character_sprite.visible = visibility unless @character_sprite.nil?

  end

  

  # * Frame Update

  def update

    super

    self.visible = ORBS.enabled?

    @new_battler = $game_party.members[@index]

    if @new_battler != @battler

      @battler = @new_battler

      refresh

    end

    return if @battler.nil?

    @character_sprite.update

    if @battler.dead?

      @character_sprite.src_rect.x = @cs_cw + @offset_x

      @character_sprite.tone.set(-50, -50, -50, 50)

    else

      case Graphics.frame_count % 60

      when 0, 30 ; @character_sprite.src_rect.x = @cs_cw + @offset_x

      when 15 ; @character_sprite.src_rect.x = @offset_x

      when 45 ; @character_sprite.src_rect.x = @cs_cw * 2 + @offset_x

      end

      @character_sprite.tone.set(0, 0, 0, 0)

    end

  end

 

end

 
 

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