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.

[Resolve]d I have a HUD, I want a switch :D

Status
Not open for further replies.
Yeah, the topic title barely explains anything. I just wanted it to be kind of funny (Laugh at my stupid sense of humor, lol). Now, let me explain what I want.

I found this AWESOME hud, that makes gradients, and other cool stuff without using a single picture. Unfortunately, it doesn't have a switch which can turn it ON and OFF at will.

Therefore, can somebody edit this script and make it work depending on a switch.

This the script (SMF doesn't have spoilers.. :-\)
Code:
#-----------------------------------------------------------------
class Scene_Map
#-----------------------------------------------------------------
  alias sk_bar_main main
  def main
    @bars = Window_Sk_Bars.new
    sk_bar_main
    @bars.dispose if @bars != nil
  end
#-----------------------------------------------------------------
  alias sk_bar_update update
  def update
    @bars.update
    sk_bar_update
  end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Base < Window
#-----------------------------------------------------------------
  def sk_initialize(font=0,size=22)
    font = "Tahoma" if font == 0
    self.contents = Bitmap.new(self.width-32,self.height-32)
    self.contents.font.name = font
    self.contents.font.size = size
  end
#-----------------------------------------------------------------
  def draw_text_outline(x,y,w,h,str,c=normal_color,a=0)
    self.contents.font.color = Color.new(0,0,0,255)
    self.contents.draw_text(x-1,y,w,h,str,a)
    self.contents.draw_text(x+1,y,w,h,str,a)
    self.contents.draw_text(x,y+1,w,h,str,a)
    self.contents.draw_text(x,y-1,w,h,str,a)
    self.contents.font.color = c
    self.contents.draw_text(x,y,w,h,str,a)
  end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Sk_Bars < Window_Base
#-----------------------------------------------------------------
  def initialize
    super(444,-8,206,96)
    sk_initialize("Arial")
    self.opacity = 0
  end
#-----------------------------------------------------------------
  def update
    self.contents.clear
    actor = $game_party.actors[0]
    draw_text_outline(0,-4,64,26,"HP")
    draw_actor_hp(actor,30,0)
  end
#-----------------------------------------------------------------
  def draw_actor_hp(actor,x,y)
    width = 128
    y += 4
    white = Color.new(255,255,255,255)
    black = Color.new(0,0,0,255)
    w = width * actor.hp / actor.maxhp
    # White border
    self.contents.fill_rect(x+1, y-1, width-2, 1, white)
    self.contents.fill_rect(x, y, width, 1, white)
    self.contents.fill_rect(x-1, y+1, width+2, 9, white)
    self.contents.fill_rect(x, y+10, width, 1, white)
    self.contents.fill_rect(x+1, y+11, width-2, 1, white)
    # Black back
    self.contents.fill_rect(x+2, y, width-4, 1, black)
    self.contents.fill_rect(x+1, y+1, width-2, 1, black)
    self.contents.fill_rect(x, y+2, width, 7, black)
    self.contents.fill_rect(x+1, y+9, width-2, 1, black)
    self.contents.fill_rect(x+2, y+10, width-4, 1, black)
    # Generating the color
    val = 255 * ((actor.hp*100)/actor.maxhp)
    green = 255 - val/100
    color = Color.new(224,green,0,255)
    w_color = Color.new(255,green+32,96,255)
    if green > 64 then green -= 32
    elsif green > 128 then green -= 64 end
    b_color = Color.new(172,green,0,255)
    # Making the bar
    self.contents.fill_rect(x+2, y, w-4, 1, w_color)
    self.contents.fill_rect(x+1, y+1, w-2, 1, w_color)
    self.contents.fill_rect(x, y+2, w, 7, color)
    self.contents.fill_rect(x+1, y+9, w-2, 1, color)
    self.contents.fill_rect(x+2, y+10, w-4, 1, b_color)
  end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------

Thanks to anyone who can do this for me!  ;)
 
You can replace:

Code:
  def update
    self.contents.clear
    actor = $game_party.actors[0]
    draw_text_outline(0,-4,64,26,"HP")
    draw_actor_hp(actor,30,0)
  end

with

Code:
  def update
    self.contents.clear
    if $game_switches[<insert the switch number here>]
      actor = $game_party.actors[0]
      draw_text_outline(0,-4,64,26,"HP")
      draw_actor_hp(actor,30,0)
    end
  end
 
no charlie.lee, that will only remove the content.

above the following line:
Code:
@bars.update
put this line, where switch_id is the number of the switch.
Code:
@bars.visible = $game_switches[switch_id]
 
Freakboy":1cugrr3e said:
no charlie.lee, that will only remove the content.

above the following line:
Code:
@bars.update
put this line, where switch_id is the number of the switch.
Code:
@bars.visible = $game_switches[switch_id]

This has been done on purpose. This window is supposed to use a transparent skin (self.opacity=0), so if you remove the contents, nothing will be displayed. Moreover with my code you don't waste time processing data for a not visible window.
 
Thanks everyone. I have yet to try it out, but since charlie.lee has posted this, it will probably work (great scripters like him don't usually make mistakes  :D)

Once again, thanks everyone, you guys have really been of a great help to me  ;)

EDIT: It works! Thanks everybody!  ;D
 
Status
Not open for further replies.

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