Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> 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: Revolutionary
Posts: 100
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
   
 
Start new topic
Replies
m4uesviecr
post Jul 8 2012, 07:47 AM
Post #2


Level 7
Group Icon

Group: Revolutionary
Posts: 100
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
   

Posts in this topic


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: 18th June 2013 - 10:56 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker