Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Bob423

[Resolved] Remembering the inventory

Question

Is there a way to take away the player's items, weapons, and armor, then, put them all back, later, exactly the way they were, including the equipment?

Edited by Bob423

Share this post


Link to post
Share on other sites

12 answers to this question

Recommended Posts

  • 0

hows this:

 

 

#==============================================================================
# Script Calls:
# -------------
# * $game_party.remove_items (removes and stores all objects in possesion)
# * $game_party.regain_items (regains all stored items)
#
# * when using the script calls removing items multiple times will result in
#   item amounts stacking so you dont have to worry about losing stored items,
#   also regaining items will stack ontop of the current invetory so you dont
#   need to worry about losing the current possesions
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  modified to remove and store items, weapons and armors
#==============================================================================
class Game_Party
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader :stored_items, :stored_weapons, :stored_armors
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 alias init_items initialize
 def initialize
   init_items
   @stored_items = {}
   @stored_weapons = {}
   @stored_armors = {}
 end
 #--------------------------------------------------------------------------
 # * Get stored item amount
 #--------------------------------------------------------------------------
 def stored_item_number(item_id)
   # If quantity data is in the hash, use it. If not, return 0
   return @stored_items.include?(item_id) ? @stored_items[item_id] : 0
 end
 #--------------------------------------------------------------------------
 # * Get stored weapon amount
 #--------------------------------------------------------------------------
 def stored_weapon_number(weapon_id)
   # If quantity data is in the hash, use it. If not, return 0
   return @stored_weapons.include?(weapon_id) ? @stored_weapons[weapon_id] : 0
 end
 #--------------------------------------------------------------------------
 # * Get stored armor amount
 #--------------------------------------------------------------------------
 def stored_armor_number(armor_id)
   # If quantity data is in the hash, use it. If not, return 0
   return @stored_armors.include?(armor_id) ? @stored_armors[armor_id] : 0
 end
 #--------------------------------------------------------------------------
 # * Remove and store items in possesion
 #--------------------------------------------------------------------------
 def remove_items
   (1..$data_items.size).each {|i|
  @stored_items[i] = stored_item_number(i) + item_number(i)
   }
   (1..$data_weapons.size).each {|i|
  @stored_weapons[i] = stored_weapon_number(i) + weapon_number(i)
   }
   (1..$data_armors.size).each {|i|
  @stored_armors[i] = stored_armor_number(i) + armor_number(i)
   }
   @items = {}
   @weapons = {}
   @armors = {}
 end
 #--------------------------------------------------------------------------
 # * Regain stored items
 #--------------------------------------------------------------------------
 def regain_items
   (1..$data_items.size).each {|i|
  amount = stored_item_number(i)
  gain_item(i, amount)
   }
   (1..$data_weapons.size).each {|i|
  amount = stored_weapon_number(i)
  gain_weapon(i, amount)
   }
   (1..$data_armors.size).each {|i|
  amount = stored_armor_number(i)
  gain_armor(i, amount)
   }
   @stored_items = {}
   @stored_weapons = {}
   @stored_armors = {}
 end
end

 

 

:)

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

thanks, but i get an error when i use the script call:

line 36: no method error

undefined method "include?" for nil:NilClass

Share this post


Link to post
Share on other sites
  • 0

do you have any other custom scripts? the only reason i can think of is that one of your scripts is overwriting the initialization method and not aliasing it, put my script below all others and above main for good messure, i have tested the script i posted up and all is well

edit:

you can also get rid of the public instance variables, i forgot to remove them

 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader :stored_items, :stored_weapons, :stored_armors

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

i have the script under all other scripts, and above main. i do have custom scripts, so i guess i could try it in a blank project.

i removed the public instance variables, and it gives me the same error.

Share this post


Link to post
Share on other sites
  • 0

hmmm strange, can you upload a sample project exactly how it is?

also in the time being you could try changing the following in def remove_item and regain item :(1..$data_OBJECT.size)

to : (1...$data_OBJECT.size), just add a . for each object in each method

Share this post


Link to post
Share on other sites
  • 0

