[XP] Item Weight

Started by ForeverZer0, April 15, 2012, 07:13:11 pm

Previous topic - Next topic

ForeverZer0

April 15, 2012, 07:13:11 pm Last Edit: April 16, 2012, 03:52:27 pm by ForeverZer0
Item Weight
Authors: ForeverZer0
Version: 1.0
Type: Item/Equipment Add-On
Key Term: Player / Party / Troop Add-on



Introduction

This system provides your game with an inventory "weight" feature. Every item and piece of equipment can be configured with an individual weight that provides a different dynamic to collecting items, since the player will have to manage their inventories instead of just collecting everything in sight. Settings for can be made for managing it on a "per actor basis", and various states can be applied when a character/party is "overweight".


Features


  • States can be applied to the whole party or individual actor basis

  • Every item, weapon, and armor can have a unique weight

  • Unlimited number of states

  • Can us a dynamic weight capacity that grows with actor power, or static capacity that you can control yourself via simple script calls

  • Automatic setting of game variables that are equal to the party's current weight and total capacity

  • Configurable modifier that allows for defining the rate of dynamic weight capacity based off actor strength

  • Automatic adding of weight to item descriptions if desired so that the player is always aware of each item's weight

  • Configuration for allowing or not items to be picked up by party or equipped by actors if weight would exceed capacity




Screenshots

None.


Demo

None.


Script

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# Item Weight
# Author: ForeverZer0
# Date: 4.15.2012
# Version: 1.0
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#                           VERSION HISTORY
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# v.1.0
#   - Original release
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#
# Explanation:
#   This system provides your game with an inventory "weight" feature. Every
#   item and piece of equipment can be configured with an individual weight that
#   provides a different dynamic to collecting items, since the player will have
#   to manage their inventories instead of just collecting everything in sight.
#   Settings for can be made for managing it on a "per actor basis", and various
#   states can be applied when a character/party is "overweight".
#
# Features:
#   - States can be applied to the whole party or individual actor basis
#   - Every item, weapon, and armor can have a unique weight
#   - Unlimited number of states
#   - Can us a dynamic weight capacity that grows with actor power, or static
#     capacity that you can control yourself via simple script calls
#   - Automcatic setting of game variables that are equal to the party's current
#     weight and total capacity
#   - Configurable modifier that allows for defining the rate of dynamic weight
#     capacity based off actor strength
#   - Automatic adding of weight to item descriptions if desired so that the
#     player is always aware of each item's weight
#   - Configuration for allowing or not items to be picked up by party or
#     equipped by actors if weight would exceed capacity
#    
# Instructions:
#   - Place script below default scripts, and above "Main"
#   - See below and find the "Weight" module. There are a few simple settings
#     that can be made with detailed descriptions of each
#   - Configure item weights in the RPG::Item, RPG::Weapon, and RPG::Armor
#     classes found below
#   - When using STATIC_CAPACITY and you would like to change an actor's
#     carrying capacity, use these script calls:
#
#         $game_party.actors[ACTOR_INDEX].weight_capacity = VALUE
#                         OR
#         $game_actors[ACTOR_ID].weight_capacity = VALUE
#
#
#
# Compatibility:
#   - Custom CMS's (specifically the equip part of it), could possibly cause
#     problems, and would require minor edits to ensure that items that are too
#     heavy could not be equipped when OVERWEIGHT_ACTOR is false.
#
# Credits/Thanks:
#   - ForeverZer0, for the script
#   - Bigfoot, for requesting it
#
# Author's Notes:
#   - Please report any bugs/issues to www.chaos-project.com or via email:
#     foreverzer0@chaos-project.com
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#                          BEGIN CONFIGURATION
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:

#===============================================================================
# Weight
#-------------------------------------------------------------------------------
# Module for configuring various weight settings
#===============================================================================

