william7733

Villager
Member
Joined
Jul 7, 2019
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
I have been trying to find a way to find a way for my characters have their own money instead of sharing, and I have not been able to figure it out.

I am using this awesome plugin by Shiggy, which adds a world of warcraft style money display:

the plugin works great, but now I want to find a way store the money. The way it seems to work is simply display the money within menus in a different format, so if you have 158 currency, it shows 0 gold, 1 silver, 58 copper in both inventory and shop menus.
creating some variables linked to the currency as well as conditional branches works, I have made a way to successfully store the money, as demonstrated in this video:

however this method spits out the total number of money when the variable is read, and again that works, I could just have it read " your current bank amount is 15,842 \i[copper coin icon id]"
but I would much rather have it say " your current bank balance is 1 \i[gold icon id] 58 \i[silver icon id] 42 \i[copper icon id]" if there is a way to do this.

I feel like I am overlooking something, and that there is a way to make it display in the text bubble the way I want without creating endless condition branches calculating exactly how much money you have and spiting out the correct text bubble.

The only way I can imagine accomplishing this is by instead using yanfly's more currencies plugin and yanfly's item categories plugin instead of Shiggy's, making the coins items, giving them their own "currencies" item category in the inventory, and then having the bank system demonstrated in the video above check for each item amount in some way.

is there a way to have the system take the total amount of money you have, subtract 10,000 from it until it cannot anymore, and use the number of times it was able to subtract to show how many gold coins you have, then move on and do the same with the silver and copper?

If anybody has any ideas or suggestions I would be extremely grateful, I have been stuck on this for awhile now.
 

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
133
Reaction score
95
First Language
English
Primarily Uses
RMMZ
While loops can do that, using variables for each denomination, plus one for temporary use in the loop, so that you don't actually change your money amount. Should be doable with event commands.

Basically set your temp variable to 0, and start the first loop, checking to see if (for example gold) your temp variable * 10,000 > the full money amount, if yes, set the gold variable to the temp variable - 1 and break the loop, if no, increase the temp variable by 1.

Then do that again for each denomination until done. Run the sequence every time you need to display the message, and have the message display each denomination in sequence. If you don't want gold showing if you don't have any, use branches to only display a currency type if you actually have it.
 

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,834
Reaction score
2,335
First Language
English
Primarily Uses
RMMZ
Something like this should work in a script call if I understand what you're asking.

JavaScript:
var gold = String(15842).padZero(5);  // Make sure number string is at least 5 characters
var copper = gold.slice(-2);  // Slice off last 2 to get copper value
gold = gold.slice(0, -2);  // Truncate last two characters from gold
var silver = gold.slice(-2);  // Slice off last 2 to get silver value
gold = gold.slice(0, -2)  // Truncate last two characters from gold. What remains is the gold value.

$gameVariables.setValue(1, ~~gold);    // Set variable 1 to gold value
$gameVariables.setValue(2, ~~silver);  // Set variable 2 to silver value
$gameVariables.setValue(3, ~~copper);  // Set variable 3 to copper value
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,153
Reaction score
14,652
First Language
English
Primarily Uses
RMMV
[move]Plugin Support[/move]
 

william7733

Villager
Member
Joined
Jul 7, 2019
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
While loops can do that, using variables for each denomination, plus one for temporary use in the loop, so that you don't actually change your money amount. Should be doable with event commands.

Basically set your temp variable to 0, and start the first loop, checking to see if (for example gold) your temp variable * 10,000 > the full money amount, if yes, set the gold variable to the temp variable - 1 and break the loop, if no, increase the temp variable by 1.

Then do that again for each denomination until done. Run the sequence every time you need to display the message, and have the message display each denomination in sequence. If you don't want gold showing if you don't have any, use branches to only display a currency type if you actually have it.
Thank you for the reply! I'm not too great with the finer details of RPG maker or working with variables, so I don't quite understand how to accomplish this.


Something like this should work in a script call if I understand what you're asking.

JavaScript:
var gold = String(15842).padZero(5);  // Make sure number string is at least 5 characters
var copper = gold.slice(-2);  // Slice off last 2 to get copper value
gold = gold.slice(0, -2);  // Truncate last two characters from gold
var silver = gold.slice(-2);  // Slice off last 2 to get silver value
gold = gold.slice(0, -2)  // Truncate last two characters from gold. What remains is the gold value.

$gameVariables.setValue(1, ~~gold);    // Set variable 1 to gold value
$gameVariables.setValue(2, ~~silver);  // Set variable 2 to silver value
$gameVariables.setValue(3, ~~copper);  // Set variable 3 to copper value
Thank you for the reply! I checked out some of your plugins, they look really great! I'm going to look into them further once my project is a bit more developed.

This looks exactly like what I need, though i'm not great with the scripting aspects of RPG maker. I believe I understand what is happening here, though I don't quite know how to use this.
I set up variables to be linked with the amounts, then I changed the numbers to match up with my variables, so it reads:

$gameVariables.setValue(44, ~~gold); // Set variable 1 to gold value
$gameVariables.setValue(45, ~~silver); // Set variable 2 to silver value
$gameVariables.setValue(46, ~~copper); // Set variable 3 to copper value


I set up a simple event that runs the script then displays a text bubble with the variables in it. it displays \v[44] \v[45] \v[46] as 1 58 42, which is exactly what I am looking for. But I'm not sure how to get this value to reflect the current money I have, or the amount stored. The only way i can imagine making this work with my limited understanding of scripting is having a common event that is near endless, full of condition branches saying:
IF money = 1 THEN =javascript]var gold = String(00001).padZero(5);... (rest of script)
IF money = 2 THEN =javascript]var gold = String(00002).padZero(5);... (rest of script)
and so on, that can't be how I have to do this, right?
 
