Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Zexion on April 28, 2013, 03:16:10 pm

Title: Error updating HUD
Post by: Zexion on April 28, 2013, 03:16:10 pm
Nvm I fixed it. Just incase anyone was wondering, the fix was simply deleteing these lines:

   if @old_hp != @actor.hp or
      @old_sp != @actor.sp

and of course the extra
end

That make it only update if the hp/sp are changing
Spoiler: ShowHide
I edited a HUD script by sub to my liking and it does what it should do for the most part. However, updates to the actual graphics only happen if you take or heal damage to hp/sp. For example, I made the health grow by a variable that I can set by script call. It works, but I have to take damage for it to update to the new sprite. I am now trying to make the mp bar flash if mp_charge = 1, but since the graphics don't update all the time, it doesn't work. Can someone explain to me what I need to do?

Script:
Code: ruby
module PLAYER_HUD
                 Toggle = 27
                 Xcoord = 0  
                 Ycoord = 230
end

class Window_Base < Window
 
 def draw_base(actor, x, y) # Draws the base picture.
   actor = $game_party.actors[0]
   
   case $game_variables[1]
     when 1
       back = RPG::Cache.picture("P1 - HUD/" + "L2-Base")
     when 2
       back = RPG::Cache.picture("P1 - HUD/" + "L3-Base")
     when 3
       back = RPG::Cache.picture("P1 - HUD/" + "L4-Base")
     when 4
       back = RPG::Cache.picture("P1 - HUD/" + "L5-Base")
     else
       back = RPG::Cache.picture("P1 - HUD/" + "L1-Base")
     end
   cw = back.width  
   ch = back.height
   src_rect = Rect.new(0, 0, cw, ch)    
   self.contents.blt(x + 5, y, back, src_rect)
   
   case $game_variables[1]
     when 1
       bar = RPG::Cache.picture("P1 - HUD/" + "L2-Health")
     when 2
       bar = RPG::Cache.picture("P1 - HUD/" + "L3-Health")
     when 3
       bar = RPG::Cache.picture("P1 - HUD/" + "L4-Health")
     when 4
       bar = RPG::Cache.picture("P1 - HUD/" + "L5-Health")
     else
       bar = RPG::Cache.picture("P1 - HUD/" + "L1-Health")
     end
   cw = bar.width  * actor.hp / actor.maxhp
   ch = bar.height
   src_rect = Rect.new(0, 0, cw, ch)
   self.contents.blt(x + 28, y + 51, bar, src_rect)
 end
 
 def draw_mpbar(actor, x, y)
   actor = $game_party.actors[0]
   
   if $mp_charge == 1 # Checks for MP Charge Remember to Change!
   back = RPG::Cache.picture("P1 - HUD/" + "MPCharg-Base")
   else
   back = RPG::Cache.picture("P1 - HUD/" + "MP-Base")
   end
   cw = back.width  
   ch = back.height
   src_rect = Rect.new(0, 0, cw, ch)    
   self.contents.blt(x, y, back, src_rect)
   
   if $mp_charge == 1 # Checks for MP Charge Remember to Change!
     if $mp_flash == 0
       bar = RPG::Cache.picture("P1 - HUD/" + "MPCharg-Dark")
     else
       bar = RPG::Cache.picture("P1 - HUD/" + "MPCharg-Lit")
     end
   else
      bar = RPG::Cache.picture("P1 - HUD/" + "MP-Bar")
    end
   
   cw = bar.width  * actor.sp / actor.maxsp
   ch = bar.height
   src_rect = Rect.new(0, 0, cw, ch)
   self.contents.blt(x + 24, y + 1, bar, src_rect)
 end
 
end

class Window_PlayerHUD < Window_Base
def reset
   @old_hp = @actor.hp
   @old_sp = @actor.sp
end
 
def initialize
   super(170, 192, 310, 128)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.windowskin = RPG::Cache.windowskin("")
   self.opacity = 0
   @actor = $game_party.actors[0]
   if @actor != nil
   reset
   refresh
   end
 end  
 
def refresh
 self.contents.clear
   draw_base(@actor, 0, 0)
   draw_mpbar(@actor, 0, 61)
   reset
end
def update
  @actor = $game_party.actors[0]
  if @actor != nil  
  if @old_hp != @actor.hp or
     @old_sp != @actor.sp
  refresh
  end
end
  # Creates a loop that makes the MP bar flash on recharge.
 if $mp_charge == 1
  if $mp_flash == 0
    $mp_flash += 1
  end
 
  if $mp_flash == 5
    $mp_flash -= 1
  end
end
end
end

class Scene_Map
alias phud_main main
def main
   @phud = Window_PlayerHUD.new
   @phud.x = PLAYER_HUD::Xcoord
   @phud.y = PLAYER_HUD::Ycoord
   if $game_switches[PLAYER_HUD::Toggle] == false
   @phud.visible = true  
   else
   @phud.visible = false  
   end    
   phud_main
   @phud.dispose
end
alias phud_update update
def update
   if $game_switches[PLAYER_HUD::Toggle] == false
   @phud.visible = true  
   else
   @phud.visible = false  
   end    
   @phud.update
   phud_update
end  
end  


If you need a demo, just ask and I'll pm you!
Title: Re: Error updating HUD
Post by: KK20 on April 29, 2013, 12:59:31 am
Might want to reconsider that, seeing as it will always draw new graphics every frame update.
Make it check if current HP/MP or max HP/MP are different to update.
Title: Re: Error updating HUD
Post by: Zexion on April 29, 2013, 03:14:16 pm
Yeah, I am putting it back now because I realized that hp will be added when I extend the bar, so it would make it update either way haha.