08 November 2009

Victory Count Script

I was asked some time ago how to add a "Victory Count" - i.e. a counter for the number of battles won - so decided to experiment and this is the result. This is a very simple script modification, directly modifying various parts of the code.

Game_System
Under the Public Instance Variables, add the following:
attr_accessor :victory_count          # number of victories

Under initialize, add:
@victory_count = 0

Scene_Battle
Look for def display_exp_and_gold, place the following underneath $game_party.gain_gold(gold):
$game_system.victory_count += 1

Scene_Menu
In def start, add:
@victory_window = Window_Victory.new(0, 175)

In def terminate, add:
@victory_window.dispose

In def update, add:
@victory_window.update

Create a new entry, entitled Window_Victory, and paste the following code:
class Window_Victory < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(x, y)
super(x, y, 160, WLH + 32)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.size = 16
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
return if Graphics.frame_count % 10 != 0
self.contents.clear
self.contents.draw_text(0, WLH * 0, 120, WLH, "# Victories:")
self.contents.draw_text(0, WLH * 0, 120, WLH, $game_system.victory_count.to_s, 2)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
refresh
end
end

This will display the "# Victories" on the Status Menu. It can be expanded for other things as well, such as the number of saves, the number of inn stays, etc.

2 Comments So Far:

Anonymous said...

wouldn't it be better to alias the script, instead of modifying the default?

Companion Wulf said...

You're right, it would be. Although, admittedly, this is just a very basic method. I'm getting ready to update most of the scripts/scriptlets I have on here anyway. It's about that time! Thanks for commenting (and reminding me about aliasing!).

Post a Comment

Related Posts with Thumbnails
Template Design "Perfect World" by SkinCorner