module Weight
 
 # Set to true/false if actor weight capacity grows with the actor's
 # strength, or remains a fixed number (can be changed via script call)
 DYNAMIC_CAPACITY = false
 
 # Define the modifier for the DYNAMIC_CAPACITY. This value will be multiplied
 # by the actor's strength to determine their carrying capacity. Ignore this
 # setting if DYNAMIC_CAPACITY is false.
 DYNAMIC_MODIFIER = 1.5
 
 # Define the static carrying capacity that actors begin with. This value can
 # only be changed via script call, and will not grow with the actor's power.
 # Ignore this setting if DYNAMIC_CAPACITY is true.
 STATIC_CAPACITY = 4.0
 
 # Include the IDs of any states that will be applied when
 #cweight exceeds maximum capacity.
 OVERWEIGHT_STATES = [2, 3]
 
 # Set to true/false if individual actors can become overweight, or if it is
 # only on a "whole party" basis. The entire party will still be afflicted with
 # states if the total weight exceeds the party's capacity. In other words,
 # define if actor's can equip items that are too heavy for them.
 OVERWEIGHT_ACTOR = true
 
 # Determines if items/equipment can still be gained when current weight would
 # exceed total carrying capacity after picking it up. The maximum number that
 # can be added will still be received if this is false and receiving multiple
 # quantities. In other words, can items still be picked up that are too
 # heavy for the party.
 OVERWEIGHT_PARTY = false
 
 # Set the ID of the variable that will be equal to the party's current weight
 CURRENT_VARIABLE = 10
 
 # Set the ID of the variable that will be equal to the party's total capacity
 CAPACITY_VARIABLE = 11
 
 # Set to true/false if item weights should automatically be added to the
 # description for help menu's, etc.
 WEIGHT_DESCRIPTION = true
 
 # Determines the modification of the item's description. Ignore if
 # WEIGHT_DESCRIPTION is false.
 # EXAMPLE: "[#{weight} lbs] #{text}"
 def self.description(text, weight)
   return "#{text} (#{weight} kg)"
 end
end

#===============================================================================
# * RPG::Item
#===============================================================================
module RPG
 class Item
   #---------------------------------------------------------------------------
   # * weight
   #     Define the weights of items (when ITEM_ID then WEIGHT)
   #---------------------------------------------------------------------------
   def weight
     return case @id
     when 1 then 0.5
     when 2 then 0.75
     when 3 then 1.0
     when 4 then 1.0
     when 5 then 1.0
     when 6 then 1.0
     when 7 then 1.0
     when 8 then 1.0
     when 9 then 1.0
     when 10 then 1.0
     else 1.0
     end
   end
   #---------------------------------------------------------------------------
   # * description
   #     Returns the modified description when WEIGHT_DESCRIPTION is true
   #---------------------------------------------------------------------------
   def description
     return !Weight::WEIGHT_DESCRIPTION ? @description :
       Weight.description(@description, weight)  
   end
 end
#===============================================================================
# * RPG::Weapon
#===============================================================================
 class Weapon
   #---------------------------------------------------------------------------
   # * weight
   #     Define the weights of weapons (when WEAPON_ID then WEIGHT)
   #---------------------------------------------------------------------------
   def weight
     return case @id
     when 1 then 1.0
     when 2 then 1.0
     when 3 then 1.0
     when 4 then 1.0
     when 5 then 1.0
     when 6 then 1.0
     when 7 then 1.0
     when 8 then 1.0
     when 9 then 1.0
     when 10 then 1.0
     else 1.0
     end
   end
   #---------------------------------------------------------------------------
   # * description
   #     Returns the modified description when WEIGHT_DESCRIPTION is true
   #---------------------------------------------------------------------------
   def description
     return !Weight::WEIGHT_DESCRIPTION ? @description :
       Weight.description(@description, weight)  
   end
 end
#===============================================================================
# * RPG::Armor
#===============================================================================
 class Armor
   #---------------------------------------------------------------------------
   # * weight
   #     Define the weights of armors (when ARMOR_ID then WEIGHT)
   #---------------------------------------------------------------------------
   def weight
     return case @id
     when 1 then 1.0
     when 2 then 1.0
     when 3 then 1.0
     when 4 then 1.0
     when 5 then 1.0
     when 6 then 1.0
     when 7 then 1.0
     when 8 then 1.0
     when 9 then 1.0
     when 10 then 1.0
     when 29 then 2.0
     else 1.0
     end
   end
   #---------------------------------------------------------------------------
   # * description
   #     Returns the modified description when WEIGHT_DESCRIPTION is true
   #---------------------------------------------------------------------------
   def description
     return !Weight::WEIGHT_DESCRIPTION ? @description :
       Weight.description(@description, weight)  
   end
 end
end

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#                            END CONFIGURATION
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:

#===============================================================================
# * Game_Actor
#===============================================================================

class Game_Actor
 #-----------------------------------------------------------------------------
 # * initailize
 #     Aliased method to add capacity variable to Game_Actor, which is used
 #     when using STATIC_CAPACITY.
 #-----------------------------------------------------------------------------
 alias inventory_weight_init initialize
 def initialize(actor_id)
   inventory_weight_init(actor_id)
   @capacity = Weight::STATIC_CAPACITY
 end
 #-----------------------------------------------------------------------------
 # * weight
 #     Returns the total weight of all equipped items the actor has
 #-----------------------------------------------------------------------------
 def weight
   weight = 0
   equipment = [
     $data_weapons[@weapon_id],
     $data_armors[@armor1_id],
     $data_armors[@armor2_id],
     $data_armors[@armor3_id],
     $data_armors[@armor4_id]
   ]
   equipment.each {|item| weight += (item != nil ? item.weight : 0) }
   return weight
 end
 #-----------------------------------------------------------------------------
 # * weight_capacity=
 #     Sets the carrying capacity of the actor when using STATIC_CAPACITY
 #-----------------------------------------------------------------------------
 def weight_capacity=(capacity)
   @capacity = capacity
 end
 #-----------------------------------------------------------------------------
 # * weight_capacity
 #     Returns the amount of weight the actor can carry
 #-----------------------------------------------------------------------------
 def weight_capacity
   if Weight::DYNAMIC_CAPACITY
     return base_str * Weight::DYNAMIC_MODIFIER
   else
     return @capacity
   end
 end
 #-----------------------------------------------------------------------------
 # * within_capacity?
 #     Factors in weight when determining if piece of equipment is equippable
 #     or not.
 #-----------------------------------------------------------------------------
 def equippable_weight?(item)
   return true if item == nil || Weight::OVERWEIGHT_ACTOR
   actor_weight = self.weight + item.weight
   if item.is_a?(RPG::Weapon)
     weapon = $data_weapons[@weapon_id]
     actor_weight -= (weapon == nil ? 0 : weapon.weight)
   elsif item.is_a?(RPG::Armor)
     case item.kind
     when 0 # Armor
       armor = $data_armors[@armor1_id]
     when 1 # Shield
       armor = $data_armors[@armor2_id]
     when 2 # Helmet
       armor = $data_armors[@armor3_id]
     when 3 # Accessory
       armor = $data_armors[@armor4_id]
     end
     actor_weight -= (armor == nil ? 0 : armor.weight)
   end
   return actor_weight <= weight_capacity
 end
 #-----------------------------------------------------------------------------
 # * equip
 #     Refreshes party weight and states after item change
 #-----------------------------------------------------------------------------
 alias item_weight_equip equip
 def equip(kind, id)
   item = kind == 0 ? $data_weapons[id] : $data_armors[id]
   if equippable_weight?(item)
     item_weight_equip(kind, id)
     $game_party.refresh_weight
   end
 end
end

#===============================================================================
# * Game_Party
#===============================================================================

