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.

More Currencies (Very short)

More Currencies
Version: 1
By: MephistoX


Introduction

This Script allow your party to has more Currencies Types, you can customize the Initial quantity of these, the max that you can carry, the Currency name and the Icon.

Features
  • Easy to Use
  • No more :)

Script

It's very very short, I didn't put a Header, of my name or instrucctiosn or Sintax, Because its innecesary.

Code:
#==============================================================================

# ** Game_Party => Meph's New Currencies

#==============================================================================

 

class Game_Party

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

  # * Public Instance Variables

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

  attr_reader   :silver

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

  # * Alias Listing 

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

  alias_method  :meph_curry_gprty_init,  :initialize

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

  # * Object Initialization

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

  def initialize

    meph_curry_gprty_init

    @silver = {'Name' => 'Plata', 'Value' => 0, 'Max' => 1000, 'Icon' => '001-Weapon01'}

  end

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

  # * Get Currency

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

  def gain(currency, n)

    # eval the string, this was made to get each defined currency

    s  = "@#{(c = currency.downcase)}['Value'] ="

    s += "[[@#{c}['Value'] + n, 0].max, @#{c}['Max']].min"

    eval(s)

  end

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

  # * Lose Currency

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

  def lose(currency, n)

    # use the gain method, in a reverse mode with a -integer

    gain(currency, -n)

  end

end

Instructions

To create your new currencies:

1. Create a Instance Variable, after my alias:

Example:

Code:
@currency = {'Name' => 'Name', 'Value' => 0, 'Max' => 1000, 'Icon' => '001-Weapon01'}

 

'Currency' => Your currency Name

'Name' => In-Game Currency Name

'Value' => Initial Currency Quantity

'Max' => Max of the currency that party can carry

'Icon' => In-Game Icon (I didn't give a real use to this...use your brain :)

 

<span style="color:#996600;"

2. Public your Currency as a Instance Variable.
Code:
attr_reader   :yourcurrency_name

Remember that the Currency name, and this must be the same.

That's All, now if you want to gain X quantity of your new currency, use:
Code:
$game_party.gain('YourCurrencyName', quantity)

If you Want to show your currency in a window, use:

Code:
self.contents.draw_text(x, y, w, h, $game_party."currency"['Value'].to_s)

I explain in a Quick Form, for Advanced Users, If you need Help with this, I can give the trick :).


Compatibility

Work With everything......I guess..

Credits and Thanks

No credit Required, but you can't say that you made it!. :box:

Thats All!
 
Actually, using:

Code:
self.contents.draw_text(x, y, w, h, $game_party."currency".to_s
(assuming they actually change "currency" to the actual instance name defined in the attr_reader method should return all the data (name, value, max, etc.)

Right idea, but not how I would have went about it. I suggest setting up a module, and making constant values to setup everything (currency names, start value, etc.)
Code:
module Currencies

  Names = {

    0 => 'Currency Name',

    1 => 'Currency Name', 

    # ...

  }

  Start_Values = {

    0 => 0,

    1 => 100, 

    # ...

  }

  # ...

end

From here, I would setup Game_Party methods to gain currency based off an id value (ids are the keys in your constant setup).

Code:
class Game_Party

  def initialize

    # aliased method

    @currencies = {}

    Currencies::Start_Values.each {|id, n| @currencies[id] = n}

    @currencies.default = 0

  end

  def currency_value(id)

    return @currencies[id]

  end

  def gain_currency(id, n)

    @currencies[id] = @currencies[id] + n

  end

  def lose_currency(id, n)

    gain_currency(id, -n)

  end

end

To get names and such now, you just have to use Currency::Names[id] and things like that.


Once again, not trying to tear apart the script you made, just lending a hand and hoping to make you into a better scripter. Good to see you scripting. Keep it up. :thumb:
 
I love the Tips and Suggerences by the Masters.

About the first suggestion I forgot about that, because I copy this from another forum(This is a 2 months old Script), yes, the code to display the currency is:

Code:
$game_party.silver['Value'].to_s
_____
Yes, I love the modules, but in this case I saw this code like a minimini script, not enough bigger to make a module, so I ignored the idea.

I will take your examples and I check them, maybe i can use for other things, and also I will check my script, for now :shades:
__

Thanks again for the tips, i really appreciate that. :cheers:
 
Two things I'd like to comment here...

1st, 'gain' and 'lose' aren't just uninformative about the method's functions (that's a beauty error and not really bad), but also (now here comes the bad part) very likely to be included in another script. You should name them something like 'gain_currency' and 'lose_currency' IMO.

2nd, when I read your hash setup, I thought you had some cool ideas there... like the value thing. Later, I realized you didn't include what I thought you did, but instead just made that the starting money amount XD
I think you should include some kind of exchanging system, so that for example, you define every currency by the value of 1 unit of $game_party.gold, aka the default currency. So for example, one unit of @bronze is worth 5, @silver is 12 and @gold (here I see complications arising with your attr_reader way of handling things) is worth 26.
Now when you enter a store that wants regular money (having different currencies makes you wanna have folks who just accept that currency, but I think you wanna have some generic merchants as well who just take everything you throw them), it'll automatically convert your $game_party.gold, @bronze, @silver and @goldencurrency to $game_party.gold using the value you assigned them, and maybe (now that'd make the script a little bit larger ^^) let you choose which ones you wanna sped on the desired article, maybe have you throw a bit of value away because you wanna buy something that costs 20, but you only have @goldencurrency with you.
To not completely forget about your starting money, you could add an additional value for that... I kinda like the idea of having folks not starting with jack in their pockets, so don't leave it out completely.

Ah well... not trying to make you work, just some thoughts crossing my mind while checking out the script ^^ Nice idea anyway, but like Seph said, would need a different approach to be perfectly efficient.

Keep up the good work.
 
I've been looking for a multiple currency script for a while now, and hopefully this will work out for me...

But I don't really understand how it works...(sorry, I'm not good with scripts)

Can I show all the currencies from the Menu? Let's say my currencies are Gold, Chips, and Pumpkins...could I have the amount of Gold, Chips, and Pumpkins all viewable at once from the main menu screen?

Can we make enemies drop different currencies? If so, how would I go about doing this?

Thanks in advance.
 
Both doesn't get covered by just this handling script. Instead, you'd have to slightly modify the default scripts for that.

The value display in Scene_Menu is done inside Window_Gold. You can increase the height there (fourth initialization value, note that XP uses 32px per line) and add additional lines in the refresh method, each time changing the y value (second display value). The problem here is that the window would be too tall to be displayed in Scene_Menu completely, so you'd have to sacrifice another window to display it completely.

For your second issue, sure you can do that, and with relatively low effort. What you'd have to do is modify a method within Scene_Battle (I think it's something with 5 in the end, but I really can't remember XPs battle system too well, being a VX scripter now ;) ) that gives you the treasures defined in the database. Now if you're fine with random currency drops, just make a random variable there ( random = rand(anInteger) ), followed by a case conditional asking for it's value, giving the respective currency afterwards. If you're not content with random drops, you'd need an additional variable holding some information about what money they should drop, etc. ... if you say you're not good with scripting, that might exceed your possibilities though.

Either way, that covers the basics really... if you want a complete script done, post it in Script Requests please.
 

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