Bob423 52 Report post Posted September 21, 2012 (edited) 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 September 22, 2012 by Bob423 Share this post Link to post Share on other sites
0 diagostimo 11 Report post Posted September 21, 2012 (edited) 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 September 21, 2012 by diagostimo Share this post Link to post Share on other sites
0 Bob423 52 Report post Posted September 21, 2012 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 diagostimo 11 Report post Posted September 21, 2012 (edited) 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 September 21, 2012 by diagostimo Share this post Link to post Share on other sites
0 Bob423 52 Report post Posted September 21, 2012 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 diagostimo 11 Report post Posted September 21, 2012 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 Bob423 52 Report post Posted September 21, 2012 it works perfectly with no extra scripts, so something is clashing. i'll send you a pm with the project. Share this post Link to post Share on other sites
0 diagostimo 11 Report post Posted September 21, 2012 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 Bob423 52 Report post Posted September 21, 2012 that was the problem :D but now, there's a new problem. it doesnt touch the player's equipment. Share this post Link to post Share on other sites
0 diagostimo 11 Report post Posted September 22, 2012 by that do you mean currently equiped? if so i didn't account for that, ill get onto it Share this post Link to post Share on other sites
0 Bob423 52 Report post Posted September 22, 2012 yea that's what i meant, thanks Share this post Link to post Share on other sites
0 diagostimo 11 Report post Posted September 22, 2012 (edited) 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 September 22, 2012 by diagostimo 1 Bob423 reacted to this Share this post Link to post Share on other sites
0 Bob423 52 Report post Posted September 22, 2012 thanks, it works :D now to completely re-play test everything i've worked on, for like the 10th time Share this post Link to post Share on other sites
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 Bob423Share this post
Link to post
Share on other sites