Multiple Currencies
#1
SG Multiple Currencies
by mudgolem/Sandgolem
Version: 1

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.


Introduction

This script allows you to easily have multiple currencies with icons and quickly change from them. By default, it's set up with "G", "Tokens" and "Tickets" (Casino/Arcade?)

It uses these icons, which can be changed with one line:
(all three images lost)

Features
  • Change currencies at any time
  • No maximum amount of currencies
  • Only three lines to edit in the entire script
  • Shows currency with an icon in the gold window
  • Stored as variables, which can be easily checked in events
  • SDK compatable and also works without it - no commenting necessary


Script

Place it above main, under the SDK if you're using it


Code:
#=============================================================================
# ** SG Multiple Currencies
#=============================================================================
# sandgolem
# Version 1
# 16.03.06
#=============================================================================
#
# Part of this script was based on one "Link_05" posted to rmxp.net boards
# An additional edit to it was by him, with the icon shown on the left
# (The "Icon where currency (Gold) is" script)
#
# If you don't intend to use multiple currencies in your game, I highly
# recommend using that script instead of this one to show it's icon!
#
#=============================================================================
#
# This requires event scripting to switch, see below.
#
# The only script-related things to edit is this:
#
$sg_currency_names = ['G','Token','Ticket']
$sg_currency_icons = ['mbag','coin','card']
$sg_currency_vars = [2,3,4]
#
# These need to be ordered exactly the same. You can increase the amount of
# currencies by adding more to the end of each.
#
# Set the first to what you have your gold name as in the database.
# Icons and vars are picked based on the order that you have your names set
# to. Make sure you name the variable in RMXP so you won't reuse it.
#
#=============================================================================
#
# To change the player's currency, use this in a call script:
# sg_change_currency('NameHere')
#
# This changes your current currency and modifies the amount of gold you have
# to whatever it is set at. The amount of gold you had before is set to the
# variable listed for it. This can be used anywhere, even in other scripts
#
#=============================================================================
#
# The variable used for your current gold is NOT altered until you change the
# currency. To do checks for that amount ingame, just use the regular gold.
#
# Or, you can save it by using this in a script: sg_save_currency
# This command is included in sg_change_currency and generally not useful
#
#=============================================================================
#
# To check for updates or find more scripts, visit:
# [url=http://www.gamebaker.com/rmxp/scripts/]http://www.gamebaker.com/rmxp/scripts/[/url]
#
# To use this script, copy it and insert it in a new section above "Main",
# under the default scripts and Software Development Kit (optional).
#
# Have problems? You can leave me a message at:
# [url=http://www.gamebaker.com/users/sandgolem]http://www.gamebaker.com/users/sandgolem[/url]
#
#=============================================================================

#--------------------------------------------------------------------------
# * SDK Log Script
#--------------------------------------------------------------------------
begin
SDK.log("SG Multiple Currencies", "sandgolem", 1, "16.03.06")
if SDK.state("SG Multiple Currencies") != true
@sg_multiple_currencies_disabled = true
end
rescue
end

#--------------------------------------------------------------------------
# * Begin SDK Enable Test
#--------------------------------------------------------------------------
if !@sg_multiple_currencies_disabled

class Window_Gold < Window_Base

def refresh
self.contents.clear
#------------------------------------------------------------------------------
# Begin SG Multiple Currencies in Window Edit
#------------------------------------------------------------------------------
self.contents.font.color = normal_color
self.contents.draw_text(4, 1, 120, 32, $game_party.gold.to_s, 2)
sg_select_currency_icon
src_rect = Rect.new(0, 0, 32, 32)
if @icon != nil
self.contents.blt(0, 3, @icon, src_rect)
end
#------------------------------------------------------------------------------
# End SG Multiple Currencies Edit
#------------------------------------------------------------------------------
end

def sg_select_currency_icon
@sg_mc_temp = 0
loop do
if @sg_mc_temp > $sg_currency_names.size
return
end
if $data_system.words.gold == $sg_currency_names[@sg_mc_temp]
@icon = RPG::Cache.icon($sg_currency_icons[@sg_mc_temp])
return
end
@sg_mc_temp+=1
end
end
end

def sg_save_currency
@sg_mc_temp = 0
loop do
if @sg_mc_temp > $sg_currency_names.size
p "You have an invalid currency name! Contact game author"
p $data_systems.words.gold
@sg_mc_currency_stop = true
return
end
if $data_system.words.gold == $sg_currency_names[@sg_mc_temp]
$game_variables[$sg_currency_vars[@sg_mc_temp]] = $game_party.gold
return
end
@sg_mc_temp+=1
end
end

def sg_change_currency(cur_new)
sg_save_currency
if @sg_mc_currency_stop == true
return
end
@sg_mc_temp = 0
loop do
if @sg_mc_temp > $sg_currency_names.size
p "Invalid currency name in command! Contact game author"
p cur_new
return
end
if cur_new == $sg_currency_names[@sg_mc_temp]
$game_party.lose_gold($game_party.gold)
$game_party.gain_gold($game_variables[$sg_currency_vars[@sg_mc_temp]])
$data_system.words.gold = cur_new
return
end
@sg_mc_temp+=1
end
end

#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end


Instructions

Use this command in an event's call script (or any other script) to change the currency:

Code:
sg_change_currency('NameHere')


Your current currency saved in the variable is not changed until you run that command, use the regular gold options to check how much of it you have. You can also force it to save by using this (included in sg_change_currency): sg_save_currency

Change the three uncommented lines at the start of the script to whatever you'd like. One of the currencies must be named the same as your gold name in the database

Compatibility

This script rewrites Window_Gold's refresh, so place it above any others that use that.

Credits and Thanks

Part of this script was based on one Link_05 posted on .net titled "Icon where currency (Gold) is"

Prexus for the way to have it not crash if the SDK isn't present

Thanks to Magic Magor, MeisMe, Prexus & SephirothSpawn for putting up with newbie-ish scripting questions.

Author's Notes

Since they're stored as variables, you can easily check the others ingame for whatever reason without changing your gold. I have a "Currency Shop" add-on in the works that should be posted soon

Useful script? Any weird bugs or horrible coding? Let me know! [Image: smile.gif]

edit: Added sg_save_currency to the comments. Nothing new
}


Messages In This Thread
Multiple Currencies - by mudgolem - 03-16-2006, 01:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  D&D-esque currencies Jimmie 0 2,475 03-24-2007, 01:00 PM
Last Post: Jimmie



Users browsing this thread: 1 Guest(s)