Last edited:

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
133
Reaction score
95
First Language
English
Primarily Uses
RMMZ
Thank you for the reply! I'm not too great with the finer details of RPG maker or working with variables, so I don't quite understand how to accomplish this.



Thank you for the reply! I checked out some of your plugins, they look really great! I'm going to look into them further once my project is a bit more developed.

This looks exactly like what I need, though i'm not great with the scripting aspects of RPG maker. I believe I understand what is happening here, though I don't quite know how to use this.
I set up variables to be linked with the amounts, then I changed the numbers to match up with my variables, so it reads:

$gameVariables.setValue(44, ~~gold); // Set variable 1 to gold value
$gameVariables.setValue(45, ~~silver); // Set variable 2 to silver value
$gameVariables.setValue(46, ~~copper); // Set variable 3 to copper value


I set up a simple event that runs the script then displays a text bubble with the variables in it. it displays \v[44] \v[45] \v[46] as 1 58 42, which is exactly what I am looking for. But I'm not sure how to get this value to reflect the current money I have, or the amount stored. The only way i can imagine making this work with my limited understanding of scripting is having a common event that is near endless, full of condition branches saying:
IF money = 1 THEN
JavaScript:
var gold = String(00001).padZero(5);... (rest of script)
IF money = 2 THEN [CODE=javascript]var gold = String(00002).padZero(5);... (rest of script)
and so on, that can't be how I have to do this, right?
It's fine, Frogboy's method is a lot more concise than mine anyway. Running a bunch of loops is... not ideal when simpler alternatives exist.

As for his method, if I'm reading right (I'm still learning some of the finer points of scripting myself) the amount of gold you have needs to go into the string(xx) part at the beginning. If it's for the amount held by the party, sticking $gameParty.gold there should do it. For stored gold separate from party gold, if that's stored in a variable, you'd stick $gameVariables.value(x) there instead, where x is the variable number you're using.

JavaScript:
var gold = String($gameParty.gold).padZero(5);
or
JavaScript:
var gold = String($gameVariables.value(95)).padZero(5); //change 95 to stored money's variable

This way it automatically fetches the value and puts it into the function.
 

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
133
Reaction score
95
First Language
English
Primarily Uses
RMMZ
I'll try to break it down so you can understand exactly what's going on. I'm assuming based on my own limited programming knowledge and haven't used this myself, I'm mostly going off context clues.
The String() function takes the value in the () and turns it into a string (string is basically text in programming, if you didn't already know that). The ".padZero(5)" basically adds zeros if the value is less than 5 digits. This means if you put 55 in the string() part, with .padZero(5) the actual string would read "00055". This ensures that the string is long enough to eventually chop 4 digits off.
The slice function is pretty easy to figure out what it does, but without playing with it, I'm not sure exactly HOW to use it properly. Obviously he's using the -2 to trim 2 digits off the end.

Hope that helps you understand what the function is doing and why you shouldn't need any conditional branching for this!
 

william7733

Villager
Member
Joined
Jul 7, 2019
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
I'll try to break it down so you can understand exactly what's going on. I'm assuming based on my own limited programming knowledge and haven't used this myself, I'm mostly going off context clues.
The String() function takes the value in the () and turns it into a string (string is basically text in programming, if you didn't already know that). The ".padZero(5)" basically adds zeros if the value is less than 5 digits. This means if you put 55 in the string() part, with .padZero(5) the actual string would read "00055". This ensures that the string is long enough to eventually chop 4 digits off.
The slice function is pretty easy to figure out what it does, but without playing with it, I'm not sure exactly HOW to use it properly. Obviously he's using the -2 to trim 2 digits off the end.

Hope that helps you understand what the function is doing and why you shouldn't need any conditional branching for this!

Thank you, this information is very helpful! I definitely understand a lot more of what is going on now. Many thanks friend.

var gold = String($gameParty.gold).padZero(5);

Unfortunately when I use this the variables come up as 0 0 0. The party gold should be 0 13 58, as that's the amount I gave the character to test this script.

Edit: maybe I have a plugin that messes with gold? I will look though them and see, but I don't think I have any that directly effect gold other that Shiggy's plugin which as far as I can tell just effects how money is displayed in menus.
 

william7733

Villager
Member
Joined
Jul 7, 2019
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
Thank you Drakkonis and Frogboy, I figured it out. I can't say why using $gameParty.gold came up with 0 0 0, but I found that if I assign a variable to equal gold, then use $gameVariables.value(x) instead to run the script it works great! I seriously cannot thank you both enough, I never could have figured this out on my own.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
929
Reaction score
492
First Language
English
Primarily Uses
RMMV
var gold = String($gameParty.gold).padZero(5);
The .gold is a member function, not a variable. Therefore, it needs parentheses for the function call.
Code:
var gold = String($gameParty.gold()).padZero(5);
 

Latest Threads

Latest Profile Posts

Ami
tomorrow is the finale of my Endurance
2dfloor.png
What a fun tileset I've got here so far!
Minecraft Tiles, Maid Day, Custom Menu, Retry at GameOver, Save in Appdata | RPG Maker News #36

side view special bust.png
Reworking the art for the 'special busts' in important game dialogue. Potentially replacing the more 'dead-on' look of the original:
original.png
Me: Imma work on my game! Let's get some progress done
Me, five minutes later smoking a cigarette: *screams into the void*

Forum statistics

Threads
111,262
Messages
1,059,670
Members
144,545
Latest member
Drachiel
Top