Skip to content

Instantly share code, notes, and snippets.

@AdamKyle
Last active December 20, 2015 01:09
Show Gist options
  • Save AdamKyle/6046633 to your computer and use it in GitHub Desktop.
Save AdamKyle/6046633 to your computer and use it in GitHub Desktop.
This script is designed to allow you to create custom currencies
#==============================================================================
# Currency Generator!
# ----------------------------------------------------------------------------
# Version: 1.0.2
# Author: Kalacious (AKA: VindictivePersonality)
# License: GPL 3.0
#
# Changes 1.0.1
# ----------------------------------------------------------------------------
# ---> Fixed issue with windows.
# ---> Now a default part of the menu as the last option.
# (see bottom of header for more info.)
#
# Changes 1.0.2
# ----------------------------------------------------------------------------
# ---> Aligned text in the description window.
# ---> You can now have a bit more of a discription.
#
# Compatibillity Issues
# ----------------------------------------------------------------------------
#
# There should be NO compatibillity issues what so ever. How ever if there are,
# Please let me know.
#
# TOS
# ----------------------------------------------------------------------------
# If you know the GPL version 3, you know the answer, but this still applies:
#
# Script for RGSS 3 ONLY adds abillity to generate currencies.
# Copyright (C) 2013 Kalacious (AKA VindictivePersonality)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
#
#==============================================================================
#
# How to Use?
# -----------
#
# You have one main object for messing with currencies: $kc_currency, We will
# get into what this object does and how to efectivly use it.
# Lets talk about the module CURR and what thats all about:
#
# CURR::CURR_HASH
# ---------------
#
# This hash will contain a key=>value{key=>value} type of hash (associative).
# The top level key is the vocab, this is also called the currency symbol,
# much like Gold's symbol is G, any key here should be the currency symbol.
#
# The value, contains specific keys with custom values.
# That is each key inside the core value tells you more about the currency.
#
# Lets look at this as a high level over view:
#
# 'Currency Symbol' => {
# :full_name => 'Whats the Full name?',
# :icon => 0, #Icon index is?
# :max => 9999, #Max value is what?
# :description => 'Describe your currency in few words.',
# #Example: Used for Legendary Mats.
# :obtained => 'How is this obtained, few words.',
# #Example: Guild Battles.
# }, #Don't forget the comma :D
#
#
# The next set of options you have are color options, these should be
# pretty obvious as to what they do.
#
# So lets learn what we have to use, in terms of manipulating the currencies.
# This is where the $kc_currency object is going to come in handy. When this object
# is created we take the hash you created below and compact it into an array
# of class objects that can then be picked apart. Lets do that now:
#
# $kc_currency Object
# ---------------
#
# $kc_currency.create ---> Dont call me, or try not to,
# why create the array of class
# objects again and again?
#
# $kc_currency.currencies ---> Returns that array of currency
# objects.
#
# $kc_currency.exists?(curr_vocab) ---> Does this currency exist?
#
#
# $kc_currency.currency(curr_vocab) ---> Get ONE currency object out of
# the array of curencies.
#
# $kc_currency.increase(curr_vocab, value) ---> Increase the value of ONE currency.
#
# $kc_currency.decrease(curr_vocab, value) ---> Decrease the value of ONE currency.
#
# $kc_currency.set(curr_vocab, value) ---> Be careful! This will OVERIDE any
# value already set and set it with
# this new one.
#
# $kc_currency.value(curr_vocab) ---> Get the value of this particular
# currency.
#
# $kc_currency.delete(curr_vocab) ---> Delete this currency from the
# array of currencies based on the
# name.
#
#
# So we have managed to create some currencies and manipulate individaul
# currencies based on the the methods we have. But what about the actuall
# object? The class object that contains the values of that array? what if I
# want to print the name of a specific currency?
#
# Create_CurrencyObject
# ---------------------
#
# There isn't anything in this class you would touch, accpet the abillity
# to get information on a particular object:
#
# curr_sym ---> The currency symbol.
#
# full_name ---> The actual full name.
#
# icon ---> The icon index.
#
# max ---> The maximum value this currency can be.
#
# description --> The SHORT description of the currency.
#
# obtained ---> The SHORT description of how it's obtained.
#
# So now that we have this, what if we want GC's (from the example below)
# full name? Well that's easy:
#
# $kc_currency.currency('GC').full_name #puts: Guild Currency
#
# Now that we have created the currencies, manipulate them and pulled
# individual pieces of information from the objects, based on the name
# lets call the window, lets open it. How do we do that?
#
# Opening!
# --------
#
# There are a couple of ways to do this, one is to call: call_currencies.
# How ever by default what we did was enable this in the menu. This will
# Display as the very LAST option in the menu.
#
# If you are using scripts that alter or change the menu you have the added
# bonus of the new method call: add_currency_command which will allow you
# to place the command in the menu list.
#
# In order for the second part to work you need to set: CURR::SHOW_IN_MENU
# to false, this wills top the currency option from showing in the menu.
#
#==============================================================================
# ** CURR
#------------------------------------------------------------------------------
# This is your customization module where you give your new currency a name
# and set it's max value.
# ----------------------------------------------------------------------------
#==============================================================================
module CURR
#--------------------------------------------------------------------------
# * Currency hash object created. The vocab here is the key, where
# as the value is a hash of key=>value that defines the currency.
#--------------------------------------------------------------------------
CURR_HASH = {
'GC' => {
:full_name => 'Guild Coin',
:icon => 330,
:max => 9999,
:description => 'Used for Ascended.',
:obtained => 'Guild Battles'
},
'RT' => {
:full_name => 'Resource Token',
:icon => 278,
:max => 9999,
:description => 'Used for crafting.',
:obtained => 'Jobs'
},
'CC' => {
:full_name => 'Celestial Coin',
:icon => 526,
:max => 9999,
:description => 'Used for Celestial gear.',
:obtained => 'Celestial Rips'
},
}
COLOR_CURRENCY_NAME = 5
COLOR_CURRENCY_SYM = 5
COLOR_CURRENCY_OBTAINED = 2
COLOR_CURRENCY_DESCRIPT = 2
SHOW_IN_MENU = false
end
#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * Call the currencies window.
#--------------------------------------------------------------------------
def call_currencies
SceneManager.call(Scene_Currencies)
end
end
#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
# This module manages the database and game objects. Almost all of the
# global variables used by the game are initialized by this module.
#==============================================================================
class << DataManager
#--------------------------------------------------------------------------
# * Create Game Objects.
#--------------------------------------------------------------------------
alias kalacious_currency_game_objects create_game_objects
def create_game_objects
kalacious_currency_game_objects
$kc_currency = Game_Currency.new
end
end
#==============================================================================
# ** Crate_CurrencyObject
#------------------------------------------------------------------------------
# Creates a new currency object based on the information passed in.
#==============================================================================
class Create_CurrencyObject
attr_reader :curr_sym
attr_reader :full_name
attr_reader :icon
attr_reader :max
attr_reader :description
attr_reader :obtained
attr_accessor :value
#--------------------------------------------------------------------------
# * Create the object.
#--------------------------------------------------------------------------
def initialize(curr_sym, full_name, icon, max, description,
obtained, value = 0)
@curr_sym = curr_sym
@full_name = full_name
@icon = icon
@max = max
@description = description
@obtained = obtained
@value = value
end
end
#==============================================================================
# ** Game_Currency
#------------------------------------------------------------------------------
# This class is designed to manipulate the currency object based on the
# current currency that your looking to manipulate.
#==============================================================================
class Game_Currency
attr_reader :currency
#--------------------------------------------------------------------------
# * Create the currency object for manipulation.
#--------------------------------------------------------------------------
def initialize
@currencies = []
create
end
#--------------------------------------------------------------------------
# * Create the actuall currency object.
#--------------------------------------------------------------------------
def create
CURR::CURR_HASH.each do |key, value|
currency = Create_CurrencyObject.new(key, value[:full_name], value[:icon],
value[:max], value[:description], value[:obtained], 0)
@currencies.push(currency)
end
end
#--------------------------------------------------------------------------
# * Return the array of currencies.
#--------------------------------------------------------------------------
def currencies
@currencies
end
#--------------------------------------------------------------------------
# * Grab one currency object based on the vocab passed in.
#--------------------------------------------------------------------------
def currency(curr_vocab)
if @currencies.any?
@currencies.each do |currency|
if currency.curr_sym == curr_vocab
return currency
end
end
end
end
#--------------------------------------------------------------------------
# * Does said currency exist?
#--------------------------------------------------------------------------
def exists?(curr_vocab)
if @currencies.any?
@currencies.each do |currency|
if currency.curr_sym == curr_vocab
return true
end
end
end
end
#--------------------------------------------------------------------------
# * Increase one particular currency in the list of currencies by a
# value.
#--------------------------------------------------------------------------
def increase(curr_vocab, value)
if @currencies.any?
@currencies.each do |currency|
if currency.curr_sym == curr_vocab
currency.value = [[currency.value + value, 0].max, currency.max].min
end
end
end
end
#--------------------------------------------------------------------------
# * Decrease one particular currency in the list of currencies by a
# value.
#--------------------------------------------------------------------------
def decrease(curr_vocab, value)
if @currencies.any?
@currencies.each do |currency|
if currency.curr_sym == curr_vocab
increase(curr_vocab, -value)
end
end
end
end
#--------------------------------------------------------------------------
# * Set on particular currency to a specific value.
#--------------------------------------------------------------------------
def set(curr_vocab, value)
if @currencies.any?
@currencies.each do |currency|
if currency.curr_sym == curr_vocab
currency.value = [[value, 0].max, currency.max].min
end
end
end
end
#--------------------------------------------------------------------------
# * Get the value of curreny passed in.
#--------------------------------------------------------------------------
def value(curr_vocab)
if @currencies.any?
@currencies.each do |currency|
if currency.curr_sym == curr_vocab
return currency.value
end
end
end
end
#--------------------------------------------------------------------------
# * Delete a currency based on the name.
#--------------------------------------------------------------------------
def delete(curr_vocab)
@currencies.delete_if {|x, *_| x == curr_vocab }
end
end
#==============================================================================
# ** List_Currencies_Window
#------------------------------------------------------------------------------
# Creates the currencies list window.
#==============================================================================
class List_Currencies_Window < Window_Selectable
#--------------------------------------------------------------------------
# * Create the currencies window and associated data.
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super
@data = []
activate
refresh
end
#--------------------------------------------------------------------------
# * Max columns.
#--------------------------------------------------------------------------
def col_max
return 1
end
#--------------------------------------------------------------------------
# * Item max.
#--------------------------------------------------------------------------
def item_max
@data ? @data.size : 1
end
#--------------------------------------------------------------------------
# * Set the enabled state to true.
#--------------------------------------------------------------------------
def enable?(item)
true
end
#--------------------------------------------------------------------------
# * Return the item.
#--------------------------------------------------------------------------
def item
@data && index >= 0 ? @data[index] : nil
end
#--------------------------------------------------------------------------
# * Draw the item based on the index passed in.
#--------------------------------------------------------------------------
def draw_item(index)
currency = @data[index]
if currency
rect = item_rect_for_text(index)
draw_icon(currency.icon, rect.x + 40, rect.y, enable?(currency))
rect.x += 24
rect.width -= 24
draw_text(rect, currency.value.to_s)
end
end
#--------------------------------------------------------------------------
# * Grab all currencies to populate the data object.
#--------------------------------------------------------------------------
def make_item_list
@data = $kc_currency.currencies
end
#--------------------------------------------------------------------------
# * Baseic Refresh.
#--------------------------------------------------------------------------
def refresh
make_item_list
create_contents
draw_all_items
end
end
#==============================================================================
# ** Currency_Description_Window
#------------------------------------------------------------------------------
# Creates the currencies list window.
#==============================================================================
class Currency_Description_Window < Window_Base
def initialize(x, y, width, height)
super
end
#--------------------------------------------------------------------------
# * Create the window.
#--------------------------------------------------------------------------
def data=(index)
return if @content == index
@content = index
refresh
end
#--------------------------------------------------------------------------
# * Create new draw_text method.
#--------------------------------------------------------------------------
def draw_text(x, y, text_width, text_height, text, alignment = 0)
contents.draw_text(x, y, text_width, text_height, text, alignment = 0)
end
#--------------------------------------------------------------------------
# * Allow text to be both sized and colored.
#--------------------------------------------------------------------------
def size(x, y, text_width, text_height, text, size, color = 0, alignment = 0)
currentsize = self.contents.font.dup
contents.font.size = size
contents.font.color.set(text_color(color))
draw_text(x, y, text_width, text_height, text, alignment = 0)
self.contents.font = currentsize
end
#--------------------------------------------------------------------------
# * Allow text to have its color changed.
#--------------------------------------------------------------------------
def color(x, y, tw, th, text, color, alignement = 0)
currentcolor = self.contents.font.dup
contents.font.color.set(text_color(color))
draw_text(x, y, tw, th, text, alignment = 0)
self.contents.font = currentcolor
end
#--------------------------------------------------------------------------
# * Call this method directorly when creating the window. Will draw
# all the contents in the widnow based on the @content object.
#--------------------------------------------------------------------------
def draw_contents
refresh
draw_main_title
draw_currency_title
draw_currency_name
draw_currency_sym_title
draw_currency_sym
draw_obtained_title
draw_obtained
draw_icon_title
draw_currency_icon
draw_currency_description_title
draw_currency_description
end
#--------------------------------------------------------------------------
# * Draw the main title.
#--------------------------------------------------------------------------
def draw_main_title
size(width/2 - 110, 0, 220, 50, "Currency Description", 40, )
size(width/2 - 130, 30, 275, 50, "Pick a currency to view information.",
18, 3)
end
#--------------------------------------------------------------------------
# * Draw the currency title.
#--------------------------------------------------------------------------
def draw_currency_title
text = "Currency: "
draw_text(20, 60, text.length + 275, 50, text)
end
#--------------------------------------------------------------------------
# * Draw the currency name.
#--------------------------------------------------------------------------
def draw_currency_name
text = @content.full_name
color(175, 60, text.length + 200, 50, text, CURR::COLOR_CURRENCY_NAME)
end
#--------------------------------------------------------------------------
# * Draw currency symbol title.
#--------------------------------------------------------------------------
def draw_currency_sym_title
text = "Currency Symbol: "
draw_text(20, 90, text.length + 275, 50, text)
end
#--------------------------------------------------------------------------
# * Draw the currency symbol.
#--------------------------------------------------------------------------
def draw_currency_sym
text = @content.curr_sym
color(175, 90, text.length + 200, 50, text, CURR::COLOR_CURRENCY_SYM)
end
#--------------------------------------------------------------------------
# * Draw the icon title.
#--------------------------------------------------------------------------
def draw_icon_title
text = "Universial Symbol: "
draw_text(20, 120, text.length + 250, 50, text)
end
#--------------------------------------------------------------------------
# * Draw the actual icon.
#--------------------------------------------------------------------------
def draw_currency_icon
draw_icon(@content.icon, 175, 134)
end
#--------------------------------------------------------------------------
# * Draw the obtained title.
#--------------------------------------------------------------------------
def draw_obtained_title
text = "Obtained?: "
draw_text(20, 150, text.length + 275, 50, text)
end
#--------------------------------------------------------------------------
# * Draw the obtained.
#--------------------------------------------------------------------------
def draw_obtained
text = @content.obtained
color(175, 150, text.length + 200, 50, text, CURR::COLOR_CURRENCY_OBTAINED)
end
#--------------------------------------------------------------------------
# * Draw the currency description title.
#--------------------------------------------------------------------------
def draw_currency_description_title
text = "Currency Description: "
draw_text(20, 180, text.length + 375, 50, text)
end
#--------------------------------------------------------------------------
# * Draw the currency description.
#--------------------------------------------------------------------------
def draw_currency_description
text = @content.description
color(40, 220, text.length + 400, 50, text, CURR::COLOR_CURRENCY_DESCRIPT)
end
#--------------------------------------------------------------------------
# * Typical refresh.
#--------------------------------------------------------------------------
def refresh
contents.clear
create_contents
return if @content
end
end
#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
# This window deals with general command choices.
#==============================================================================
class Window_MenuCommand < Window_Command
#--------------------------------------------------------------------------
# ● Add the command
#--------------------------------------------------------------------------
alias make_kc_command_window_list make_command_list
def make_command_list
make_kc_command_window_list
if CURR::SHOW_IN_MENU
add_currency_command
end
end
#--------------------------------------------------------------------------
# ○ Add said command
#--------------------------------------------------------------------------
def add_currency_command
add_command("Currency", :currency_command, true)
end
end
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
# This class performs the menu screen processing.
#==============================================================================
class Scene_Menu < Scene_MenuBase
#--------------------------------------------------------------------------
# ● Suppose to create the currency command.
#--------------------------------------------------------------------------
alias kc_create_currency_command create_command_window
def create_command_window
kc_create_currency_command
@command_window.set_handler(:currency_command, method(:command_personal))
end
#--------------------------------------------------------------------------
# ○ Suppoose to call the currency scene.
#--------------------------------------------------------------------------
def command_call_currency_window
SceneManager.call(Scene_Currencies)
end
#--------------------------------------------------------------------------
# ● Suppose to do something when you select and hit enter.
#--------------------------------------------------------------------------
alias kc_on_personal_ok_currencies on_personal_ok
def on_personal_ok
kc_on_personal_ok_currencies
if @command_window.current_symbol == :currency_command
command_call_currency_window
end
end
end
#==============================================================================
# ** Scene_Currencies
#------------------------------------------------------------------------------
# Creates a new scene that is then called via the script call.
#==============================================================================
class Scene_Currencies < Scene_MenuBase
#--------------------------------------------------------------------------
# * Start the scene.
#--------------------------------------------------------------------------
def start
super
create_currencies_window
create_description_window
end
#--------------------------------------------------------------------------
# * Create the currencies window.
#--------------------------------------------------------------------------
def create_currencies_window
width = 100
height = Graphics.height - 100
@currency_list = List_Currencies_Window.new(60, 50, width, height)
@currency_list.select(0)
@currency_list.viewport = @viewport
@currency_list.set_handler(:ok, method(:on_item_ok))
end
#--------------------------------------------------------------------------
# * Create the desciption window.
#--------------------------------------------------------------------------
def create_description_window
@currency_description = Currency_Description_Window.new(@currency_list.width + 60,
50, Graphics.width - @currency_list.width - 100, Graphics.height - 100)
@currency_description.draw_main_title
end
#--------------------------------------------------------------------------
# * When you select a currencie we will pass the object from the currency
# list over to the currency window.
#--------------------------------------------------------------------------
def on_item_ok
@currency_description.data = @currency_list.item
@currency_description.draw_contents
@currency_list.activate
end
#--------------------------------------------------------------------------
# * Do something when we hit esc.
#--------------------------------------------------------------------------
def update
super
if Input.trigger?(:B)
SceneManager.return
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment