Hi guys, it's the first message of mine in this forum.
Recently I made a hud script that shows infos (hp, mp, exp, avatar, name etc.) while in the map.
The problem is I'm not a scripter, I'm a pixelartist, and I can't make my hud to change hp/mp/exp when a decrease hp/mp event or an enemy attack occurs in the map (I'm using an ABS).
The following is the main hud script:
# Hud principale
class Finestra_Mappa < Window_Base
def initialize
super(-10, -10, 670, 140)
self.contents = Bitmap.new( width - 32, height - 32)
self.opacity = 0
self.contents.font.name = "Arial"
self.contents.font.size = 16
$eroe = $game_party.actors[0]
refresh
end
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.draw_actor_hp($eroe, 135,0, width = 488)
self.draw_actor_sp($eroe, 135,42, width = 488)
self.draw_actor_exp($eroe, 135, 50, width = 488)
self.draw_pix("hud.png", 30-10, 117)
if $eroe.name = "Kelly"
self.draw_pix("kelly name+avatar.png", 30-10, 117)
end
update
end
def update
super
end
end
And in Scene_Map I added two lines:
class Scene_Map
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make sprite set
@spriteset = Spriteset_Map.new
# Make message window
@message_window = Window_Message.new
#------------ Finestra ---------------------#
@message_finestra = Finestra_Mappa.new
# Transition run
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
[...]
And:
[...]
# Prepare for transition
Graphics.freeze
# Dispose of sprite set
@spriteset.dispose
# Dispose of message window
@message_window.dispose
#------------ Finestra ---------------------#
@message_finestra.dispose
# If switching to title screen
if $scene.is_a?(Scene_Title)
# Fade out screen
Graphics.transition
Graphics.freeze
end
end
[...]
Anyone know how to refresh my hud everytime stats changes?
Also: a screenshot
(http://i734.photobucket.com/albums/ww349/asukicco/hudingame.png)
In class Finestra_Mappa, in the update method...
You need to have it call the refresh method there.
But... you also need to add conditions or it'd refresh every frame (which is bad)
So add conditions to see if the hp/mp/etc changed, then call refresh.
also that is one badass hud
Quote from: Aqua on February 13, 2010, 04:47:28 pm
In class Finestra_Mappa, in the update method...
You need to have it call the refresh method there.
But... you also need to add conditions or it'd refresh every frame (which is bad)
So add conditions to see if the hp/mp/etc changed, then call refresh.
Wow, 2 replies in a couple of minutes! : D
Aqua, thank you for the comment... if I'm wrong please let me know:
I have to store current hp/mp/exp on a variable, and then put a series of ifelse under def refresh method to check if the stored hp/mp/exp is different from the current one. If true, I have to call refresh method one more time?
Could you be more specific, maybe with examples or something? Thank you aqua.
@Ryexander: Thank you, if you are interested you can check my other pieces here: http://pixeljoint.com/pixels/profile.asp
You do not have to store HP/MP/EXP in a variable. Instead, use:
$game_actors[id].hp
$game_actors[id].sp
$game_actors[id].exp
... respectively. Also, replace "id" with the actors id. (ex. 1 for Arshes)
but he has to check if they have changed so
(in init)
@hp = $game_actors[id].hp
(in refresh)
if @hp != $game_actors[id].hp
hud_refresh
end
@hp = $game_actors[id].hp
Ah, my bad. I thought they meant game variables. Sorry about that. :^_^':
Ok, this is what I got so far:
# Hud principale
class Finestra_Mappa < Window_Base
def initialize
super(-10, -10, 670, 140)
self.contents = Bitmap.new( width - 32, height - 32)
self.opacity = 0
self.contents.font.name = "Arial"
self.contents.font.size = 16
$eroe = $game_party.actors[0]
@hud_hp = $eroe.hp # apparently RGSS doesn't accept this syntax: (hud.hp, hud.mp, hud.exp) = ($eroe.hp, $eroe.sp, $eroe.exp)
@hud_mp = $eroe.sp
@hud_exp = $eroe.exp
refresh
end
def refresh
self.contents.clear
self.contents.font.color = normal_color
#self.draw_actor_state($eroe, 30, 60)
#self.draw_actor_level($eroe, 30, 8)
self.draw_actor_hp($eroe, 135,0, width = 488)
self.draw_actor_sp($eroe, 135,42, width = 488)
self.draw_actor_exp($eroe, 135, 50, width = 488)
self.draw_pix("hud.png", 30-10, 117)
if $eroe.name = "Kelly"
self.draw_pix("kelly name+avatar.png", 30-10, 117)
end
if $eroe.hp != @hud_hp or $eroe.sp != @hud_mp or $eroe.exp != @hud_exp
@Finestra_Mappa.refresh
end
@hud_hp = $eroe.hp
@hud_mp = $eroe.sp
@hud_exp = $eroe.exp
update
end
def update
super
end
end
But it doesn't work.
what abs are u using that might help
Try this
# Hud principale
class Finestra_Mappa < Window_Base
def initialize
super(-10, -10, 670, 140)
self.contents = Bitmap.new( width - 32, height - 32)
self.opacity = 0
self.contents.font.name = "Arial"
self.contents.font.size = 16
$eroe = $game_party.actors[0]
@hud_hp = $eroe.hp
@hud_mp = $eroe.sp
@hud_exp = $eroe.exp
refresh
end
def refresh
self.contents.clear
self.contents.font.color = normal_color
#self.draw_actor_state($eroe, 30, 60)
#self.draw_actor_level($eroe, 30, 8)
self.draw_actor_hp($eroe, 135,0, width = 488)
self.draw_actor_sp($eroe, 135,42, width = 488)
self.draw_actor_exp($eroe, 135, 50, width = 488)
self.draw_pix("hud.png", 30-10, 117)
if $eroe.name = "Kelly"
self.draw_pix("kelly name+avatar.png", 30-10, 117)
end
@hud_hp = $eroe.hp
@hud_mp = $eroe.sp
@hud_exp = $eroe.exp
end
def update
if $eroe.hp != @hud_hp || $eroe.sp != @hud_mp || $eroe.exp != @hud_exp
refresh
end
end
end
@Aqua: Thank you, it works like god himself!
@nathmatt: I'm using Blizz-ABS v.2.7
Thank you all for comments, the problem has been resolved.
Then you can actually use $game_player.battler instead of $eroe. :)
Quote from: Blizzard on February 14, 2010, 06:20:46 am
Then you can actually use $game_player.battler instead of $eroe. :)
I'm using $eroe for short.
Also, are you THAT Blizzard?
Yes, I'm THAT Blizzard. xD Welcome to my forum. :D
tell me how this works for you did the best i can with what info you gave
edit please add (resolved) to your topics name
#==============================================================================
# Hud
#------------------------------------------------------------------------------
# This class was modified to support SR display and modify the number of
# skills left to use.
#==============================================================================
class Hud < Sprite
#----------------------------------------------------------------------------
# Initialization
# viewport - the viewport for the sprite
#----------------------------------------------------------------------------
def initialize(viewport = nil)
# call superclass method
super
# create positions
create_positions
# get height
h = BlizzABS::Config::DIRECT_HOTKEYS ? @hud_height - 28 : @hud_height
# create bitmap
self.bitmap = Bitmap.new(@hud_width, h)
# set font
self.bitmap.font.name = 'Arial'
# set font size
self.bitmap.font.size = 16
# set font to bold
self.bitmap.font.bold = true
# set x, y position
self.x, self.y = -10, -10
# set z coordinate
self.z = 1000
# draw basic HUD
draw_basic
# update
update
end
#----------------------------------------------------------------------------
# create_positions
# Sets drawing positions. This method can be aliased and the positions
# modified to create a different HUD.
#----------------------------------------------------------------------------
def create_positions
@original_width = @hud_width = 670
@original_height = @hud_height = 140
end
#----------------------------------------------------------------------------
# draw_basic
# Draws the HUD template.
#----------------------------------------------------------------------------
def draw_basic
# fill with grey rectangle
self.bitmap.fill_rect(0, 0, self.bitmap.width, self.bitmap.height,
Color.new(0, 0, 0, 0))
# determine color depending on HUD style
color = Color.new(0, 0, 0, 0)
end
#----------------------------------------------------------------------------
# draw_hp
# Draws the HP display.
#----------------------------------------------------------------------------
def draw_hp
# set current variables
@hp, @maxhp = actor.hp, actor.maxhp
# remove old display
self.bitmap.fill_rect(135 ,0, 488, 32, Color.new(0, 0, 0, 0))
# draw gradient bar
self.draw_actor_hp(actor, 135,0, width = 488)
end
#----------------------------------------------------------------------------
# draw_sp
# Draws the SP display.
#----------------------------------------------------------------------------
def draw_sp
# set current variables
@sp, @maxsp = actor.sp, actor.maxsp
# remove old display
self.bitmap.fill_rect(135 ,42, 488, 32, Color.new(0, 0, 0, 0))
# draw gradient bar
self.draw_actor_sp(actor, 135,42, width = 488)
end
#----------------------------------------------------------------------------
# draw_exp
# Draws the EXP display.
#----------------------------------------------------------------------------
def draw_exp
# set current variables
@now_exp, @next_exp = actor.now_exp, actor.next_exp
# remove old display
self.bitmap.fill_rect(135 ,50, 488, 32, Color.new(0, 0, 0, 0))
# draw gradient bar
self.draw_actor_exp(actor, 135, 50, width = 488)
end
#----------------------------------------------------------------------------
# draw_hp
# Draws the HP display.
#----------------------------------------------------------------------------
def draw_graphic
# set current variables
@name = actor.name
# remove old display
self.bitmap.fill_rect(20 ,117, 100, 100, Color.new(0, 0, 0, 0))
# load bitmap
bitmap = RPG::Cache.picture(@name+'avatar')
s# draw bitmap
self.bitmap.blt(@face_x, @face_y, bitmap, Rect.new(20, 117, 670, 140))
end
end
#----------------------------------------------------------------------------
# update
# Checks if HUD needs refreshing.
#----------------------------------------------------------------------------
def update
# if actor doesn't exist
if actor == nil
# unless already drawn empty HUD
unless @empty_hud_drawn
# draw HUD template
draw_basic
# empty HUD was drawn
@empty_hud_drawn = true
end
else
# if HUD needs refresh
if $game_temp.hud_refresh
# draw all data about actor
draw_graphic
draw_hp
draw_sp
draw_exp
# remove flag
$game_temp.hud_refresh = nil
else
# draw data that needs to ve updated
test_graphic
test_hp
test_sp
test_exp
end
# empty HUD wasn't drawn
@empty_hud_drawn = false
end
end
#----------------------------------------------------------------------------
# test_hp
# Tests and draws the HP.
#----------------------------------------------------------------------------
def test_hp
# draw new HP if HP or max HP have changed
draw_hp if actor.hp != @hp || actor.maxhp != @maxhp
end
#----------------------------------------------------------------------------
# test_sp
# Tests and draws the SP.
#----------------------------------------------------------------------------
def test_sp
# draw new SP if SP or max SP have changed
draw_sp if actor.sp != @sp || actor.maxsp != @maxsp
end
#----------------------------------------------------------------------------
# test_exp
# Tests and draws the EXP.
#----------------------------------------------------------------------------
def test_exp
# draw new EXP if EXP or NEXT_EXP have changed
draw_exp if actor.now_exp != @now_exp || actor.next_exp != @next_exp
end
#----------------------------------------------------------------------------
# test_exp
# Tests and draws the EXP.
#----------------------------------------------------------------------------
def test_graphic
# draw new GRAPHIC if NAME has changed
draw_graphic if actor.name != @name
end
#----------------------------------------------------------------------------
# actor
# Returns the party leader's battler for easier reference.
#----------------------------------------------------------------------------
def actor
return $game_player.battler
end
end
#==============================================================================
# Game_Actor
#==============================================================================
class Game_Actor
#----------------------------------------------------------------------------
# now_exp
# Returns the EXP collected in this level.
#----------------------------------------------------------------------------
def now_exp
return @exp - @exp_list[@level]
end
#----------------------------------------------------------------------------
# next_exp
# Returns the EXP needed to level up as number.
#----------------------------------------------------------------------------
def next_exp
return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
end
end
#==============================================================================
# Hotkey_Assignment
#------------------------------------------------------------------------------
# This class creates and display currently assigned hotkeys and is more
# effiecient than the Window class.
#==============================================================================
class Hotkey_Assignment < Sprite
#----------------------------------------------------------------------------
# Initialization
# viewport - the viewport for the sprite
#----------------------------------------------------------------------------
def initialize(viewport = nil)
# call superclass
super
# create bitmap
self.bitmap = Bitmap.new(320, 32)
# set font to bold
self.bitmap.font.bold = true
# decrease font size
self.bitmap.font.size -= 8
# set font color
self.bitmap.font.color = system_color
# set x and y position
self.x, self.y, self.z = 160, 445, 1100
# skill IDs on hotkeys
@skills = BlizzABS::Cache::EmptyKeys
# item IDs on hotkeys
@items = BlizzABS::Cache::EmptyKeys
# update display
update
end
end
QuoteThank you all for comments, the problem has been resolved.
think aqua already solved the problem
Nath... this wasn't a request topic... o.o