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.

Disappearing Bars

Hi, this is my first time posting in this section.
I'm using a hp/sp bar system that displays on the map in a HUD. This is the script I'm using at the moment. It's by Slipknot and was posted a long time ago, before the hack, so I didn't want to go necroposting something that hasn't been touched in nearly a year. The original is here.. http://www.rmxp.org/forums/showthread.php?t=2384&page=2
I've edited slightly to meet my needs but I'm having a problem with teleportation on maps. When I teleport the bars disappear and wont return until I've entered the menu and exited it again.
Here's the edited script..
Code:
#==============================================================================
# ** HP & SP Bars on Map
#------------------------------------------------------------------------------
# Slipknot
# 1.0
# 05.23.06
#==============================================================================

#------------------------------------------------------------------------------
# SDK Log
#------------------------------------------------------------------------------
SDK.log('HP & SP Bars on Map', 'Slipknot', 1.0, '05.23.06')

#------------------------------------------------------------------------------
# Begin SDK Enabled Check
#------------------------------------------------------------------------------
if SDK.state('HP & SP Bars on Map') == true

module MapBars_Settings
 #--------------------------------------------------------------------------
 HPBar = true
 #--------------------------------------------------------------------------
 SPBar = true
 #--------------------------------------------------------------------------
 LevelText = 'Level: '
 #--------------------------------------------------------------------------
 AllowChange = true
 #--------------------------------------------------------------------------
end

#------------------------------------------------------------------------------
# Begin Scene_Map Edit
#------------------------------------------------------------------------------
class Scene_Map
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader(:sprite_bars)
 #--------------------------------------------------------------------------
 # * Alias
 #--------------------------------------------------------------------------
 alias slipknot_mapbars_maindraw main_draw
 alias slipknot_mapbars_updgraphics update_graphics
 alias slipknot_mapbars_maindispose main_dispose
 #--------------------------------------------------------------------------
 # * Main Draw
 #--------------------------------------------------------------------------
 def main_draw
   slipknot_mapbars_maindraw
   @sprite_bars = Sprite_Bars.new
 end
 #--------------------------------------------------------------------------
 # * Main Dispose
 #--------------------------------------------------------------------------
 def main_dispose
   slipknot_mapbars_maindispose
   @sprite_bars.dispose
 end
 #--------------------------------------------------------------------------
 # * Update Graphics
 #--------------------------------------------------------------------------
 def update_graphics
   slipknot_mapbars_updgraphics
   @sprite_bars.update
 end
end
#------------------------------------------------------------------------------
# End Scene_Map Edit
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Begin Interpreter Edit
#------------------------------------------------------------------------------
class Interpreter
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader(:hp_bar, :sp_bar, :bars_index)
 attr_accessor(:bars_need_refresh)
 #--------------------------------------------------------------------------
 # * Alias
 #--------------------------------------------------------------------------
 alias slipknot_mapbars_initialize initialize
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize(depth = 0, main = false)
   slipknot_mapbars_initialize(depth, main)
   if main
     @bars_need_refresh = true
     @hp_bar = MapBars_Settings::HPBar
     @sp_bar = MapBars_Settings::SPBar
     @bars_index = 0
   end
 end
 #--------------------------------------------------------------------------
 # * Bar's Actor Index
 #--------------------------------------------------------------------------
 def bars_index=(index)
   if @bars_index != index
     @bars_index = index
     @bars_need_refresh = true
   end
   return true
 end
 def set_bars_index(index = 0)
   self.bars_index = (index)
 end
 #--------------------------------------------------------------------------
 # * Show HP Bar
 #--------------------------------------------------------------------------
 def show_hp_bar(value = true)
   @hp_bar = value
   @bars_need_refresh = true
 end
 #--------------------------------------------------------------------------
 # * Show SP Bar
 #--------------------------------------------------------------------------
 def show_sp_bar(value = true)
   @sp_bar = value
   @bars_need_refresh = true
 end
end
#------------------------------------------------------------------------------
# End Interpreter Edit
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Begin Spriteset_Map Edit
#------------------------------------------------------------------------------
class Spriteset_Map
 #--------------------------------------------------------------------------
 # * Alias
 #--------------------------------------------------------------------------
 alias slipknot_mapbars_updpicturesprites update_picture_sprites
 #--------------------------------------------------------------------------
 # * Update Picture Sprites
 #--------------------------------------------------------------------------
 def update_picture_sprites
   @timer_sprite.x = ($game_system.map_interpreter.sp_bar ||
     $game_system.map_interpreter.sp_bar) ? 400 : 552
   slipknot_mapbars_updpicturesprites
 end
end
#------------------------------------------------------------------------------
# End Spriteset_Map Edit
#------------------------------------------------------------------------------

class Sprite_Bars < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   @sprite = Sprite.new()
   @sprite.bitmap = Bitmap.new(144, 82)
   @sprite.x = 8
   @sprite.y = -20
   @old_hp = @old_sp = false
   interpreter.bars_need_refresh = true
   update
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   if ! hp? && ! sp?
     bitmap.clear
     return
   end
   if MapBars_Settings::AllowChange && Input.press?(11)
     if Input.repeat?(Input::L)
       interpreter.bars_index = (interpreter.bars_index - 1) % $game_party.actors.size
     end
     if Input.repeat?(Input::R)
       interpreter.bars_index = (interpreter.bars_index + 1) % $game_party.actors.size
     end
   end
   actor = $game_party.actors[interpreter.bars_index]
   if need_refresh?
     bitmap.clear
     lvt = MapBars_Settings::LevelText + actor.level.to_s
     width = bitmap.text_size(lvt).width

   end  
   if hp? && (need_refresh? || @old_hp != actor.hp)
     draw_hp_bar(actor, 0, 22)
     @old_hp = actor.hp
     hp = true
   end
   if sp? && (need_refresh? || @old_sp != actor.sp)
     y = hp != nil ? 30 : 0
     draw_sp_bar(actor, 0, y + 14)
     @old_sp = actor.sp
   end
   interpreter.bars_need_refresh = false
 end
 #--------------------------------------------------------------------------
 # * @sprite.bitmap & $game_system.map_interpreter
 #--------------------------------------------------------------------------
 def bitmap
   @sprite.bitmap
 end
 def interpreter
   $game_system.map_interpreter
 end
 #--------------------------------------------------------------------------
 # * Return Interpreter Variables
 #--------------------------------------------------------------------------
 def need_refresh?
   interpreter.bars_need_refresh
 end
 def hp?
   interpreter.hp_bar
 end
 def sp?
   interpreter.sp_bar
 end
 
 #--------------------------------------------------------------------------
 # * Draw HP Bar
 #--------------------------------------------------------------------------
 def draw_hp_bar(actor, x, y)
   bitmap.fill_rect(x, y, 144, 10, Color.new(0, 0, 0, 0))
   bitmap.fill_rect(x, y + 14, 112, 6, Color.new(0, 0, 0))
   width = 112.0 * actor.hp / actor.maxhp
   red = 144.0
   step = 80.0 / (width - 2).to_f
   for p in 0...(width - 2)
     bitmap.fill_rect(x + p + 1, y + 15, 1, 4, Color.new(red, 64, 32))
     red += step
   end
 end
 #--------------------------------------------------------------------------
 # * Draw SP Bar
 #--------------------------------------------------------------------------
 def draw_sp_bar(actor, x, y)
   bitmap.fill_rect(x, y, 144, 10, Color.new(0, 0, 0, 0))
   bitmap.fill_rect(x, y + 14, 112, 6, Color.new(0, 0, 0))
   width = 112.0 * actor.sp / actor.maxsp
   blue = 144.0
   step = 80.0 / (width - 2).to_f
   for p in 0...(width - 2)
     bitmap.fill_rect(x + p + 1, y + 15, 1, 4, Color.new(32, 64, blue))
     blue += step
   end
 end
 #--------------------------------------------------------------------------
 # * Draw Outline Text
 #--------------------------------------------------------------------------
 def draw_text(x, y, width, height, string, align = 0)
   col = bitmap.font.color.dup
   bitmap.font.color = Color.new(32, 32, 32, col.alpha)
   bitmap.draw_text(x - 1, y, width, height, string, align)
   bitmap.draw_text(x, y - 1, width, height, string, align)
   bitmap.draw_text(x + 1, y, width, height, string, align)
   bitmap.draw_text(x, y + 1, width, height, string, align)
   bitmap.font.color = col
   bitmap.draw_text(x, y, width, height, string, align)
 end
end
#--------------------------------------------------------------------------
 # * Dispose
 #--------------------------------------------------------------------------
 def dispose
   @sprite.dispose
   bitmap.dispose
 end

#------------------------------------------------------------------------------
# End SDK Enabled Test
#------------------------------------------------------------------------------
end
I don't know what's wrong with it or if I've done something to it to make it do this. I'm also using Ccoas UMS, Caldarons 1 Hero CMS, Prexcraft, Selwyns Minimap and Lambchops Intro Screen. I'm hoping these other scripts aren't causing conflict because it's taken me a little while to get them to work together.
Another problem I'm having is with displaying variables set by events in the menu. I want to display a variable ([0001]) where the Steps section would be saying "Coins: x/100" where the x is the variable but I cant get it to display.
I have this so far..
Code:
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(0, 0, 64, 32, "Coins")
    self.contents.font.color = normal_color
    self.contents.draw_text(64, 0, 144, 32, "/100" )
  end
..where it says "/100" I want it to display the contents of Variable [0001] before it.
Thanks to anyone who can help me with these problems.
 
Yeah, thats what I figured since they re-appear after exiting the menu, but I'm not really a scripter I'm just editing them to my basic needs and I can't figure out how to add an update after transferring player :/
 

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