class Game_Party
 #-----------------------------------------------------------------------------
 # * weight_capacity
 #     Returns the cumulative weight capacity of all current party members
 #-----------------------------------------------------------------------------
 def weight_capacity
   weight = 0
   @actors.each {|actor| weight += actor.weight_capacity }
   return weight
 end
 #-----------------------------------------------------------------------------
 # * actor_weight
 #     Returns the total weight of all equipment worn by party members
 #-----------------------------------------------------------------------------
 def actor_weight
   weight = 0
   @actors.each {|actor| weight += actor.weight }
   return weight
 end
 #-----------------------------------------------------------------------------
 # * item_weight
 #     Returns the total weight of all items in inventory
 #-----------------------------------------------------------------------------
 def item_weight
   weight = 0
   @items.each_pair {|id, qty| weight += $data_items[id].weight * qty }
   return weight
 end
 #-----------------------------------------------------------------------------
 # * weapon_weight
 #     Returns the total weight of all weapons in inventory
 #-----------------------------------------------------------------------------
 def weapon_weight
   weight = 0
   @weapons.each_pair {|id, qty| weight += $data_weapons[id].weight * qty }
   return weight
 end
 #-----------------------------------------------------------------------------
 # * armor_weight
 #     Returns the total weight of all armors in inventory
 #-----------------------------------------------------------------------------
 def armor_weight
   weight = 0
   @armors.each_pair {|id, qty| weight += $data_armors[id].weight * qty }
   return weight
 end
 #-----------------------------------------------------------------------------
 # * total_weight
 #     Returns the total weight of all inventory and equipment that is
 #     equipped by the party members
 #-----------------------------------------------------------------------------
 def total_weight
   return actor_weight + item_weight + weapon_weight + armor_weight
 end
 #-----------------------------------------------------------------------------
 # * gain_item
 #     Aliased method to determine if party can add an item to inventory when
 #     ALLOW_OVERWHEIGHT is set to false. The maximum quantity that can fit
 #     will be added out of the total quanity if capacity would be exceeded.
 #-----------------------------------------------------------------------------
 alias item_weight_gain_item gain_item
 def gain_item(id, quantity)
   if Weight::OVERWEIGHT_PARTY
     item_weight_gain_item(id, quantity)
   else
     item = $data_items[id]
     weight = item == nil ? 0 : item.weight
     if !enough_capacity?(weight * quantity)
       allowed = (weight_capacity - total_weight) / weight
       item_weight_gain_item(id, allowed.floor)
     else
       item_weight_gain_item(id, quantity)
     end
   end
   refresh_weight
 end
 #-----------------------------------------------------------------------------
 # * gain_weapon
 #     Aliased method to determine if party can add a weapon to inventory when
 #     ALLOW_OVERWHEIGHT is set to false. The maximum quantity that can fit
 #     will be added out of the total quanity if capacity would be exceeded.
 #-----------------------------------------------------------------------------
 alias item_weight_gain_weapon gain_weapon
 def gain_weapon(id, quantity)
   if Weight::OVERWEIGHT_PARTY
     item_weight_gain_weapon(id, quantity)
   else
     weapon = $data_weapons[id]
     weight = weapon == nil ? 0 : weapon.weight
     if !enough_capacity?(weight * quantity)
       allowed = (weight_capacity - total_weight) / weight
       item_weight_gain_weapon(id, allowed.floor)
     else
       item_weight_gain_weapon(id, quantity)
     end
   end
   refresh_weight
 end
 #-----------------------------------------------------------------------------
 # * gain_armor
 #     Aliased method to determine if party can add an armor to inventory when
 #     ALLOW_OVERWHEIGHT is set to false. The maximum quantity that can fit
 #     will be added out of the total quanity if capacity would be exceeded.
 #-----------------------------------------------------------------------------
 alias item_weight_gain_armor gain_armor
 def gain_armor(id, quantity)
   if Weight::OVERWEIGHT_PARTY
     item_weight_gain_armor(id, quantity)
   else
     armor = $data_armors[id]
     weight = armor == nil ? 0 : armor.weight
     if !enough_capacity?(weight * quantity)
       allowed = (weight_capacity - total_weight) / weight
       item_weight_gain_armor(id, allowed.floor)
     else
       item_weight_gain_armor(id, quantity)
     end
   end
   refresh_weight
 end  
 #-----------------------------------------------------------------------------
 # * add_actor
 #     Refreshes party weight and states when actor is added to party
 #-----------------------------------------------------------------------------
 alias item_weight_add_actor add_actor
 def add_actor(actor_id)
   item_weight_add_actor(actor_id)
   refresh_weight
 end
 #-----------------------------------------------------------------------------
 # * remove_actor
 #     Refreshes party weight and states when actor is removed from party
 #-----------------------------------------------------------------------------
 alias item_weight_remove_actor remove_actor
 def remove_actor(actor_id)
   item_weight_remove_actor(actor_id)
   refresh_weight
 end
 #-----------------------------------------------------------------------------
 # * enough_capacity?
 #     Returns true/false if given weight would not exceed capacity
 #-----------------------------------------------------------------------------
 def enough_capacity?(weight)
   return (total_weight + weight) <= weight_capacity
 end
 #-----------------------------------------------------------------------------
 # * refresh_weight
 #     Refreshes the weight variables and adds/removes weight states
 #-----------------------------------------------------------------------------
 def refresh_weight
   total, capacity = total_weight, weight_capacity
   $game_variables[Weight::CURRENT_VARIABLE] = total
   $game_variables[Weight::CAPACITY_VARIABLE] = capacity
   # Add/remove states to party as a whole
   if Weight::OVERWEIGHT_PARTY && total > capacity
     @actors.each {|actor|
       Weight::OVERWEIGHT_STATES.each {|state_id| actor.add_state(state_id) }
     }
   # Add/remove individual states for actors
   elsif Weight::OVERWEIGHT_ACTOR
     @actors.each {|actor|
       if actor.weight > actor.weight_capacity
         Weight::OVERWEIGHT_STATES.each {|state_id| actor.add_state(state_id) }
       else
         Weight::OVERWEIGHT_STATES.each {|state_id| actor.remove_state(state_id) }
       end
     }
   else
     @actors.each {|actor|
       Weight::OVERWEIGHT_STATES.each {|state_id| actor.remove_state(state_id) }
     }
   end
 end
 #-----------------------------------------------------------------------------
 # * setup_starting_members
 #     Alias method to set the game variables at the beginning of the game
 #-----------------------------------------------------------------------------
 alias item_weight_setup_starting_members setup_starting_members
 def setup_starting_members
   item_weight_setup_starting_members
   refresh_weight
 end
end

#===============================================================================
# * Scene_Equip
#-------------------------------------------------------------------------------
# This needs to be here more or less just to what can only be considered either
# bad coding or a bug in RMXP. The "equip" method of Game_Actor is constantly
# called whenever an item is highlighted in Scene_Equip, and this is kind of
# a little bypass for that.
#===============================================================================

class Scene_Equip
 #-----------------------------------------------------------------------------
 # * update_item
 #     Cancels equipping item if configured to do so and item would put
 #     actor overweight
 #-----------------------------------------------------------------------------
 alias item_weight_update_item update_item
 def update_item
   if Input.trigger?(Input::C)
     item = @item_window.item
     unless @actor.equippable_weight?(item)
       $game_system.se_play($data_system.buzzer_se)
       return
     end
   end
   item_weight_update_item
 end
end

   




Add-Ons

These are some add-ons to the system to either augment the script, or fix conflicts with other scripts. Unless otherwise instructed, these add-ons will all be placed under the main script in the editor.

Default Shop System Fix
This add-on will prevent the purchasing of items that would put the party overweight when OVERWEIGHT_PARTY is false. It also adds a nice display to the shop screen that will show the player the weight/capacity ratio of the selected quantity.

Screenshot: ShowHide

Script: ShowHide
#===============================================================================
# * Scene_Shop
#===============================================================================

