Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Battle HUD Won't Show HP/MP, Fixed. You can close it!
m4uesviecr
post Jul 6 2012, 06:43 AM
Post #1


Level 7
Group Icon

Group: Member
Posts: 94
Type: Musician
RM Skill: Skilled




Hey there! I am new to scripting and have thus taken a liking to the scripting tutorial thread on this site. I was using the tutorial provided by Ccoa here --> Adding A Window to A Scene, and editing it so that it could function as a battle HUD.

As of now, everything works perfectly fine: The game starts, when the switch turns on, the window appears showing the specified iconery, it is the correct size, blah blah blah, but it doesn't show the player's HP or MP. The area of code I think that I believe I need to edit is this:

CODE
self.contents.draw_text(@actor_hp, 0, 32, 180, @hp.to_s)


If it is, I do not know what to put there, and if it isn't, I have no unearthly clue what is wrong. I tried replacing the text (assuming it may be too low or positioned incorrectly), but that didn't work. It just doesn't show up.

Here is the entire script, and I attached the icon pngs you will need to import into your game to allow the icons to show to this thread.

Battle HUD Code
CODE
class Window_HUD < Window_Base
  def initialize
    super(0,0, 110, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    
    # This will make sure tis isn't visible all the time. (It should only be
    # Viewed when in a battle
    self.visible = false
    
    #Make the windonw semi-transparent (In battle it won't be, but at least
    #I know what method to use when needing to change the opacity
    self.opacity = 225
    
    # Display actor data (In the game, I may let player switch btw characters)
    @actor = $data_actors[1]
    #Get hp of that actor
    @hp = @actor_hp
    #Get mp of the actor
    @mp = @actor_mp
    
      refresh
    end
    
    #remember to clear the contents of the window (basically, define refresh)
    def refresh
      self.contents.clear
      
      # This isn't necessary, BUT, you can draw the HP icon.
      bitmap = Cache.load_bitmap("Graphics/Icon/", "HP")
      self.contents.blt(0,4, bitmap, Rect.new(0,0,24,24),255)
      
      #draw the actual HP of the actor (I want a gauge here soon)
      self.contents.draw_text(0, 32, 96, 32, @hp.to_s)
      
      #draw the icon for mp on the window (255 is the opacity!)
      bitmap = Cache.load_bitmap("Graphics/Icon/", "MP")
      self.contents.blt(0,36, bitmap, Rect.new(0,0,24,24),255)
      
      #draw the MP of the actor
      self.contents.draw_text(32, 32, 96, 32, @mp.to_s)
    end
    
    #run each and every frame
    def update
      
      # The HUD will be visible only if this switch is on.
      self.visible = $game_switches[1]
      
      #Don't update if we can't see the window
      if !self.visible
        return
      end
      
      #only reresh if something has changed <-- IMPORTANT
      if (@hp != @actor_hp) or (@mp != @actor_hp)
        # current hp of actor
        @hp = @actor_hp
        #current mp of actor
        @mp = @actor_mp
        
        refresh
      end
        #this allows the parent windows to do what needs to be done. (i.e
        #window base and whatnot)
        super
      end
    end


In your graphics folder, title a new folder "Icon", and stick these two in there. Make sure their files names are capitalized like this -> HP and MP.

Thank you in advance for helping me!

This post has been edited by m4uesviecr: Jul 8 2012, 07:48 AM
Attached File(s)
Attached File  HP.png ( 852bytes ) Number of downloads: 0
Attached File  MP.png ( 330bytes ) Number of downloads: 0
 


__________________________
My Project


What I'm Looking Forward To

Awesome Sauces
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Jul 8 2012, 05:25 AM
Post #2


Level 50
Group Icon

Group: +Gold Member
Posts: 1,527
Type: Scripter
RM Skill: Undisclosed




I've made a few tweaks which should help:

CODE
class Window_HUD < Window_Base
  def initialize
    super(0,0, 110, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    
    # This will make sure tis isn't visible all the time. (It should only be
    # Viewed when in a battle
    self.visible = false
    
    #Make the windonw semi-transparent (In battle it won't be, but at least
    #I know what method to use when needing to change the opacity
    self.opacity = 225
    
    # Get the leading actor in the party
    @actor = $game_party.members[0]
    
    # If there wasn't any actors in the party, set the HP & MP to 0
    if @actor == nil
      @hp = @mp = 0
    # If there was an actor in the party
    else
      #Get hp of that actor
      @hp = @actor.hp
      #Get mp of the actor
      @mp = @actor.mp
    end
    
    # Redraw the graphics
    refresh
  end
    
  #remember to clear the contents of the window (basically, define refresh)
  def refresh
    self.contents.clear
    
    # This isn't necessary, BUT, you can draw the HP icon.
    bitmap = Cache.load_bitmap("Graphics/Icon/", "HP")
    self.contents.blt(0,4, bitmap, Rect.new(0,0,24,24),255)
    
    #draw the actual HP of the actor (I want a gauge here soon)
    self.contents.draw_text(0, 32, 96, 32, @hp.to_s)
    
    #draw the icon for mp on the window (255 is the opacity!)
    bitmap = Cache.load_bitmap("Graphics/Icon/", "MP")
    self.contents.blt(0,36, bitmap, Rect.new(0,0,24,24),255)
    
    #draw the MP of the actor
    self.contents.draw_text(32, 32, 96, 32, @mp.to_s)
  end
    
  #run each and every frame
  def update
    
    # The HUD will be visible only if this switch is on.
    self.visible = $game_switches[1]
    
    #Don't update if we can't see the window
    if !self.visible
      return
    end
    
    #only reresh if something has changed <-- IMPORTANT
    if (@hp != @actor.hp) or (@mp != @actor.hp) or
       (@actor != $game_party.members[0])
      # current leading actor in the party
      @actor = $game_party.members[0]
      # If there wasn't any actors in the party, set the HP & MP to 0
      if @actor == nil
        @hp = @mp = 0
      # If there was an actor in the party
      else
        # Get hp of that actor
        @hp = @actor.hp
        # Get mp of the actor
        @mp = @actor.mp
      end
      # Redraw the graphics
      refresh
    end
    
    #this allows the parent windows to do what needs to be done. (i.e
    #window base and whatnot)
    super
  end
end


I've edited the code to get the leading actor in the party, as opposed to only getting the first actor in the database, ad I've included some checks if there isn't an actor in the party.

And in your update method, I have changed the refresh requirements to check if the hp/mp has changed for the actor (@actor.hp, not @actor_hp), as well as checking if the actor has changed.

I think that's about it, hope that helps happy.gif


__________________________
K.I.S.S.
Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
m4uesviecr
post Jul 8 2012, 07:47 AM
Post #3


Level 7
Group Icon

Group: Member
Posts: 94
Type: Musician
RM Skill: Skilled




Hey Nightrunner! I actually had a friend look over it and offer some advice, but I saw you put in an edit for when there is no party member present! Thank you so much!

I plan on trying to use this (with some modifications), for a game I will be making later on, so your addition will be duly noted!

Again, thank you very much. smile.gif



__________________________
My Project


What I'm Looking Forward To

Awesome Sauces
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 25th May 2013 - 02:37 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker