The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Demon X on November 24, 2006, 02:33:04 AM

Title: A nice, clean, translucent HUD
Post by: Demon X on November 24, 2006, 02:33:04 AM
Here is a clean and translucent HUD script:
Code: [Select]
#==============================================================================
# ** Game_Actor
# Script by MeisMe
# Graphics added by Peaches
# Icons made by Joshie666 & Axerax
#------------------------------------------------------------------------------
# This class handles the actor. It's used within the Game_Actors class
# ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================
class Game_Actor
#--------------------------------------------------------------------------
# * Get the current EXP
#--------------------------------------------------------------------------
def now_exp
return @exp - @exp_list[@level]
end
#--------------------------------------------------------------------------
# * Get the next level's EXP
#--------------------------------------------------------------------------
def next_exp
return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
end
end

#==============================================================================
# ** Window_HUD
#------------------------------------------------------------------------------
# This class is used to display HP, SP and Gold on the map.
#==============================================================================
class Window_HUD < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(-16, -16, 672, 150)
self.contents = Bitmap.new(width-32, height-32)
self.opacity = 0
self.contents.font.size = 14
self.contents.font.name = "Arial"
@actors = []
@old_hp = []
@old_sp = []
@old_exp = []
@old_level = []
for i in 0...$game_party.actors.size
@actors.push($game_party.actors[i])
@old_hp.push(@actors[i].hp)
@old_sp.push(@actors[i].sp)
@old_exp.push(@actors[i].now_exp)
@old_level.push(@actors[i].level)
end
@old_gold = $game_party.gold
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
#self.contents.draw_text(6, 0, 32, 14, $data_system.words.hp + "")
#self.contents.draw_text(6, 14, 32, 14, $data_system.words.sp + "")
self.contents.draw_text(6, 28, 32, 14, "")
#self.contents.draw_text(6, 42, 32, 14, $data_system.words.gold + "")
self.contents.font.color = normal_color
#Images

case @actors.size
when 1
bitmap = RPG::Cache.picture("HUD Graphic")
self.contents.blt(0, 0, bitmap, Rect.new(0, 10, 500, 500))
when 2
bitmap = RPG::Cache.picture("HUD Graphic2")
self.contents.blt(0, 0, bitmap, Rect.new(0, 10, 500, 500))
when 3
bitmap = RPG::Cache.picture("HUD Graphic2")
self.contents.blt(0, 0, bitmap, Rect.new(0, 10, 500, 500))
when 4
bitmap = RPG::Cache.picture("HUD Graphic3")
self.contents.blt(0, 0, bitmap, Rect.new(0, 10, 640, 500))
when 5
bitmap = RPG::Cache.picture("HUD Graphic3")
self.contents.blt(0, 0, bitmap, Rect.new(0, 10, 640, 500))
end

#bitmap = RPG::Cache.picture("HUD Graphic")
#self.contents.blt(0, 0, bitmap, Rect.new(0, 10, 500, 500))
bitmap = RPG::Cache.icon("HP Symbol")
self.contents.blt(3, 10, bitmap, Rect.new(0, 0, 24, 24))
bitmap = RPG::Cache.icon("SP Symbol")
self.contents.blt(3, 30, bitmap, Rect.new(0, 0, 24, 24))
bitmap = RPG::Cache.icon("EXP Symbol")
self.contents.blt(3, 50, bitmap, Rect.new(0, 0, 24, 24))
bitmap = RPG::Cache.icon("Hero")
self.contents.blt(25, 67, bitmap, Rect.new(0, 0, 24, 24))

if $game_switches[99] == true
if $game_variables[99] == 0
self.contents.draw_text(x, y, 210, 14, $game_party.item_number[1])
elsif $game_variables[8] == 1
  self.contents.draw_text(x, y, 210, 14, $game_party.item_number(2))
elsif $game_variables[8] ==2
  self.contents.draw_text(x, y, 110, 14, @actors[i].name)
end
end
x = 32
for i in 0...@actors.size
y = 6
self.contents.draw_text(x, y, 110, 14, @actors[i].name)
self.contents.draw_text(x, y, 110, 14, "Lv: #{@actors[i].level}", 2)
y += 16
draw_hp_bar(@actors[i], x, y, 112, 5)
y += 19
draw_sp_bar(@actors[i], x, y, 104, 5)
y += 19
draw_exp_bar(@actors[i], x, y, 88, 5)
y += 19
x += 130
end
x = 32
self.contents.draw_text(45, 73, 110, 14, $game_party.gold.to_s)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if @actors.size != $game_party.actors.size
@actors = []
for i in 0...$game_party.actors.size
@actors.push($game_party.actors[i])
end
refresh
return
end
for i in 0...@actors.size
if @old_hp[i] != @actors[i].hp or
@old_sp[i] != @actors[i].sp or
@old_exp[i] != @actors[i].now_exp or
@old_level[i] != @actors[i].level or
@old_gold != $game_party.gold
refresh
@old_hp[i] = @actors[i].hp
@old_sp[i] = @actors[i].sp
@old_exp[i] = @actors[i].now_exp
@old_level[i] = @actors[i].level
@old_gold = $game_party.gold
end
end
end
#--------------------------------------------------------------------------
# * Draw HP Bar
#--------------------------------------------------------------------------
def draw_hp_bar(actor, x, y, length, thick)
width = length
height = thick
c1 = Color.new(255, 0, 0)
c2 = Color.new(155, 0, 0)
e1 = actor.hp
e2 = actor.maxhp
self.contents.fill_rect(x-1, y - 1, width+2, height + 3, Color.new(255, 255, 255, 255))
self.contents.fill_rect(x, y, width, height + 1, Color.new(0, 0, 0, 255))
w = width * e1 / e2
for i in 0..height
r = c1.red + (c2.red - c1.red) * (height -i)/height + 0 * i/height
g = c1.green + (c2.green - c1.green) * (height -i)/height + 0 * i/height
b = c1.blue + (c2.blue - c1.blue) * (height -i)/height + 0 * i/height
a = c1.alpha + (c2.alpha - c1.alpha)* (height -i)/height + 255 * i/height
self.contents.fill_rect(x, y+i, w, 1, Color.new(r, g, b, a))
end
end
#--------------------------------------------------------------------------
# * Draw SP Bar
#--------------------------------------------------------------------------
def draw_sp_bar(actor, x, y, length, thick)
width = length
height = thick
c1 = Color.new(0, 0, 255)
c2 = Color.new(0, 0, 155)
e1 = actor.sp
e2 = actor.maxsp
self.contents.fill_rect(x-1, y - 1, width+2, height + 3, Color.new(255, 255, 255))
self.contents.fill_rect(x, y, width, height + 1, Color.new(0, 0, 0))
w = width * e1 / e2
for i in 0..height
r = c1.red + (c2.red - c1.red) * (height -i)/height + 0 * i/height
g = c1.green + (c2.green - c1.green) * (height -i)/height + 0 * i/height
b = c1.blue + (c2.blue - c1.blue) * (height -i)/height + 0 * i/height
a = c1.alpha + (c2.alpha - c1.alpha)* (height -i)/height + 255 * i/height
self.contents.fill_rect(x, y+i, w, 1, Color.new(r, g, b, a))
end
end
#--------------------------------------------------------------------------
# * Draw EXP Bar
#--------------------------------------------------------------------------
def draw_exp_bar(actor, x, y, length, thick)
width = length
height = thick
c1 = Color.new(158, 208, 9)
c2 = Color.new(58, 108, 0)
e1 = actor.now_exp
e2 = actor.next_exp
if actor.next_exp == 0
e1 = 1
e2 = 1
end
self.contents.fill_rect(x-1, y - 1, width+2, height + 3, Color.new(255, 255, 255, 255))
self.contents.fill_rect(x, y, width, height + 1, Color.new(0, 0, 0, 255))
w = width * e1 / e2
for i in 0..height
r = c1.red + (c2.red - c1.red) * (height -i)/height + 0 * i/height
g = c1.green + (c2.green - c1.green) * (height -i)/height + 0 * i/height
b = c1.blue + (c2.blue - c1.blue) * (height -i)/height + 0 * i/height
a = c1.alpha + (c2.alpha - c1.alpha)* (height -i)/height + 255 * i/height
self.contents.fill_rect(x, y+i, w, 1, Color.new(r, g, b, a))
end
end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Object Aliasing
#--------------------------------------------------------------------------
alias hud_scene_map_main main
alias hud_scene_map_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def main
@HUD = Window_HUD.new
hud_scene_map_main
@HUD.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
@HUD.update
hud_scene_map_update
end
end

You will need to put the following images into the Pictures folder:

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg317.imageshack.us%2Fimg317%2F24%2Fhudgraphic1yz5.png&hash=eb90616833ab2bb562e12be9867ee9b2ac5b637b)
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg374.imageshack.us%2Fimg374%2F7384%2Fhudgraphic2ko8.png&hash=4c68464b2a7031bff1d30590894c41b9e9c17df7)
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg389.imageshack.us%2Fimg389%2F475%2Fhudgraphic3fz9.png&hash=c592783945a50a862b78e01894045e48f028e400)
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg374.imageshack.us%2Fimg374%2F5445%2Fhudgraphicbp1.png&hash=3452e6d9682c5bfcc88ca3dbbc62ae2b367a4816)

And you will need to put these in your Icons folder:

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg317.imageshack.us%2Fimg317%2F5509%2Fhpsymbolyg8.png&hash=e7157df2638b1778160fa02ca7d108c36f98cdd1)
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg374.imageshack.us%2Fimg374%2F61%2Fspsymboltm7.png&hash=6adf2c21ba0cd8fe7bfb66ce1a39d6be84edf343)
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg389.imageshack.us%2Fimg389%2F4991%2Fexpsymbolmv7.png&hash=e0838da5fafabb6e85eb97a722e33683286d0af2)
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg389.imageshack.us%2Fimg389%2F4738%2Fherori4.png&hash=ba9ce6cba0f5d9fdf5a3df304f320359a2c53e89)

Credit goes to Axerax, not me!
Title: Re: A nice, clean, translucent HUD
Post by: Falcon on November 24, 2006, 03:46:02 PM
Credit also goes to:
 Script by MeisMe
 Graphics added by Peaches
 Icons made by Joshie666 & Axerax
Title: Re: A nice, clean, translucent HUD
Post by: coolkid25344 on November 25, 2006, 08:11:37 PM
Its good, is there an option to hide the window if you want?, because it gets in the way sometimes
Title: Re: A nice, clean, translucent HUD
Post by: &&&&&&&&&&&&& on November 25, 2006, 08:20:00 PM
what is a HUD?
... I mean I kinda know what it is but... aren't zelda typ games hard to make?
Title: Re: A nice, clean, translucent HUD
Post by: Bloods the Hedgehog on November 26, 2006, 05:09:34 AM
A HUD ( Heads up Display ) is something that shows status, that can be Health, Magic, Mana, Gold, or Experience, or something.

[ - x - Bloods - x - ]
Title: Re: A nice, clean, translucent HUD
Post by: Winged on November 26, 2006, 06:09:50 AM
Wow, from what I've seen, it looks impressive. Thanks for sharing  :)

~Winged
Title: Re: A nice, clean, translucent HUD
Post by: kypep on January 04, 2007, 03:46:55 PM
hey? can we get a screeny? i like to see it so i know what to look for?
Title: Re: A nice, clean, translucent HUD
Post by: Irock on January 10, 2007, 01:12:23 AM
How would I go about hideing it?
Title: Re: A nice, clean, translucent HUD
Post by: Blizzard on January 10, 2007, 11:24:39 AM
Code: [Select]
class Scene_Map

  alias upd_disable_hud_later update
  def update
    @HUD.visible = $game_switches[X]
    upd_disable_hud_later
  end

end

Change X to a switch ID. Turn the switch on to make it visible, turn it off to make it invisible.
Title: Re: A nice, clean, translucent HUD
Post by: pliio8 on January 13, 2007, 11:13:13 PM
Okay...can I get some help? It won't work, any kind of demo maybe?
Title: Re: A nice, clean, translucent HUD
Post by: Wolfwood on March 01, 2007, 12:46:30 PM
I'm sorry dude but this one is BAD. I needed to fix images' names and check em from the code. Same went with the icons. The filenames are wrong. Finally I tested it without errors. It looked ok, but when I started battle, got error again. Fix the script, then its ok!
Title: Re: A nice, clean, translucent HUD
Post by: Blizzard on March 01, 2007, 12:47:59 PM
Imageshack renames pictures, you need to remove the last 3 characters from each filename. Maybe it's that.
Title: Re: A nice, clean, translucent HUD
Post by: Arrow on March 01, 2007, 01:39:01 PM
Yeah, when I first found this a gamebaker I had to do that as well.
Title: Re: A nice, clean, translucent HUD
Post by: Wolfwood on March 01, 2007, 05:11:22 PM
no, it wasnt just last characters.. I needed to replace the HOLE NAMES, and dunno why got error when I entered battle :P
Title: Re: A nice, clean, translucent HUD
Post by: digital_ninja2k on April 21, 2007, 07:56:04 PM
I don't know if this has been figure out yet but the last three letters of the title have to be deleted AND you have to change the graphics and Icon names to the following:

hud graphic.png
hud graphic1.png
hud graphic2.png
hud graphic3.png

exp symbol.png
hero.png
hp symbol.png
sp symbol.png

Title: Re: A nice, clean, translucent HUD
Post by: Jalkson on April 22, 2007, 03:22:27 AM
Nice work, It worked fine for me.
Title: Re: A nice, clean, translucent HUD
Post by: Neverplayd on June 26, 2007, 05:03:04 AM
ok im having a problem with this script.
The HUD works fine, but it seems to have screwed up my menu.

The error says:
-----------------------------------------------------------------
?????? 'Window_Base' ? 30 ??? RGSSError ????????

disposed window
-----------------------------------------------------------------

I copied the section around line 30

---------------------------------
  def dispose
    if self.contents != nil
      self.contents.dispose
    end
    super
  end
----------------------------------

The menu works fine without the HUD, but I get the error whenever I put the HUD script in.
I'm not using a CMS or anything, but I am using the unlimited lvl script by Cybersam, if that makes a difference.

Can someone help? tx
Title: Re: A nice, clean, translucent HUD
Post by: Yawgmothsbud on July 02, 2007, 04:01:02 AM
Code: [Select]
class Scene_Map

  alias upd_disable_hud_later update
  def update
    @HUD.visible = $game_switches[X]
    upd_disable_hud_later
  end

end

Change X to a switch ID. Turn the switch on to make it visible, turn it off to make it invisible.


Where do you add this?