class Scene_Shop
 #-----------------------------------------------------------------------------
 # * update_number
 #     Prevents purchasing of items when OVERWEIGHT_PARTY is true and number
 #     of items to buy would exceed maximum weight
 #-----------------------------------------------------------------------------
 alias item_weight_update_number update_number
 def update_number
   unless Weight::OVERWEIGHT_PARTY
     if Input.trigger?(Input::C) && @command_window.index == 0
       weight = @item.weight * @number_window.number
       weight += $game_party.total_weight
       if weight > $game_party.weight_capacity
         $game_system.se_play($data_system.buzzer_se)
         return
       end
     end
   end
   item_weight_update_number
 end
end

#===============================================================================
# * Window_ShopNumber
#===============================================================================

class Window_ShopNumber
 #-----------------------------------------------------------------------------
 # * refresh
 #     Adds a weight display to the number screen at the shop
 #-----------------------------------------------------------------------------
 alias item_weight_refresh refresh
 def refresh
   item_weight_refresh
   weight = (@item.weight * @number) + $game_party.total_weight
   capacity = $game_party.weight_capacity
   self.contents.draw_text(4, 192, 72, 32, 'Weight:')
   color = weight > capacity ? crisis_color : normal_color
   self.contents.font.color = color
   self.contents.draw_text(76, 192, 64, 32, weight.to_s, 2)
   self.contents.font.color = normal_color
   self.contents.draw_text(144, 192, 64, 32, '/ ' + capacity.to_s)
 end
end


Default Menu Display
Adds a display to the default menu system that shows the weight/capacity of each actor.

Screenshot: ShowHide

Script: ShowHide
#===============================================================================
# * Window_Base
#===============================================================================

class Window_Base
 #-----------------------------------------------------------------------------
 # * draw_actor_weight
 #     Draws the actor's weight/capacity at given location
 #-----------------------------------------------------------------------------
 def draw_actor_weight(actor, x, y, width = 144)
   self.contents.font.color = system_color
   self.contents.draw_text(x, y, 32, 32, 'WT')
   color = actor.weight > actor.weight_capacity ? crisis_color : normal_color
   self.contents.font.color = color
   if width - 32 >= 108
     wt_x = x + width - 108
     flag = true
   elsif width - 32 >= 48
     wt_x = x + width - 48
     flag = false
   end    
   self.contents.draw_text(wt_x, y, 48, 32, actor.weight.to_s, 2)
   if flag
     self.contents.font.color = normal_color
     self.contents.draw_text(wt_x + 48, y, 12, 32, '/', 1)
     self.contents.draw_text(wt_x + 60, y, 48, 32, actor.weight_capacity.to_s)
   end
 end
end

#===============================================================================
# * Window_MenuStatus
#===============================================================================

class Window_MenuStatus
 #-----------------------------------------------------------------------------
 # * refresh
 #     Draws each actor's weight/capacity on the menu
 #-----------------------------------------------------------------------------
 alias item_weight_refresh refresh
 def refresh
   item_weight_refresh
   $game_party.actors.each_index {|i|
     draw_actor_weight($game_party.actors[i], 300, i * 116) }
 end
end


Simple HUD
This is a simple HUD that can be displayed on the screen in the location of your choice. It can either be as a small window, or simple text on the screen. The font can also be changed as desired, and there is a script call for hiding/showing it.

Screenshot - No Window: ShowHide

Screenshot - Window: ShowHide

Script: ShowHide
#===============================================================================
# * WeightHUD
#===============================================================================

class WeightHUD < Window_Base
 
  # Set true/false if windowskin should be used or not. If not, text will simply
  # be displayed on the screen.
  WINDOWED = true
 
  # Set the location of the HUD. [X, Y, WIDTH, HEIGHT]
  # I recommend a small X and Y offset if WINDOWED is set to false to have
  # the text placed properly and not to far off the edge of the screen.
  LOCATION = [0, 0, 144, 64]
 
  # Set the font used for the HUD. [FONT_NAME, FONT_SIZE]
  # A value of nil for either setting will have it simply use the default font
  FONT = ['Calibri', 20]
 
  # Script Calls:
  #   hide_weightHUD(true/false) - Sets the hidden state of the weight HUD
 
  #-----------------------------------------------------------------------------
  # * initialize
  #     Creates a new instance of the HUD
  #-----------------------------------------------------------------------------
  def initialize
    super(*LOCATION)
    self.windowskin = nil unless WINDOWED
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = FONT[0] == nil ? Font.default_name : FONT[0]
    self.contents.font.size = FONT[1] == nil ? Font.default_size : FONT[1]
    refresh
  end
  #-----------------------------------------------------------------------------
  # * refresh
  #   Clears and redraws the HUD
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(0, 0, 32, 32, 'WT')
    weight, capacity = $game_party.total_weight, $game_party.weight_capacity
    color = weight > capacity ? crisis_color : normal_color
    self.contents.font.color = color
    self.contents.draw_text(32, 0, 42, 32, weight.to_s, 2)
    self.contents.font.color = normal_color
    self.contents.draw_text(74, 0, 8, 32, '/', 1)
    self.contents.draw_text(82, 0, 42, 32, capacity.to_s)
  end
end

#===============================================================================
# * Game_Party
#===============================================================================

class Game_Party
  #-----------------------------------------------------------------------------
  # * refresh_weight
  #     Tells Scene_Map that the HUD needs refresh when the values change
  #-----------------------------------------------------------------------------
  alias weight_hud_refresh_weight refresh_weight
  def refresh_weight
    weight_hud_refresh_weight
    if $scene.is_a?(Scene_Map)
      $scene.refresh_weightHUD
    end
  end
end

#===============================================================================
# * Scene_Map
#===============================================================================

class Scene_Map
  #-----------------------------------------------------------------------------
  # * main
  #     Creates the HUD and disposes it when the scene ends
  #-----------------------------------------------------------------------------
  alias item_weight_main main
  def main
    @weight_hud = WeightHUD.new
    item_weight_main
    @weight_hud.dispose
  end
  #-----------------------------------------------------------------------------
  # * hide_weightHUD
  #     Hides/Shows the weight HUD if it is present and not disposed
  #-----------------------------------------------------------------------------
  def hide_weightHUD(bool)
    if @weight_hud != nil && !@weight_hud.disposed?
      @weight_hud.visible = bool
    end
  end
  #-----------------------------------------------------------------------------
  # * refresh_weightHUD
  #     Refreshes the weight HUD if it is present and not disposed
  #-----------------------------------------------------------------------------
  def refresh_weightHUD
    if @weight_hud != nil && !@weight_hud.disposed?
      @weight_hud.refresh
    end
  end
end

#===============================================================================
# * Interpreter
#===============================================================================

class Interpreter
  #-----------------------------------------------------------------------------
  # * hide_weightHUD
  #     Hides/Shows the weight HUD if it is present and not disposed
  #-----------------------------------------------------------------------------
  def hide_weightHUD(value = true)
    if $scene.is_a?(Scene_Map)
      $scene.hide_weightHUD(value)
    end
  end
end




Instructions

Simple configuration, which can be found in the script.


Compatibility

Possible compatibility issues with actor equipping issues in custom menu systems. (See script for explanation)
If you have a problem with a custom CMS, make a post about it and see if it can be fixed, which should be quite simple.


Credits and Thanks


  • ForeverZer0, for the script

  • Bigfoot, for requesting it




Author's Notes

Please report any issues/bugs you may come across so they can be addressed.
Enjoy! Main
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Bigfoot

Thank you so much!  I tried testing it out, but got a syntaxerror on line 535.  Not sure why, that's the end of the script.  I'll try going back into it and read the directions more thoroughly.

