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.

Storing items in variables (or just 1 script)

In regards to this topic: viewtopic.php?f=155&t=25871&p=252302&hilit=store+armor+in+variables#p252302

I would like to know if there is any way to store all of the items (including weapons and armor) in variables or would it be best in a script, and if it's best done in a script, then how can I enhance the script from the link above?
For example: if the player acquires 1 shield, 2 potions and 6 scrolls in chapter 1, then when chapter 2 starts, your previous inventory is stored (in a variable(s) or a script and you're starting out fresh and new again with no inventory. Then when chapter 3 starts, you get all of the previous inventory you acquired. I hope this makes sense...

I initially tried doing variables, but then I saw that you can't store armor or weapons in variables.. or is there just something I'm doing wrong..
 
How do you do this? There's no place to set how many types of armors or weapons you have. It's only for items:

28337003.jpg


As you can see, there's nothing in the variables section that deals with weapons and armor. Only items.
 
Yep. Crazy amounts of Conditional Branches would do it.

If Player 1 is Bronze Sword equipped, Variable (Player 1 Weapon)=1

If Player 1 is Iron Sword equipped, Variable (Player 1 Weapon)=2

Like that.
 
Try this... (paste above main)

Code:
#---------------------------------------------------------

# Store & Restore items - Brew

#

# $game_party.store_items

#   stores items & empties inventory

#

# $game_party.restore_items

#   restores stored items & adds them to current inventory

#---------------------------------------------------------

 

class Game_Party

  

  alias store_items_init initialize

  def initialize

    store_items_init

    @stored_items = [{},{},{}]

  end

  

  def store_items

    @stored_items[0] = @items

    @stored_items[1] = @weapons

    @stored_items[2] = @armors

    @items = {}

    @weapons = {}

    @armors = {}

  end

  

  def restore_items

    @stored_items[0].each_pair {|key, value| 

      gain_item(key, value)

    }

    @stored_items[1].each_pair {|key, value| 

      gain_weapon(key, value)

    }

    @stored_items[2].each_pair {|key, value| 

      gain_armor(key, value)

    }

  end

end

to use...

Code:
$game_party.store_items

$game_party.restore_items
 

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