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.

How-to Display Weapon Names and Icon?

Could someone here please tell me how I can display the party leader's weapon name and icon? Like, I need the syntax to be able to display them.
 

khmp

Sponsor

Code:
weapon = $data_weapons[$game_party.actors[0].weapon_id]
return if weapon.nil?
weapon_name = weapon.name
weapon_icon = RPG::Cache.icon(weapon.icon_name)#Bitmap.new('Graphics/Icons/' + weapon.icon_name)

Assuming you are using this for a window:
Code:
self.contents.blt(x, y, weapon_icon, weapon_icon.rect)
self.contents.draw_text(x + 26, y, width - (32 + 26), 32, weapon_name)
 
I am using it for a HUD, i s that the same thing?
Do you think you could add it into this coding, and I will see what you did? or you could also explain it?

Code:
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# Shifter HUD 
# v 1.0
# Author - Joshua Long
# This HUD is made for Shifter.
#-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
class Scene_Map
  alias jlhud_main main
  alias jlhud_update update
  def main
    @jlhud = Window_hud.new
    jlhud_main
    @jlhud.dispose
  end
  def update
    @jlhud.update
    jlhud_update
  end
end
class Window_hud < Window_Base
  def initialize
    super(-10, -10, 650, 650)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Arial"
    self.contents.font.size = 16
    self.back_opacity = 0
    refresh
  end
  def refresh
    self.contents.clear
    reset_variables
    return if !@actor
    draw_actor_graphic(@actor, 590, 58)
    draw_bar(0, 450, @actor.sp, @actor.maxsp, 90, 8, Color.new(88, 200, 244, 255), Color.new(0, 56, 200, 255))
    self.contents.draw_text(0, 420, 120, 32, "Stamina")
    draw_actor_name(@actor, 578, -10.5)
    self.contents.draw_text(20, 0, 100, 32, "Strength: " +$game_party.actors[0].str.to_s)
    self.contents.draw_text(20, 14, 100, 32, "Agility: " +$game_party.actors[0].agi.to_s)
    self.contents.draw_text(20, 26, 100, 32, "Intelligence: " +$game_party.actors[0].int.to_s)
    self.contents.draw_text(20, 38, 100, 32, "Dexterity: " +$game_party.actors[0].dex.to_s)
  end
def reset_variables
  @actor = $game_party.actors[0]
  @oldsp = @actor ? @actor.sp : 0
  @oldmaxsp = @actor ? @actor.maxsp : 0
  @str = @actor ? @actor.str : 0
  @agi = @actor ? @actor.agi : 0
  @int = @actor ? @actor.int : 0
  @eva = @actor ? @actor.dex : 0
end

def update
  super
  actor = $game_party.actors[0]
  refresh if actor != @actor ||
    @oldsp != actor.sp ||
    @oldmaxsp != actor.maxsp ||
    @str != actor.str ||
    @agi != actor.agi ||
    @int != actor.int ||
    @eva != actor.dex
  end
end
#================================================= =============================
# ** Window_Base
#------------------------------------------------------------------------------
# This class is for all in-game windows.
#================================================= =============================
class Window_Base < Window
#--------------------------------------------------------------------------
# * Draw Slant Bar
#--------------------------------------------------------------------------
def draw_bar(x, y, min, max, width = 152, height = 6,
bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
# Draw Border
for i in 0..height
self.contents.fill_rect(x, y + height - i, width, 1, Color.new(50, 50, 50, 255))
end
# Draw Background
for i in 1..(height - 1)
r = 100 * (height - i) / height + 0 * i / height
g = 100 * (height - i) / height + 0 * i / height
b = 100 * (height - i) / height + 0 * i / height
a = 255 * (height - i) / height + 255 * i / height
self.contents.fill_rect(x, y + height - i, width, 1, Color.new(r, b, g, a))
end
# Draws Bar
for i in 1..( (min / max.to_f) * width - 1)
for j in 1..(height - 1)
r = bar_color.red * (width - i) / width + end_color.red * i / width
g = bar_color.green * (width - i) / width + end_color.green * i / width
b = bar_color.blue * (width - i) / width + end_color.blue * i / width
a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
self.contents.fill_rect(x + i - 1, y + height - j, 1, 1, Color.new(r, g, b, a))
end
end
end
end
 

khmp

Sponsor

You can place these five lines at the bottom of the refresh method of your HUD:
Code:
    weapon = $data_weapons[$game_party.actors[0].weapon_id]
    weapon_name = weapon.name
    weapon_icon = RPG::Cache.icon(weapon.icon_name)
    self.contents.blt(0, 72, weapon_icon, weapon_icon.rect)
    self.contents.draw_text(26, 72, 120, 32, weapon_name)

There is way to much wasted space on the window. Originally you were blanketing the entire screen. If you turn the opacity to 0 you won't see the border. "self.contents.opacity" controls the opacity of the objects drawn on it. For those reasons you can change you HUD's initialize to this:
Code:
  def initialize
    super(0, 0, 200, 200)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Arial"
    self.contents.font.size = 15
    self.back_opacity = 0
    self.opacity = 0 # I don't want to see a border.
    refresh
  end
 

khmp

Sponsor

Code:
weapon = $data_weapons[$game_party.actors[0].weapon_id]
unless weapon.nil?
  weapon_name = weapon.name
  weapon_icon = RPG::Cache.icon(weapon.icon_name)
  self.contents.blt(0, 72, weapon_icon, weapon_icon.rect)
  self.contents.draw_text(26, 72, 120, 32, weapon_name)
end
 
yay, would you like to see what this was for? here is the hud that took me forever :)

http://i35.tinypic.com/vpua7s.png[/img]
I also figured out a way to refresh :)

Code:
def update
    refresh if something_changed?
  end
end
  #--------------------------------------------------------------------------
  # * Something Changed?
  #--------------------------------------------------------------------------
  def something_changed?
    return false if Graphics.frame_count % 30 != 0
    return true if @actor != $game_party.actors[0]
    return true if @old_sp != @actor.sp 
    return true if @str != actor.str
    return true if @agi != actor.agi
    return true if @gold_n != $game_party.gold
    return true if @int != actor.int
    return true if @dex != actor.dex
    return true if $kts != nil and @time != $kts.time.to_s
    return true if $kts == nil and @time != game_time
    return false
  end
 

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