Decimal Currency

Discussion in 'JS Plugin Requests' started by sutorumie, Jul 27, 2018.

Thread Status:
Not open for further replies.
  1. sutorumie

    sutorumie I'm a whimsical girl. Veteran

    Messages:
    30
    Likes Received:
    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.


    [​IMG]
     
    #1
  2. robhav

    robhav Veteran Veteran

    Messages:
    49
    Likes Received:
    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);
    };

    })();
     
    #2
    sutorumie likes this.
  3. sutorumie

    sutorumie I'm a whimsical girl. Veteran

    Messages:
    30
    Likes Received:
    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: Jul 29, 2018
    #3
  4. sutorumie

    sutorumie I'm a whimsical girl. Veteran

    Messages:
    30
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMMV
    Bump !
     
    #4
  5. robhav

    robhav Veteran Veteran

    Messages:
    49
    Likes Received:
    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));
    };

    })();
     
    #5
    sutorumie likes this.
  6. sutorumie

    sutorumie I'm a whimsical girl. Veteran

    Messages:
    30
    Likes Received:
    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);
    };

    [​IMG]
    [​IMG]
     
    #6
    robhav likes this.
  7. robhav

    robhav Veteran Veteran

    Messages:
    49
    Likes Received:
    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.
     
    #7
  8. sutorumie

    sutorumie I'm a whimsical girl. Veteran

    Messages:
    30
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMMV
    AH okay . Thank you for all your help !
     
    #8
  9. mlogan

    mlogan Global Moderators Global Mod

    Messages:
    13,888
    Likes Received:
    7,677
    Location:
    Texas
    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.

     
    #9
Thread Status:
Not open for further replies.

Share This Page