The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: UltimaZix on October 22, 2013, 04:28:12 AM

Title: (RESOLVED) [XP] Extremely simple hud fix needed
Post by: UltimaZix on October 22, 2013, 04:28:12 AM
So the game I've been working on won't have very many battles, but will have several environmental ways of dealing damage. I then came to the conclusion that the player should be able to see his/her HP at all times, so they don't have to constantly hit Esc to see their health after they've been hurt.
I decided I'd find a super simple HUD to display just their HP, which I DID find (http://www.gdunlimited.net/forums/topic/3598-your-very-own-hud/ (http://www.gdunlimited.net/forums/topic/3598-your-very-own-hud/)) and was very happy with. Unfortunately, It shows no matter what the player is doing, which is especially difficult to deal with during cutscenes. 

So, All I need are these few fixes:

1. Some way to turn off the HUD for periods of time, preferably with a switch of some sort so I can easily cut it out of certain scenes.

2. The removal of the arrow at the end of the HUD, I have no idea why that's there.

That's all I really need. I normally can figure these things out, despite my utter lack of programming and scripting knowledge, but so far I've only been able to figure out how to put the window where I want it to be.

Original Script:
Spoiler for:
Code: [Select]
class Window_YourHUD < Window_Base
  def initialize
    super(0, 0, 640, 64)
    self.opacity = 150
    self.contents = Bitmap.new(640 - 32, 64 - 32)
    refresh
  end
  def refresh
    self.contents.clear
    reset_variables
    return if !@actor
    draw_actor_hp(@actor, 0, 0)
    draw_actor_sp(@actor, 300, 0)
    draw_actor_exp(@actor, 500, 0)
  end
  def reset_variables
    @actor = $game_party.actors[0]
    @old_hp = @actor ? @actor.hp : 0
    @old_maxhp = @actor ? @actor.maxhp : 0
    @old_sp = @actor ? @actor.sp : 0
    @old_maxsp = @actor ? @actor.maxsp : 0
  end
  def update
    super
    refresh if (@actor = $game_party.actors[0] or
                @old_hp = @actor ? @actor.hp : 0 or
                @old_maxhp = @actor ? @actor.maxhp : 0 or
                @old_sp = @actor ? @actor.sp : 0 or
                @old_maxsp = @actor ? @actor.maxsp : 0)
  end
end
class Scene_Map
  alias yourhud_main main
  alias yourhud_update update
  def main
    @yourhud = Window_YourHUD.new
    yourhud_main
    @yourhud.dispose
  end
  def update
    @yourhud.update
    yourhud_update
  end
end

Same Script, but edited to my settings:
Spoiler for:
Code: [Select]
class Window_YourHUD < Window_Base
  def initialize
    super(7, 410, 200, 64)
    self.opacity = 150
    self.contents = Bitmap.new(640 - 32, 64 - 32)
    refresh
  end
  def refresh
    self.contents.clear
    reset_variables
    return if !@actor
    draw_actor_hp(@actor, 20, 0)
  end
  def reset_variables
    @actor = $game_party.actors[0]
    @old_hp = @actor ? @actor.hp : 0
    @old_maxhp = @actor ? @actor.maxhp : 0
    @old_sp = @actor ? @actor.sp : 0
    @old_maxsp = @actor ? @actor.maxsp : 0
  end
  def update
    super
    refresh if (@actor = $game_party.actors[0] or
                @old_hp = @actor ? @actor.hp : 0 or
                @old_maxhp = @actor ? @actor.maxhp : 0 or
                @old_sp = @actor ? @actor.sp : 0 or
                @old_maxsp = @actor ? @actor.maxsp : 0)
  end
end
class Scene_Map
  alias yourhud_main main
  alias yourhud_update update
  def main
    @yourhud = Window_YourHUD.new
    yourhud_main
    @yourhud.dispose
  end
  def update
    @yourhud.update
    yourhud_update
  end
end
Title: Re: [XP] Extremely simple hud fix needed
Post by: UltimaZix on October 24, 2013, 12:47:09 AM
Bumpity
Title: Re: [XP] Extremely simple hud fix needed
Post by: UltimaZix on October 28, 2013, 03:04:45 AM
Lump da BUMP
Title: Re: [XP] Extremely simple hud fix needed
Post by: Heretic86 on November 09, 2013, 01:30:03 AM
I'll try taking a crack at this later tonight when I have more time.  But fixing is actually a relatively simple task.  Add a new "Option" to your Game System with an alias.  Then to turn the HUD on or off, use a Script: $game_system.my_option = true / false.  In the Update method, just use it to hide but not remove the HUD.

