Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: Reno-s--Joker on February 21, 2009, 12:34:46 am

Title: Dollars and Cents Script Code Snippet
Post by: Reno-s--Joker on February 21, 2009, 12:34:46 am
Here is a little code snippet thing that could be useful if you want to use dollars and cents format for your game:

Wherever you see:
self.contents.draw_text(x, y, width, height, @gold.to_s)

You can replace @gold.to_s with:
format("$%.2f", (@gold/100).to_s)


e.g. 300G becomes $3.00, 495059 gold becomes $4950.59.

Note that the above code treats 1 standard G as being 1 cent in dividing it by 100. This way, you can sell items for $9.99 like in the real shops! :V:

If you want whole dollars (which is kinda pointless) just change the code to:
format("$%.2f", @gold.to_s)


If you want to omit the $ sign, change to:
format("%.2f", (@gold/100).to_s)


Credits:
This Discussion on Ruby-Forum (http://www.ruby-forum.com/topic/89085)
Title: Re: Dollars and Cents Script Code Snippet
Post by: Holyrapid on April 02, 2009, 02:58:52 am
Nice. I may use this in my game ;) power up
Title: Re: Dollars and Cents Script Code Snippet
Post by: Reno-s--Joker on April 02, 2009, 05:39:09 am
:) Thank you! I really appreciate it, and I'm glad you found it remotely useful!
Title: Re: Dollars and Cents Script Code Snippet
Post by: RoseSkye on April 02, 2009, 06:28:29 pm
Quote from: Reno-s--Joker on April 02, 2009, 05:39:09 am
:) Thank you! I really appreciate it, and I'm glad you found it remotely useful!


*pets* Good boy *pets* Who wants a cookie? YOU DO! Who's an awesome scripter? YOU ARE!! *pets and rubs belly*
Title: Re: Dollars and Cents Script Code Snippet
Post by: Reno-s--Joker on April 03, 2009, 09:43:44 am
:3 Aww, thank you Rose! :D
I couldn't say I'm an awesome scripter just yet though. o_O Although I wish I was. ;___;
Title: Re: Dollars and Cents Script Code Snippet
Post by: meyvn MaRa on August 20, 2009, 10:14:18 am
I know this might be necroposting, but I tried this script and it didn't work. When I start the game, it says something about line 24. It contains:
self.contents.font.color = system_color


I'm a n00b at scripting, so I don't know what's up with the script.

//Oh, and I'm using XP, not VX.
Title: Re: Dollars and Cents Script Code Snippet
Post by: Aqua on August 20, 2009, 02:03:49 pm
Are you using the official RMXP or Dyna or PK or whatever it's called? xD
Title: Re: Dollars and Cents Script Code Snippet
Post by: meyvn MaRa on August 20, 2009, 02:31:56 pm
I'm using the official version.
Title: Re: Dollars and Cents Script Code Snippet
Post by: fugibo on August 20, 2009, 04:12:03 pm
Quote from: meyvn MaRa on August 20, 2009, 10:14:18 am
I know this might be necroposting, but I tried this script and it didn't work. When I start the game, it says something about line 24. It contains:
self.contents.font.color = system_color


I'm a n00b at scripting, so I don't know what's up with the script.

//Oh, and I'm using XP, not VX.


First, make sure you have the scripts in the right order.

And if that doesn't fix it, post the actual error and the scripts you're using (in the order they are in the Script editor).
Title: Re: Dollars and Cents Script Code Snippet
Post by: meyvn MaRa on August 23, 2009, 08:31:19 am
Right order? What do you mean "right order"? The instuctions say that all I have to do is to change a part of a line of a script called "Window_Gold".

Well, I'll post the script as how I wrote it:

#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  This window displays amount of gold.
#==============================================================================

class Window_Gold < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
   super(0, 0, 160, 64)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def refresh
   self.contents.clear
   cx = contents.text_size($data_system.words.gold).width
   self.contents.font.color = normal_color
   self.contents.draw_text(4, 0, 120-cx-2, 32, format("%.2f", (@gold/100).to_s)
   self.contents.font.color = system_color
   self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
 end
end
Title: Re: Dollars and Cents Script Code Snippet
Post by: meyvn MaRa on September 04, 2009, 11:32:21 am
####   #        #  ##        ##  ####
#     #  #        #  #  #    #  #  #     #
####   #        #  #    ##    #  ####
#     #  #        #  #            #  #
####     ####    #            #  #
Title: Re: Dollars and Cents Script Code Snippet
Post by: Blizzard on September 04, 2009, 11:48:50 am
The right order (http://forum.chaos-project.com/index.php?topic=23.0)
Title: Re: Dollars and Cents Script Code Snippet
Post by: meyvn MaRa on September 05, 2009, 05:00:01 am
Um, how was that supposed to help?
Title: Re: Dollars and Cents Script Code Snippet
Post by: Blizzard on September 05, 2009, 07:21:58 am
Quote from: meyvn MaRa on August 23, 2009, 08:31:19 am
Right order? What do you mean "right order"?
Title: Re: Dollars and Cents Script Code Snippet
Post by: meyvn MaRa on September 05, 2009, 10:54:43 am
Oh yeah, I forgot. But, the right order has nothing to do with this, 'cuz I only replaced a one line of a default script called "Window_Gold".
Title: Re: Dollars and Cents Script Code Snippet
Post by: Blizzard on September 06, 2009, 04:41:05 am
No problem. Just making sure, lol!
Title: Re: Dollars and Cents Script Code Snippet
Post by: meyvn MaRa on September 07, 2009, 12:09:46 pm
Quote from: Blizzard on September 06, 2009, 04:41:05 am
No problem. Just making sure, lol!

:...:

Well, can anyone help me please? I'm a :n00b: at scripting, so I have no idea of what I'm suposed to do...
Title: Re: Dollars and Cents Script Code Snippet
Post by: Jackolas on September 08, 2009, 02:47:18 am
you did:
    self.contents.draw_text(4, 0, 120-cx-2, 32, format("%.2f", (@gold/100).to_s)


change it to:
    self.contents.draw_text(4, 0, 120-cx-2, 32, format("%.2f", (@gold/100).to_s))


remember that you have the same amount of ) as of (
Title: Re: Dollars and Cents Script Code Snippet
Post by: meyvn MaRa on September 08, 2009, 01:53:52 pm
Now it gives me an error message of that line:

QuoteScript "Window_Gold" line 23: NoMethodError occured.

undefined mathed `/" for nil:NilClass
Title: Re: Dollars and Cents Script Code Snippet
Post by: Jackolas on September 08, 2009, 08:04:35 pm
been looking at this for over an hour and i have the feeling that this Snippet will only apply to 1-2 specific menu systems.

the first reason i have for this is that in WHOLE rmxp "@gold.to_s" can not be found.
the only rule there can be found that seems close is: "self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)" in window_gold

so I want to know who got this 1 to work and if they can post there script.
Title: Re: Dollars and Cents Script Code Snippet
Post by: Aqua on September 08, 2009, 08:08:19 pm
There are 2 instances of @gold.to_s in Window_BattleResult :P

And yeah, you can just use $game_party.gold.to_s instead