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.

Help With HUD Code

Im trying to make a hud kinda thing that displays your party's HP and MP and names and such in the 4 corners of the screen. The code works ok but only when I have 4 party members. I think it might be an if statement but I dont know how to code it :/ help please :]

Code:
class Window_PlayerHPMPHud < Window_Base
  def initialize
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width-32, height-32)
    self.opacity = 0
    self.contents.clear
  refresh
end
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
      y = 10
      x = 10
      actor = $game_party.actors[0]
      draw_actor_graphic(actor, x + 10, y + 40)
      draw_actor_name(actor, x + 30, y)
      draw_actor_hp(actor, x + 110, y - 10)
      draw_actor_sp(actor, x + 110, y + 10)
      actor = $game_party.actors[1]
      draw_actor_graphic(actor, x + 350, y + 40)
      draw_actor_name(actor, x + 380, y)
      draw_actor_hp(actor, x + 460, y - 10)
      draw_actor_sp(actor, x + 460, y + 10)
      actor = $game_party.actors[2]
      draw_actor_graphic(actor, x + 10, y + 430)
      draw_actor_name(actor, x + 30, y + 390)
      draw_actor_hp(actor, x + 110, y + 380)
      draw_actor_sp(actor, x + 110, y + 400)
      actor = $game_party.actors[3]
      draw_actor_graphic(actor, x + 350, y + 430)
      draw_actor_name(actor, x + 380, y + 390)
      draw_actor_hp(actor, x + 460, y + 380)
      draw_actor_sp(actor, x + 460, y + 400)
    end
  end


class Scene_Map
  alias playerhpmphud_main main
  alias playerhpmphud_update update
  def main
    @playerhpmphud = Window_PlayerHPMPHud.new
    playerhpmphud_main
    @playerhpmphud.dispose
  end
  def update
    @playerhpmphud.update
    playerhpmphud_update
  end
end
 
Well, for one, it only works with four members because you're always drawing the window as if there are four members in the party. What you should do to get the party members is this:

Code:
for actor in $game_party.actors

That way, you only get the actors in the party.

But to fix your problem of the stats showing even when there was no actor, that could easily be fixed with:

Code:
unless actor.nil?
  # Your code
end

or

Code:
if actor != nil
  # Your code
end

They're the same thing, but some prefer one over the other. But what it does is check to see if there actually is an actor before drawing the stats for them.

Also, whats the point of that line, "@item_max = $game_party.actors.size". It seems pretty useless.
 

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