Code: [Select]
class Game_System

  attr_accessor :my_new_property # allow $game_system.my_new_property = value in Script

  alias my_custom_initialize initialize
  def initialize
    # Run Original Initialize or any other Aliases of Initialize
    my_custom_initialize
    # New Property
    @my_new_property = true
  end
end

class My_Custom_Hud
  def update
    if $game_system.my_option
      @opacity = 255 # Or @object.opacity = 255
    else
      @opacity = 0    # or @object.opacity = 0
    end
    # Rest of update code
  end
end

---

Edit

Got it.  You were very close.  Just add "attr_accessor :yourhud" to Scene_Map and you can use an Event Script to set opacity and contents_opacity to 0 for your scene.

$scene.yourhud.opacity = 0
$scene.yourhud.contents_opacity = 0

Not sure about that White Arrow pointing right...
Title: Re: [XP] Extremely simple hud fix needed
Post by: EvilM00s on November 09, 2013, 05:18:07 PM
Bumpity
Lump da BUMP

No malice, but that kind of thing typically gets you nowhere or worse around here. Just sayin'.
Title: Re: [XP] Extremely simple hud fix needed
Post by: UltimaZix on November 10, 2013, 10:40:21 PM
I'll try taking a crack at this later tonight when I have more time.  But fixing is actually a relatively simple task.  Add a new "Option" to your Game System with an alias.  Then to turn the HUD on or off, use a Script: $game_system.my_option = true / false.  In the Update method, just use it to hide but not remove the HUD.

Code: [Select]
class Game_System

  attr_accessor :my_new_property # allow $game_system.my_new_property = value in Script

  alias my_custom_initialize initialize
  def initialize
    # Run Original Initialize or any other Aliases of Initialize
    my_custom_initialize
    # New Property
    @my_new_property = true
  end
end

class My_Custom_Hud
  def update
    if $game_system.my_option
      @opacity = 255 # Or @object.opacity = 255
    else
      @opacity = 0    # or @object.opacity = 0
    end
    # Rest of update code
  end
end

---

Edit

Got it.  You were very close.  Just add "attr_accessor :yourhud" to Scene_Map and you can use an Event Script to set opacity and contents_opacity to 0 for your scene.

$scene.yourhud.opacity = 0
$scene.yourhud.contents_opacity = 0

Not sure about that White Arrow pointing right...

First of all, you are an extremely beautiful human being for putting all that effort into this silly menial problem of mine. For that, you have my eternal gratitude.
Secondly, I'll test it out right now and see if it works, thanks again!

EDIT - GOOD GRAVY, IT WORKS! Also, I did some testing with that dagnabbed arrow, and I think it's an issue with window_base. Whenever I make the window not show all the text, or make it slightly smaller, the arrow appears. I'll try editing your_hud and the window_base to see what I can do to erase it.

EDIT 2 - Got rid of the arrow!!! I just lowered how much space was left for content in the box, and it went away! Thanks again for all your help man, consider yourself credited in my game! What name/alias shall I list you as?


Bumpity
Lump da BUMP

No malice, but that kind of thing typically gets you nowhere or worse around here. Just sayin'.

Ah, I see. Thought I read somewhere that bumping was allowed, so I figured I'd try it. Thanks for lettin' me know, I'll refrain from doing so.
Title: Re: (RESOLVED) [XP] Extremely simple hud fix needed
Post by: Heretic86 on November 11, 2013, 03:13:29 AM
Glad we could help.

Bump notes:  Generally one is allowed after at least 24 hours.  Three posts in 5 minutes with no other replies without eding is usually what most moderators and admins get frustrated about.
Title: Re: (RESOLVED) [XP] Extremely simple hud fix needed
Post by: UltimaZix on November 11, 2013, 04:26:17 AM
Glad we could help.

Bump notes:  Generally one is allowed after at least 24 hours.  Three posts in 5 minutes with no other replies without eding is usually what most moderators and admins get frustrated about.

Ahhh, I gotcha. I'll keep bampin' to a minimum then. Other than that, thanks again! What name or title do ya want to be credited as in the game?
Title: Re: (RESOLVED) [XP] Extremely simple hud fix needed
Post by: Heretic86 on November 11, 2013, 08:31:00 AM
Typically Heretic86 or Heretic, either works fine for me.
Title: Re: (RESOLVED) [XP] Extremely simple hud fix needed
Post by: UltimaZix on November 11, 2013, 08:59:05 AM
Typically Heretic86 or Heretic, either works fine for me.

You got it dood, thanks a bundle c: Screenshots for the game will be up soon too, I'll shoot ya a message when they're ready