ForeverZer0

April 15, 2012, 07:33:18 pm #2 Last Edit: April 15, 2012, 07:36:16 pm by ForeverZer0
Let me check, I might have had some paste get cut off.

EDIT:
I didn't get a syntax error, make sure you copy the whole script and none gets cutoff.

After you open the spoiler, use the "Select" word at the top of the code field and hit Ctrl + C to make sure you get it all.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Bigfoot

The "select" code didn't seem to work.  But I made sure it was all copied properly and still got the same error.  IDK

ForeverZer0

I dunno, might be issue with your browser.
Here's a pastebin with it.

http://pastebin.com/PFKbfHUG
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Bigfoot

Ah, that seemed to work.  Thanks again!  You're the master!

Calintz

let us know how this turns our bigfoot. this script sounds promising!

Bigfoot

I did some testing with it and found it to be exactly what I needed except for the fact that you can't tell how much the character is carrying or how much he can carry.  Some sort of display would be very useful.

diagostimo

i tested this as it sounds very useful, and i found a glitch, if the player is shopping and exceeds the the weight limit and gaining items when over encumbered is false then it still takes your money :P @ bigfoot your menu would need editing to show the weight variables value, wouldnt be hard to implement into it 

Bigfoot

Yeah, but perhaps there'd be a way to make a meter on the map.  Like a HUD.  I've seen it on other scripts.

Calintz

for the purpose of your game, having the display on the map would probably be useful. given other scenarios, perhaps a display in the menu would be more appropriate. either way, this is a thumbs up script.

ForeverZer0

Here is the catch with both of those problems. I can make a few quick fixes and they will be fixed, but so long only as you are are using the default shop and menu systems. I'll make them, but they are gonna be add-ons instead of integrated into the script, that way the script will still be easier to integrate into other systems.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Futendra

When this is fully debugged, I will sure use this for my game! I was already thinking of a way to realisticly limit items (I grabbed an actual item limiter but it is kinda weird that 100 guns weighing probably like 10 kilo each is the limit. Neither is having only 10 potions.)

ForeverZer0

April 16, 2012, 01:56:28 pm #13 Last Edit: April 16, 2012, 02:37:01 pm by ForeverZer0
I added the fix for the default shop system. It will prevent purchasing of items that will put you overweight when OVERWEIGHT_PARTY is false, and adds a display to the shop menu.

EDIT:
I also added an addon to have each actor's weight displayed on the menu screen.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Futendra

Could you put the window to show the Weight of Actor 1 here (the code) so I can add it to a CMS?

ForeverZer0

April 16, 2012, 02:54:00 pm #15 Last Edit: April 16, 2012, 03:53:49 pm by ForeverZer0
Take a look at the Menu addon above. I actually made an extension method to Window_Base called "draw_actor_weight", which works the exact same as all the default RGSS ones like "draw_actor_level", "draw_actor_hp", etc. It should be exactly what you are looking for.

EDIT:
Alrighty, I added a simple HUD add-on. Its pretty basic, but should suit most people's needs.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Bigfoot

Oh man, this is so great!  Thanks again!

Sin86

I know that this is necroposting but no one else has mentioned this but apparently, I use Stormtronics CMS and this may or may not have anything to do with the issue I'm having but if I go over my weight limit, the states won't apply like they should. Also, when browsing through my inventory, I will see how much any other item weighs except for weapons.

KK20

I downloaded the Stormtronics demo and threw this script right below it. States are applied when I either go into battle or change someone's equipment (but not right at the start of loading the game). I used Venom (state ID 3) to test this. Note that a State with a Restriction of 0 does not visually appear in the UI by default.

Regarding the weapons, I see the weight values in its description just fine. I think you're using some other script that is conflicting then.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Sin86

Ah, so that was the problem. Normally I thought the status effects would go right into play when the weight reaches the limit. I know, been playing too much Elder Scrolls lol.

All good to know, thank you.