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.

[Resolved]Removing ALL items/equipment from the player's inventory with a Call Script

Status
Not open for further replies.
is it possible to remove the entire inventory of the player along with all the equipment that is equipped with a simple Call Script command? Instead of sitting here for an hour creating a huge event that removes each item one at a time with individual event commands? If so, could someone show me the script to do so?

Please and thank you!
 
Add this in a new script above main

Code:
class Game_Party
  def remove_all_items
    @items.clear
    @weapons.clear
    @armors.clear
  end
end

Now you can do this in a call script

Code:
$game_party.remove_all_items
 
=/ it doesnt work, when i called the script $game_party.remove_all_items, it gave me this error:

Script 'Remove_all_items' line 5:NoMethodError occured.
undefined method 'clear' for nil:NilClass


line 5 is @armor.clear
any idea how to fix this?


EDIT: Found the error, its @armors.clear, not @armor.clear :P thank you for the help!
 

Mea

Member

Related question: is there a way to remove everything, kind of like what you have here, but remember it somehow so that you can eventually restock the character with everything they gained thus far?

Example: The party gets thrown into prison for a time. They escape, and find their stuff stockpiled in a storeroom on the way out.
 
Code:
class Game_Party
  def remove_all_items
    @remembered_items = @items.dup, @weapons.dup, @armors.dup
    @items.clear
    @weapons.clear
    @armors.clear
  end
  def restore_all_items
    @items, @weapons, @armors = @remembered_items if @remembered_items != nil
    @remembered_items = nil
  end
end

In addition to the above post to regain all items just do

$game_party.restore_all_items

Do note however if any items were gained during the removal and recovery they will be lost, just reply if you don't want this to happen its an easy edit of what I have now
 
Code:
class Game_Party
  def remove_all_items
    @remembered_items = @items.dup, @weapons.dup, @armors.dup
    @items.clear
    @weapons.clear
    @armors.clear
  end
  def restore_all_items
    items, weapons, armors = @remembered_items if @remembered_items != nil
    items.each {|item_id, amount| @items[item_id] += amount} 
    weapons.each {|item_id, amount| @weapons[item_id] += amount} 
    armors.each {|item_id, amount| @armors[item_id] += amount} 
    @remembered_items = nil
  end
end

Same instructions if it gives you any trouble let me know
 

Mea

Member

Getting an error:
"script 'remove all items' line 13 NoMethodError occured.
Undefined method '+' for nil:NilClass"

BTW: This happens when I call the "$game_party.restore_all_items" command.
 
Silly default scripts not making use of Hash.default=

Trickster;179228 said:
Code:
class Game_Party
  alias_method :trick_removal_party_initialize, :initialize
  def initialize
    trick_removal_party_initialize
    @items.default = 0
    @weapons.default = 0
    @armors.default = 0
  end
  def remove_all_items
    @remembered_items = @items.dup, @weapons.dup, @armors.dup
    @items.clear
    @weapons.clear
    @armors.clear
  end
  def restore_all_items
    items, weapons, armors = @remembered_items if @remembered_items != nil
    items.each {|item_id, amount| @items[item_id] += amount} 
    weapons.each {|item_id, amount| @weapons[item_id] += amount} 
    armors.each {|item_id, amount| @armors[item_id] += amount} 
    @remembered_items = nil
  end
end

If it gives you any more trouble let me know
 
Status
Not open for further replies.

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