this should have popped to mind earlyer, the problem is your using a save, the initialization only runs on a new game, because your loading old data the variables dont exist, creating a new save should solve your problem :)

Share this post


Link to post
Share on other sites
  • 0

this should do it:

 

 

#==============================================================================
# Script Calls:
# -------------
# * $game_party.remove_items (removes and stores all objects in possesion)
# * $game_party.regain_items (regains all stored items)
#
# * when using the script calls removing items multiple times will result in
#   item amounts stacking so you dont have to worry about losing stored items,
#   also regaining items will stack ontop of the current invetory so you dont
#   need to worry about losing the current possesions
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# * edited public instance variables to be accessible outside the class
#==============================================================================
class Game_Actor < Game_Battler
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :weapon_id, :armor1_id, :armor2_id, :armor3_id, :armor4_id 
end
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  modified to remove and store items, weapons and armors
#==============================================================================
class Game_Party
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 alias init_items initialize
 def initialize
   init_items
   @stored_items = {}
   @stored_weapons = {}
   @stored_armors = {}
 end
 #--------------------------------------------------------------------------
 # * Get stored item amount
 #--------------------------------------------------------------------------
 def stored_item_number(item_id)
   # If quantity data is in the hash, use it. If not, return 0
   return @stored_items.include?(item_id) ? @stored_items[item_id] : 0
 end
 #--------------------------------------------------------------------------
 # * Get stored weapon amount
 #--------------------------------------------------------------------------
 def stored_weapon_number(weapon_id)
   # If quantity data is in the hash, use it. If not, return 0
   return @stored_weapons.include?(weapon_id) ? @stored_weapons[weapon_id] : 0
 end
 #--------------------------------------------------------------------------
 # * Get stored armor amount
 #--------------------------------------------------------------------------
 def stored_armor_number(armor_id)
   # If quantity data is in the hash, use it. If not, return 0
   return @stored_armors.include?(armor_id) ? @stored_armors[armor_id] : 0
 end
 #--------------------------------------------------------------------------
 # * Remove and store items in possesion
 #--------------------------------------------------------------------------
 def remove_items
   (1...$data_items.size).each {|i|
  @stored_items[i] = stored_item_number(i) + item_number(i)
   }
   (1...$data_weapons.size).each {|i|
  @stored_weapons[i] = stored_weapon_number(i) + weapon_number(i)
   }
   (1...$data_armors.size).each {|i|
  @stored_armors[i] = stored_armor_number(i) + armor_number(i)
   }
   ($game_party.actors).each {|actor|
  w = actor.weapon_id
  @stored_weapons[w] = stored_weapon_number(w) + 1 if w > 0
  actor.weapon_id = 0
  a1 = actor.armor1_id
  @stored_armors[a1] = stored_armor_number(a1) + 1 if a1 > 0
  actor.armor1_id = 0
  a2 = actor.armor2_id 
  @stored_armors[a2] = stored_armor_number(a2) + 1 if a2 > 0
  actor.armor2_id = 0
  a3 = actor.armor3_id
  @stored_armors[a3] = stored_armor_number(a3) + 1 if a3 > 0
  actor.armor3_id = 0
  a4 = actor.armor4_id
  @stored_armors[a4] = stored_armor_number(a4) + 1 if a4 > 0
  actor.armor4_id = 0
   }
   @items = {}
   @weapons = {}
   @armors = {}
 end
 #--------------------------------------------------------------------------
 # * Regain stored items
 #--------------------------------------------------------------------------
 def regain_items
   (1...$data_items.size).each {|i|
  amount = stored_item_number(i)
  gain_item(i, amount)
   }
   (1...$data_weapons.size).each {|i|
  amount = stored_weapon_number(i)
  gain_weapon(i, amount)
   }
   (1...$data_armors.size).each {|i|
  amount = stored_armor_number(i)
  gain_armor(i, amount)
   }
   @stored_items = {}
   @stored_weapons = {}
   @stored_armors = {}
 end
end

 

 

it will remove the equipped and add it to the stored equipment, but it will not re-equip them, that is up to the player respectively as its harder to account for them re-equipping stuff in the meantime :D

Edited by diagostimo

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...