Is there any way to track total currency earned in a save? I'm trying to create an achievement to award at 1000, 10'000, and 100'000 "G" but so far it only tracks the party's current "G".
Tracking total currency earned
RPG Maker MV SupportThe easiest way would be to create a parallel event that uses 3 variables.
A "Previous G", a "Delta G" representing the difference between current G and previous G, and an "Accumulated G" which is the total amount of G earned during the game.
When current G is greater than previous G, you set delta G to current G, then subtract previous G from it. This gives you the difference between current G and previous G. Then you Add the delta G to the accumulated G. Finally, you set the previous G to the value of current G.
That's pretty much all you need for a simple G tracking system.
You also might want to add a "Wait" command so your parallel event doesn't affect your game's performance too much.
Note that this system won't work inside of shops. So if the player sells stuff, then buys stuff, the system will only see the difference after the player is done. For example, if the player sells 1 million G worth of loot, then buys 800 000 G worth of equipment, the system will think that the player only earned 200 000 G instead of 1 million G.
For that, you would need a plugin.
A "Previous G", a "Delta G" representing the difference between current G and previous G, and an "Accumulated G" which is the total amount of G earned during the game.
When current G is greater than previous G, you set delta G to current G, then subtract previous G from it. This gives you the difference between current G and previous G. Then you Add the delta G to the accumulated G. Finally, you set the previous G to the value of current G.
That's pretty much all you need for a simple G tracking system.
You also might want to add a "Wait" command so your parallel event doesn't affect your game's performance too much.
Note that this system won't work inside of shops. So if the player sells stuff, then buys stuff, the system will only see the difference after the player is done. For example, if the player sells 1 million G worth of loot, then buys 800 000 G worth of equipment, the system will think that the player only earned 200 000 G instead of 1 million G.
For that, you would need a plugin.
So the game doesn't track "G" earned as it does battles, time and steps?
Good question. I checked the code, and no. The engine only keeps track of the party's current amount of gold.
This means you have to keep track of any changes in gold yourself. Either through eventing or using a plugin.
Hmmmm, well time for some logic based math events I suppose.
Code:
Game_Party.prototype.gainGold = function(amount) {
// New section
var variable_id = 1; // Change variable which will store the data here.
if (amount > 0) {
if (this._gold + amount > this.maxGold()) {
var add = this._gold + amount - this.maxGold();
} else {
var add = amount;
}
$gameVariables.setValue(variable_id, $gameVariables.value(variable_id) + add);
}
// Old section
this._gold = (this._gold + amount).clamp(0, this.maxGold());
};
You can copy paste this and save it as a js file. I didn't test it, but it should work. Just change the line with 'variable_id' to change which variable will store the data.
Original thread: https://forums.rpgmakerweb.com/threads/tracking-total-currency-earned.152547/