Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gold Display Add-Ons
#1
Gold Display Add-Ons
by Mister C Major
Apr 30 2007

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Hi Everyone,
I thought it time that I share a lot of my Custom Scripts and RMXP Script Edits so that it may benefit the Creation Asylum Online Community since the community has helped me so much with many of my own problems. Please look forward to a lot of simple and advanced scripts from yours truly, hope you enjoy!

This script was made for the sole purpose of customization, a simple block of code made to make your game different from everyone else's. This code affects the Visuals within your Window in Scene_Menu which displays the Gold your Party currently has.

This script will have examples of the function "sprintf" which is used to add in commas separating every 3 digits, for example, "123,456,789," will show you how to make a unique scrolling effect shown in a few games, "Harvest Moon: A Wonderful Life" being the only one I can think of at this moment, where your Gold Scrolls from 0 to 1, 2, 3, ..., 999999999, and will have a few other basic ideas regarding bitmaps and text coloring explained in other areas of the community.

Before each method, I provide a small definition to what will be happening within the method, please scroll to the bottom for a full explanation.

Gold Window Add-Ons Script


Code Basics
This Window (as its original purpose) is supposed to be used in conjuntion with the Scene_Menu Class where it is not only created, but handled as well.
Within the Scene_Menu Class, it is created at

line 42:

Code:
@gold_window = Window_Gold.new

edited at,

line 43-44:

Code:
@gold_window.x = 0
@gold_window.y = 416

and has its update method called at,

line 85:

Code:
@gold_window.update



Code Explanation
As you activate The Menu Scene, Window_Gold is initialized and method refresh is called,
Code:
def initialize
  @gold = $game_party.gold
  @gold_temp = 0
  @ones = @gold %10
  @tens = @gold %100 / 10
  @hundreds = @gold % 1000 / 100
  @thousands = @gold % 10000 / 1000
  @ten_thousands = @gold % 100000 / 10000
  @hundred_thousands = @gold % 1000000 / 100000
  @millions = @gold % 10000000 / 1000000
  super(0, 0, 160, 76)    #Can be edited
  self.contents = Bitmap.new(width - 32, height - 32)
  self.contents.font.name = $defaultfontface    #Can be edited
  self.contents.font.size = $defaultfontsize    #Can be edited
  refresh
end

The refresh method can be broken down into two seperate purposes, drawing the gold string and drawing the gold bitmap.

Gold String
Code:
millions = @gold_temp / 1000000
  thousands = @gold_temp % 1000000 / 1000
  hundreds = @gold_temp % 1000
  if @gold_temp >= 1000000
    gold_text = sprintf("%d,%03d,%03d", millions, thousands, hundreds)
  elsif @gold_temp >= 1000
    gold_text = sprintf("%d,%03d", thousands, hundreds)
  else
    gold_text = sprintf("%d", hundreds)
  end
  self.contents.font.color = normal_color#Can be edited
  self.contents.draw_text(0, 16, 120, 32, gold_text, 2)#Can be edited
  self.contents.font.color = system_color#Can be edited
  self.contents.draw_text(32 + 4, 2, 120, 20, $data_system.words.gold, 0)#Can be edited



Gold Bitmap

Code:
bitmap = RPG::Cache.icon("Gold")#Can be edited
  self.contents.blt(0, 0, bitmap, Rect.new(0, 0, 24, 24), 255)

First I'll explain the Gold String. To be able to have some more control over the String, (in this case to put commas in between every 3 digits) I needed to break down every 3 digits, i do so by creating the millions, thousands, and hundreds variables.
Code:
millions = @gold_temp / 1000000
  thousands = @gold_temp % 1000000 / 1000
  hundreds = @gold_temp % 1000

I then use the function "sprintf" to put the variables in the shape and order I want them.
Code:
if @gold_temp >= 1000000
    gold_text = sprintf("%d,%03d,%03d", millions, thousands, hundreds)
  elsif @gold_temp >= 1000
    gold_text = sprintf("%d,%03d", thousands, hundreds)
  else
    gold_text = sprintf("%d", hundreds)
  end

If @gold_temp (the string i'm trying to print) is at least one million, I tell gold_text to equal a number millions, thousands with 3 zeros, and hundreds with 3 zeros. Note, if millions = 987, thousands = 654, and hundreds = 321, gold_text would equal "987,654,321". Now note, if the line rather read,

Code:
gold_text = sprinf{"%d,%d,%d", millions, thousands, hundreds}


and if million = 9, thousands = 87, and hundreds = 65, we would get gold_text ="9, 87, 65", instead of the desired "9,087,065". The same procedures are followed if @gold_temp is less then one million, but at least one thousand; however, note we are no longer accounting for the millions, and the same thing applies if @gold_temp is less then a thousand, only the hundreds are accounted for.

The Gold Bitmap is a standard function called block transfer or blt for short. It takes the file titled (in my case "Gold") from the Icon file of my RMXP game project, places the file at the coordinate (0,0) and copies the cells located at the coordinate (0,0) on the specified file, with a width and height of 24 x 24, with an opacity of 255 and pastes it on the window

The "update" Method

The update Method is called many times a second by the update method of Scene_Menu. Every time update is called, all the @gold_temp variables representing the digits get redefined, then starting in the ones place, the script checks to see if the @gold_temp ones digit equals the @gold ones digit, if so, the script moves on to the next digit until. If the digits do not equal, the @gold_temp digit gets incremented by one, and the window is refreshed to show the change just made. The update method is also returned, to prevent the program from moving onto the next digit. Once all of the @gold_temp digits equal the @gold digits, the script has finished.

Compatability
As long as no code you currently have omits the lines,
Code:
@gold_window = Window_Gold.new
  @gold_window.update

within the Scene_Menu Class, as well as completely changing the required parameters of the Window_Base.initialize method (which I dont see why anyone would) this code should face no problems since it relies on variables only found within its own class.

Thanks for reading, if you have any questions or comments (particularly how I can organize my posts to help you read/learn my script better) please feel free to let me know, and sorry for writing so much out of a very basic script. Happy Coding everyone ^^
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Display the Map Location Mister C Major 0 2,070 07-17-2007, 01:00 PM
Last Post: Mister C Major
  Gold converted to decimals Jadant 0 2,179 11-18-2006, 01:00 PM
Last Post: Jadant
  Gained item/gold window. Jimmie 0 2,202 08-28-2005, 01:00 PM
Last Post: Jimmie



Users browsing this thread: