Save-Point

Full Version: Save-Point
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Board Message
Sorry, you do not have permission to access this resource.
Save-Point - Item Tracker/Hud

Save-Point

Full Version: Item Tracker/Hud
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm basically just looking for a simple script that lets you visually keep track of how many Torches are in your inventory,without having to actually check your inventory all the time, like on a HUD or something. Would this be tough to script? Or is there already something like this? I know there's ABS's out there that include this but I'd rather not implement an entire battle system for this one feature :/
Ah, but for what system? You forgot to include that in your request and didn't select which category, be it XP, VX, VXAce... or perhaps it is another engine (if so please elaborate so I can make a suitable prefix icon).
Oh my bad, its for XP.
Well, I'd rather you not have sloppy code, so....

Code:
#==============================================================================
# ** SingleItem_Hud
#------------------------------------------------------------------------------
#    by DerVVulfman
#    version 1.0
#    05-31-2015
#    RGSS / RMXP - Aliases Only
#------------------------------------------------------------------------------
#  This basic script creates an item HUD,  rendering the quantity  of an item
#  in the player's inventory along with its icon.  It also includes an on/off
#  switch feature for game designer convenience.
#
#  The HUD's item icon may be turned on/off in the configuration system,  and
#  the hud's width and text placement self-adjusts based on this condition.
#
#==============================================================================

module SingleItem
  
  # Configurable values
    ITEM_NUMBER   = 1     # Item in inventory (by Item ID)
    ICON_ON       = true  # Item Icon displayed switch (if false, no icon)
    X_POS         = 0     # X Position on field map
    Y_POS         = 0     # Y Position on field map
    WIDTH         = 40    # Width of text area
    VIS_SWITCH    = 1     # RMXP Switch that turns Hud On/Off
end



#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles the map. It includes scrolling and passable determining
#  functions. Refer to "$game_map" for the instance of this class.
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias singleitem_hud_game_map_refresh refresh
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Refresh Hud if map ID is effective
    $scene.singleitem_hud.refresh if @map_id > 0
    # Perform the original call
    singleitem_hud_game_map_refresh
  end
end



#==============================================================================
# ** Window_SingleItem_Hud
#------------------------------------------------------------------------------
#  This window displays the Heads-Up-Display for the Lycan ABS
#==============================================================================

class Window_SingleItem_Hud < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Determine Icon offset
    x = (SingleItem::ICON_ON == true) ? 32 : 0
    # Calculate width before Super creates window
    hudwidth = SingleItem::WIDTH + 32 + x
    # Super
    super(SingleItem::X_POS, SingleItem::Y_POS, 96, hudwidth)
    # Create Bitmap
    self.contents = Bitmap.new(width - 32, height - 32)
    # Hide Window
    self.opacity  = 0
    # Get Torches
    @old_torches = 0
    # Refresh
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Clear the window contents
    self.contents.clear
    # Ensure if visible or not based on configured switch
    self.visible = $game_switches[SingleItem::VIS_SWITCH]
    # Get current torch quantity
    @old_torches = $game_party.item_number(SingleItem::ITEM_NUMBER)
    # Render window
    refresh_hud_main_window
  end
  #--------------------------------------------------------------------------
  # * Refresh Hud Display - Main Window
  #--------------------------------------------------------------------------
  def refresh_hud_main_window
    # Determine Icon offset
    x = (SingleItem::ICON_ON == true) ? 32 : 0
    # Draw item quantity
    self.contents.draw_text(x, 0, SingleItem::WIDTH, 32, @old_torches.to_s)
    # Exit if no icon being rendered
    return unless SingleItem::ICON_ON == true
    # Get bitmap
    bitmap  = RPG::Cache.icon($data_items[SingleItem::ITEM_NUMBER].icon_name)
    # Set Rectangle drawing area
    rect    = Rect.new(0, 0, 24, 24)
    # Draw contents
    self.contents.blt(0,0, bitmap, rect)
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    refresh if something_changed?
  end
  #--------------------------------------------------------------------------
  # * Something Changed?
  #--------------------------------------------------------------------------
  def something_changed?
    # Assume nothing has changed
    effective = false
    # Assume change only if item quantity has changed
    effective = true  if @old_torches != $game_party.item_number(SingleItem::ITEM_NUMBER)
    # Return change
    return effective
  end  
end



#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias singleitem_hud_scene_map_main main
  alias singleitem_hud_scene_map_update update
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :singleitem_hud           # hud variable
  #--------------------------------------------------------------------------
  # * Main Draw
  #--------------------------------------------------------------------------
  def main
    # Make hud window
    @singleitem_hud   = Window_SingleItem_Hud.new
    # Perform the original call
    singleitem_hud_scene_map_main
    # Dispose of hud window
    @singleitem_hud.dispose
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    # Update the Hud
    @singleitem_hud.update
    # Perform the original call
    singleitem_hud_scene_map_update
  end
end
Thanks man! Works perfect!