Decimal Currency

Status
Not open for further replies.

sutorumie

I'm a whimsical girl.
Veteran
Joined
Apr 26, 2014
Messages
30
Reaction score
1
First Language
English
Primarily Uses
RMMV
Would it be possible to change the way money is displayed from, say, 1,000G to $10.00 ? Preferrably so it displays on the menu screen and the shop screen. There were a few scriplets like this for VXAce (here's one), to make it so the last two digits are behind a period and the currency symbol is displayed to the left of the numbers. I suppose this would also mean I'd need to replace the icon with text, but I could also just draw a dollar sign as an icon, so, that's not a big deal.

I've looked all over and attempted to do it myself but I don't quite understand javascript yet and I haven't found anything by googling or searching these forums.


 

robhav

Veteran
Veteran
Joined
Jan 31, 2018
Messages
49
Reaction score
16
First Language
English
Primarily Uses
RMMV
This script will allow you to create decimal variables that you can use to add to the party's gold. For example you can set the decimal value at 7.98 and the party gold will display as $7.98 and will display the same way in a shop. Or if you just add a whole number value like 10, it will display as $10.00. To use the dollar sign you just put it in the currency section under system in the database. Just copy the code into notepad and save it as a .js file in your plugin folder and activate it in the editor. One thing it won't do is set shop prices with decimals.


(function() {

Game_Party.prototype.gold = function() {
return parseFloat(Math.round(this._gold * 100) / 100).toFixed(2);
};

Game_Variables.prototype.setValue = function(variableId, value) {
if (variableId > 0 && variableId < $dataSystem.variables.length) {
this._data[variableId] = value;
this.onChange();
}
};

Window_Gold.prototype.refresh = function() {
var x = this.textPadding();
var width = this.contents.width - this.textPadding() * 2;
this.contents.clear();
this.drawCurrencyValue(this.currencyUnit(), this.value(), x, 0, width);
};

})();
 

sutorumie

I'm a whimsical girl.
Veteran
Joined
Apr 26, 2014
Messages
30
Reaction score
1
First Language
English
Primarily Uses
RMMV
This works pretty well, thank you !<3

Would it be possible to get the shopbuy / shopsell windows to display in decimals, and for items to cost less than a dollar (ex. $0.50)? Maybe a notetag or something?

EDIT: After doing some more testing I've discovered that this script interferes with my ability to work with other variables unrelated to gold variables. More specifically, I'm using Orange Time System and the variable to change time (in minutes, haven't tested hours or days yet but I have no reason to believe it's any different) no longer works with this plugin installed. It just resets to the old value from before I tried to change it. I'm assuming this has something to do with the Game_Variables.prototype.setValue function but I don't know what to do with it because I don't even really know what it's doing ?
 
Last edited:

sutorumie

I'm a whimsical girl.
Veteran
Joined
Apr 26, 2014
Messages
30
Reaction score
1
First Language
English
Primarily Uses
RMMV

robhav

Veteran
Veteran
Joined
Jan 31, 2018
Messages
49
Reaction score
16
First Language
English
Primarily Uses
RMMV
Hi. Sorry. Got busy. I played around with it and seems to be working, though it's not perfect. Dollar sign is on the wrong side of buy and sell price, but you can use prices less than whole numbers. I took out the variable part. If you want to give the party other than whole number amounts of money you'll have to use the script call $gameParty.gainGold(0.99) or whatever amount. For item prices, use the note tag
<price: 0.99>
I haven't tested it extensively but I've done buys and sells of items and weapons of various decimal prices with no problems. Here's the new script.

(function() {

Game_Party.prototype.gainGold = function(amount) {
this._gold = this._gold + amount //parseFloat(Math.round(amount * 100) / 100).toFixed(2);
};

Game_Party.prototype.gold = function() {
return parseFloat(Math.round(this._gold * 100) / 100).toFixed(2);
};

Window_Gold.prototype.refresh = function() {
var x = this.textPadding();
var width = this.contents.width - this.textPadding() * 2;
this.contents.clear();
this.drawCurrencyValue(this.currencyUnit(), this.value(), x, 0, width);
};

Scene_Shop.prototype.buyingPrice = function() {
if (this._item.meta.price) {
return this._item.meta.price;
} else {
return this._buyWindow.price(this._item);
}

};

Scene_Shop.prototype.money = function() {
return Number(this._goldWindow.value());
};

Scene_Shop.prototype.sellingPrice = function() {
if (this._item.meta.price) {
return this._item.meta.price;
} else {
return this._buyWindow.price(this._item);
}
};

Window_ShopBuy.prototype.price = function(item) {
if (item.meta.price) {
return item.meta.price;
} else {
return this._price[this._data.indexOf(item)] || 0;
}

};

Window_ShopBuy.prototype.isEnabled = function(item) {
return (item && this.price(item) <= this._money &&
!$gameParty.hasMaxItems(item));
};

})();
 

sutorumie

I'm a whimsical girl.
Veteran
Joined
Apr 26, 2014
Messages
30
Reaction score
1
First Language
English
Primarily Uses
RMMV
Ah, perfect ! Although I actually can't get a currency unit to display in shopbuy / shopsell at all? Is there supposed to be one there? It doesn't show in a new project either, and I've been trying to write one in but it doesn't seem to work orz

Oh, also I added this onto the end to have the script affect Window_ShopNumber as well:

Window_ShopNumber.prototype.drawTotalPrice = function() {
var total = parseFloat(((this._price * 100) * this._number) / 100).toFixed(2);
var width = this.contentsWidth() - this.textPadding();
this.drawCurrencyValue(this._currencyUnit, total, 0, this.priceY(), width);
};


 

robhav

Veteran
Veteran
Joined
Jan 31, 2018
Messages
49
Reaction score
16
First Language
English
Primarily Uses
RMMV
No, the currency unit only shows up on the number window, which you've fixed with the code you added. Glad it worked for you.
 

sutorumie

I'm a whimsical girl.
Veteran
Joined
Apr 26, 2014
Messages
30
Reaction score
1
First Language
English
Primarily Uses
RMMV
AH okay . Thank you for all your help !
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,323
Reaction score
8,521
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just finished composing a boss battle theme!
Scripted a multi-variable weather system that randomizes wind speed, cloudiness, rain, fogginess, etc, while attempting to realistically account for interactions between them (e.g. wind speed affects fogginess, cloudiness affects rain, etc), the current weather pattern, and the player's biome e.g. swamp, beach, etc. Now I "just" have to tie visuals and sounds to the variables so stuff actually happens...
I'm having a headache balancing the combat using flat defense so I'm gonna use percentual armor, in this pic, Simon has 16 on Defense which means all the incoming damage will be reduced by 16% this will ease my burden a bit.
!Have a nice day everybody¡
SO glad they patched outer worlds for switch! I can finally play it! Weird that other peeps are still having issues. I know it was really chugging on my lite when it first came out.

Forum statistics

Threads
105,556
Messages
1,014,636
Members
137,234
Latest member
kotanimi
Top