Tinys Trade System (TTS)

TinyMine

Veteran
Veteran
Joined
Oct 26, 2013
Messages
53
Reaction score
49
First Language
German
Primarily Uses
Thanks Glorian. I will try to upload a new version this week (also with some updates in the script itself).

Regards

EDIT:

Will come this week - loads of changes... but that old script deserves it ... 
 
Last edited by a moderator:

tale

Volunteer
Veteran
Joined
Dec 16, 2016
Messages
534
Reaction score
869
First Language
English
Primarily Uses
N/A
Fixed script format, credit TinyMine.
For more details: https://forums.rpgmakerweb.com/index.php?threads/tinys-trade-system-tts.20243/
Code:
#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ Tinys Trade System
#║ By TinyMine
#║
#║ First Published/Erstveröffentlicht 22.11.2013
#║
#║ Visit : http://rpgmaker-vx-ace.de/ for further Information
#║
#║ Suggestions? Support? Bugs? Contact me in http://rpgmaker-vx-ace.de/
#║
#║ Credits required : TinyMine
#║ Commercial Use? : Contact me in http://rpgmaker-vx-ace.de/
#║ Editable? : Only by original editor TinyMine
#║
#║
#║ Version : 1.15 // 02.12.2013
#╚═=═=════════════════════════════════════════════════════════════════════════=#

$imported ||= {}
$imported[:TINY_TTS] = 1.15

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ ** FEATURES **
#║
#║ - Complete new shop scene
#║ - Trading with items
#║ - Define your vendors
#║ - Vendor will loose bought items
#║ - Vendor will get sold items
#║ - Define your windows
#║ - Define the scene sounds
#║ - Define the scene font
#║ - Penalty for player when trading
#║
#╚═=═=════════════════════════════════════════════════════════════════════════=#

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ ** UPDATES **
#║
#║ █ 1.15
#║
#║ - Added a new vendor command to exclude items individually
#║
#║ █ 1.11
#║
#║ - Added Float compatibility in text visualization
#║
#║ █ 1.1 "Thats's sheer robbery"
#║
#║ - Added a Configpoint to change the item maximum number
#║ - Added a new vendor command to change the vendors buy prices individually
#║ - Added a new vendor command to change the vendors sell prices individually
#║ - Changed the size and shape of number input window
#║ - Fixed a minor calculation bug
#║ - Fixed that amount scrolling was not effected by item_max in buy sequence
#║
#║ █ 1.01
#║
#║ - Fixed double items overrite each other
#║
#║
#╚═=═=════════════════════════════════════════════════════════════════════════=#

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ ** USAGE INSTRUCTIONS **
#║
#║ For calling the new shop scene, use...
#║ █ open_shop(symbol)
#║ Where symbol should be your defined vendor under vendor section.
#║
#║ For adding items to a specified vendor during game progress, use...
#║ █ add_vendor_item(symbol, item)
#║ Where symbol should be your defined vendor under vendor section and
#║ where item should be something like "item,id,amount"
#║
#║ For example
#║ add_vendor_item(:myvendor, "armor,2,1")
#║
#║ For exclude items/weapons/armors from trading scene, write...
#║ █ <not sellable>
#║ Into your items/weapons/armors note
#║
#║
#╚═=═=════════════════════════════════════════════════════════════════════════=#



module TINY # Do not touch
module TTS_GENERAL # Do not touch
#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** EDITABLE REGION ** Defining TTS GENERAL Settings ** EDITABLE REGION **
#╚═=═=════════════════════════════════════════════════════════════════════════=#

#█ General Settings

# Defines the max amount for each item a player can have
MAX_ITEM = 999

#█ Sound Settings

# Defines sound when scrolling with cursor by filename in SE
SCROLL_SOUND = "Cursor1"

# Defines sound when pressing menu points by filename in SE
OK_SOUND = "Equip1"

# Defines sound when canceling command/number window by filename in SE
CANCEL_SOUND = "Cancel1"

#█ Window Settings

# Defines used Window_Skin for all tts windows
WINDOWSKIN = "Window"

# Defines the font used in all tts windows
WINDOWFONT = "VL Gothic"

# Defines the Windowopacity (Frame + Skin) 0 - 255 (255 = fully visible)
OPACITY = 255

# Defines the Window Backopacity (Frame is untouched) 0 - 255 (255 = fully visible)
BACKOPACITY = 255

#█ Scene Settings

# Creates a background by image name in system folder ( "" is no picture )
BACKGROUND = ""

#█ Vendor Settings

# Defines global trade penalty in % // Calcs player values by % if no vendor command is given
PENALTY = 80

#═=═=═════════════════════════════════════════════════════════════════════════=#
end # TTS_GENERAL
module TTS_VOCAB # Do not touch
#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** EDITABLE REGION ** Defining TTS Vocab ** EDITABLE REGION **
#╚═=═=════════════════════════════════════════════════════════════════════════=#

# Headername for own Inventory in Shop Scene
VOC_GOODS = "My stuff"

# Description of amount when choosing amount of item to buy/sell
VOC_AMOUNT = "Amount"

# Names of commands in command window
VOC_TRADE = "Trade listed items "
VOC_CANCEL = "Cancel trading"

# Currencyunit used in your Game * Use VOCAB::currency_unit for DataBase currency
VOC_CURRENCY = "Gold"

# Description of items price for info window
VOC_VALUE = "Value"


#═=═=═════════════════════════════════════════════════════════════════════════=#
end # TTS_VOCAB
module TTS_VENDOR # Do not touch
VENDORS = { # Do not touch
#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** EDITABLE REGION ** Defining TTS Vendors ** EDITABLE REGION **
#╚═=═=════════════════════════════════════════════════════════════════════════=#

#╔═=═══════════════════════════════════════════════════════════════════════════#
#║ ** FULL ITEM/COMMAND LIST FOR VENDORS BELOW **
#║
#║
#║ █ adding items/armors/weapons
#║
#║ - "weapon,id,amount"
#║ - "armor,id,amount"
#║ - "item,id,amount"
#║
#║ You will find the id of each item type (item,armor,weapon) you want
#║ to add to your vendors inventory in your database, where you
#║ find all your items and their configurations.
#║
#║ █ defining individual prices when selling/buying for each vendor
#║
#║ - "buy,percentage"
#║ - "sell,percentage"
#║
#║ Recalulates the prices of each item. For example a vendor with
#║ "sell,10" configuration will sell all his items to a discount of 90%.
#║ If no "buy,percentage" command is given to a vendor the global player
#║ penalty will take affect.
#║
#║ █ excluding specified items individually for each vendor
#║
#║ - "no item ID"
#║ - "no armor ID"
#║ - "no weapon ID"
#║
#║ The ID represents, as always, the item id from your database.
#║ If you are excluding an item it won't appear in the trade list if
#║ trading to the configurated vendor.
#║
#║
#║ █ also take a look on TTS Addons to get new vendor commands
#║
#╚=════════════════════════════════════════════════════════════════════════════#

#█ EXAMPLE VENDORS

# Vendor_ID and Name SEE LIST ABOVE FOR ALL COMMANDS
:santa => ["weapon,1,1","sell,120","item,2,1","item,2,1", "no weapon 8",
"armor,4,2","item,6,3","item,5,2"],


:klaus => ["weapon,1,1","item,2,1","item,2,1","sell,90", "no item 4", "no armor 8",
"armor,4,2","buy,10", "item,6,3","item,5,2"], # Use comma when a another vendor follows


:harrison => ["item,2,1","items,2,19","buy,50", "sell,90", "armor,1,10",
"armor,4,2","item,6,3","item,5,2"] # Don't use comma when it is the last configurated vendor

#█ OWN VENDORS (If you are comfortable with the settings you can remove the examples)

# Add your own here






#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** END OF EDITABLE REGION ** BEWARE ** END OF EDITABLE REGION ** DONT! **
#║ █ ** Dont edit below this line, except... just don't **
#╚═=═=════════════════════════════════════════════════════════════════════════=#
} # end of vendors hash

# Loadgame or Newgame?
@vendors ||= VENDORS
# Method for setting @vendors
def self.vendors=(args)
@vendors = args
end

# Method for getting @vendors
def self.vendors
@vendors
end

# Method for adding value to @vendors key
def self.add_vendors_item(key, value)
@vendors[key] << value
end

# Method for refreshing value to @vendors key
def self.refresh_vendors(key, new_value)
@vendors[key] = new_value
end

end # Module TTS_VENDOR
end # Module TINY

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Module DataManager
#╚═=═=════════════════════════════════════════════════════════════════════════=#
module DataManager

# Alias
class << self
alias_method :make_save_contents_tiny_tts_124145, :make_save_contents
alias_method :extract_save_contents_tiny_tts_88342, :extract_save_contents
end

# Alias save contents for saving vendor inventories
def self.make_save_contents
contents = make_save_contents_tiny_tts_124145
contents[:tts_vendors] = TINY::TTS_VENDOR.vendors
contents
end

# Alias extract contents for extracting saved vendor inventories
def self.extract_save_contents(contents)
extract_save_contents_tiny_tts_88342(contents)
TINY::TTS_VENDOR.vendors = contents[:tts_vendors]
end

end # Module DataManager

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Module SceneManager
#╚═=═=════════════════════════════════════════════════════════════════════════=#
module SceneManager

# Calls a scene with arguments
def self.call_args(scene_class, *args)
@stack.push(@scene)
@scene = scene_class.new(*args)
end

end # Module SceneManager

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Class Game_Interpreter
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class Game_Interpreter

# Command for opening the TTS Scene
def open_shop(symbol)
SceneManager.call_args(TTS_Scene, symbol)
end

# Command for adding items to configured vendors
def add_vendor_item(symbol, item)
TINY::TTS_VENDOR.add_vendors_item(symbol, item)
end

end # Game_Interpreter

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Class Game_Party
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class Game_Party

# Attr
attr_reader :vendor_price, :vendor_penalty

# Alias
alias_method :initialize_tiny_tts_13141 , :initialize

# Alias initialize for defining tts hashs
def initialize
initialize_tiny_tts_13141
clear_all_tts_inventories
end

# Overwriting the item_max method
def max_item_number(item)
return TINY::TTS_GENERAL::MAX_ITEM
end

# Method for hash inventory sharing
def share_buffer_item(item, amount, index)
container = get_inventory(item.class, index)
return unless container
last_number = container[item.id] || 0
new_number = last_number + amount
container[item.id] = [new_number, 0].max
container.delete(item.id) if container[item.id] == 0
end

# Method for hash inventory amount
def item_number_tts(item, index)
container = get_inventory(item.class, index)
container ? container[item.id] || 0 : 0
end

# Method for returning the actual hash inventory
def get_inventory(klass, index)
case index
when 0
return @items if klass == RPG::Item
return @weapons if klass == RPG::Weapon
return @armors if klass == RPG::Armor
when 1
return @items_buffer_player if klass == RPG::Item
return @weapons_buffer_player if klass == RPG::Weapon
return @armors_buffer_player if klass == RPG::Armor
when 2
return @items_buffer_vendor if klass == RPG::Item
return @weapons_buffer_vendor if klass == RPG::Weapon
return @armors_buffer_vendor if klass == RPG::Armor
when 3
return @items_vendor if klass == RPG::Item
return @weapons_vendor if klass == RPG::Weapon
return @armors_vendor if klass == RPG::Armor
end
false
end

# Method for calc price of bought items
def calc_price_vendor
value_buffer = 0
@items_buffer_vendor.keys.each { |id| value_buffer += ($data_items[id].price * (@items_buffer_vendor[id])) }
@weapons_buffer_vendor.keys.each { |id| value_buffer += ($data_weapons[id].price * (@weapons_buffer_vendor[id])) }
@armors_buffer_vendor.keys.each { |id| value_buffer += ($data_armors[id].price * (@armors_buffer_vendor[id])) }
value_buffer = (value_buffer*@vendor_price).ceil.to_i
value_buffer
end

# Method for calc price of sold items
def calc_price_player
value_buffer = 0
@items_buffer_player.keys.each { |id| value_buffer += ($data_items[id].price * (@items_buffer_player[id])) }
@weapons_buffer_player.keys.each { |id| value_buffer += ($data_weapons[id].price * (@weapons_buffer_player[id])) }
@armors_buffer_player.keys.each { |id| value_buffer += ($data_armors[id].price * (@armors_buffer_player[id])) }
value_buffer = (value_buffer*@vendor_penalty).ceil.to_i
value_buffer
end

# Method to remove non sellable items from party hash items
def get_sellable_items
item_list = {}
@items.each { |item, quant|
next if $data_items[item].note.include?("<not sellable>")
next if @vendor_denies.include?("no item #{item}")
item_list[item] = quant
}
item_list
end

# Method to remove non sellable items from party hash weapons
def get_sellable_weapons
weapon_list = {}
@weapons.each { |weapon, quant|
next if $data_weapons[weapon].note.include?("<not sellable>")
next if @vendor_denies.include?("no weapon #{weapon}")
weapon_list[weapon] = quant
}
weapon_list
end

# Method to remove non sellable items from party hash armors
def get_sellable_armors
armor_list = {}
@armors.each { |armor, quant|
next if $data_armors[armor].note.include?("<not sellable>")
next if @vendor_denies.include?("no armor #{armor}")
armor_list[armor] = quant
}
armor_list
end

# Method for reading vendor strings
def set_buyable_items(vendor)
TINY::TTS_VENDOR.vendors[vendor].each { |item|
item =~ /sell,(\d+)/ ? adjust_vendor_prices($1.to_i) :
item =~ /buy,(\d+)/ ? adjust_vendor_penalty($1.to_i) :
item =~ /no (\w+) \W*(\w+)/ ? set_vendor_denies($1, $2) :
item =~ /(\w+)s*,\s*\W*(\w+)\s*,\s*(\d+)/ ? fill_vendor_inventory($1, $2, $3) : nil
}
end

# Method for adjusting the vendors sell prices
def adjust_vendor_prices(int)
@vendor_price = int/100.0
end

# Method for adjusting the vendors buy prices
def adjust_vendor_penalty(int)
@vendor_penalty = int/100.0
end

# Method for creating vendor hash inventories
def fill_vendor_inventory(type, id, amount)
amount_int = amount.to_i
case type.downcase
when /item\w*/
@items_vendor[id.to_i] ||= 0
@items_vendor[id.to_i] += amount_int
when /weapon\w*/
@weapons_vendor[id.to_i] ||= 0
@weapons_vendor[id.to_i] += amount_int
when /armor\w*/
@armors_vendor[id.to_i] ||= 0
@armors_vendor[id.to_i] += amount_int
end
0
end

# Method for filling up the denied items of each vendor
def set_vendor_denies(type, id)
case type.downcase
when /item\w*/
@vendor_denies += "no #{type} #{id}"
when /weapon\w*/
@vendor_denies += "no #{type} #{id}"
when /armor\w*/
@vendor_denies += "no #{type} #{id}"
end
0
end

# Method for creating new vendor strings
def get_new_vendor_value
value = []

value << "penalty,#{@vendor_penalty*100}"
value << "price,#{@vendor_price*100}"

for i in 0..@items_vendor.size
value << "item,#{@items_vendor.keys[i]},#{@items_vendor.values[i]}"
end
for i in 0..@weapons_vendor.size
value << "weapon,#{@weapons_vendor.keys[i]},#{@weapons_vendor.values[i]}"
end
for i in 0..@armors_vendor.size
value << "armor,#{@armors_vendor.keys[i]},#{@armors_vendor.values[i]}"
end
for i in 0..@items_buffer_player.size
value << "item,#{@items_buffer_player.keys[i]},#{@items_buffer_player.values[i]}"
end
for i in 0..@weapons_buffer_player.size
value << "weapon,#{@weapons_buffer_player.keys[i]},#{@weapons_buffer_player.values[i]}"
end
for i in 0..@armors_buffer_player.size
value << "armor,#{@armors_buffer_player.keys[i]},#{@armors_buffer_player.values[i]}"
end
value
end

# Method for getting all envolved data_base items/weapons/armors
def get_all_items(index)
all_items = []
case index
when 0
get_sellable_items.keys.sort.collect {|id| all_items << $data_items[id] }
get_sellable_weapons.keys.sort.collect {|id| all_items << $data_weapons[id] }
get_sellable_armors.keys.sort.collect {|id| all_items << $data_armors[id] }
when 3
@items_vendor.keys.sort.collect {|id| all_items << $data_items[id] }
@weapons_vendor.keys.sort.collect {|id| all_items << $data_weapons[id] }
@armors_vendor.keys.sort.collect {|id| all_items << $data_armors[id] }
when 1
@items_buffer_player.keys.sort.collect {|id| all_items << $data_items[id] }
@weapons_buffer_player.keys.sort.collect {|id| all_items << $data_weapons[id] }
@armors_buffer_player.keys.sort.collect {|id| all_items << $data_armors[id] }
when 2
@items_buffer_vendor.keys.sort.collect {|id| all_items << $data_items[id] }
@weapons_buffer_vendor.keys.sort.collect {|id| all_items << $data_weapons[id] }
@armors_buffer_vendor.keys.sort.collect {|id| all_items << $data_armors[id]}
end
all_items
end

# Method for defining/clearing all tts hash inventories
def clear_all_tts_inventories
@vendor_denies = ""
@vendor_penalty = adjust_vendor_penalty(TINY::TTS_GENERAL::PENALTY)
@vendor_price = adjust_vendor_prices(100)

@items_vendor = {}
@weapons_vendor = {}
@armors_vendor = {}

@items_buffer_player = {}
@weapons_buffer_player = {}
@armors_buffer_player = {}

@items_buffer_vendor = {}
@weapons_buffer_vendor = {}
@armors_buffer_vendor = {}
end

end # Game_Party

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Class Window_Base
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class Window_Base

# Defines configurations for all tts windows
def tts_window_configurations

self.windowskin = Cache.system(TINY::TTS_GENERAL::WINDOWSKIN)

self.opacity = TINY::TTS_GENERAL::OPACITY
self.back_opacity = TINY::TTS_GENERAL::BACKOPACITY

font = Font.new([TINY::TTS_GENERAL::WINDOWFONT])
font.bold = false
font.shadow = false
font.out_color = Color.new(0, 0, 0, 128)
self.contents.font = font

end

end # Window_Base

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** NEW Class TTS_Toprow_Window
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class TTS_Toprow_Window < Window_Base

# Initializes the window
def initialize(pos)
@pos = pos
super(@pos * 136, 0, 136, 48)
self.z = 200
tts_window_configurations
refresh
end

# Method for returning a standard text rect
def text_rect
rect = Rect.new(0, 0, contents_width, contents_height)
rect
end

# Method for create the price/value text
def text_price
price = $game_party.calc_price_player if @pos == 1
price = $game_party.calc_price_vendor if @pos == 2
neat_float = ""
if price.is_a?(Float)
neat_float = price.to_s
neat_float.gsub!(".") {","}
text_price = neat_float
else
text_price = price
end
text_price
end

# Method for refreshing the window contents
def refresh
contents.clear
return draw_text(text_rect,TINY::TTS_VOCAB::VOC_GOODS) if @pos == 0
return draw_text(text_rect,text_price) if @pos == 1 || @pos == 2
return draw_text(text_rect,SceneManager.scene.vendor.to_s.capitalize) if @pos == 3
end

end # TTS_Toprow_Window

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** NEW Class TTS_Midrow_Window
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class TTS_Midrow_Window < Window_Selectable

# Initializes the window
def initialize(pos)
@pos = pos
super(@pos * 136, 48, 136, 272)
self.z = 200
tts_window_configurations
refresh
end

# Method for activating the window
def activate
return if active
select(0)
SceneManager.scene.refresh_info_window(@index)
super
end

# Method for returning a standard text rect
def text_rect
rect = Rect.new(0, 0, contents_width, contents_height)
rect
end

# Method for returning contents size
def item_max
$game_party.get_all_items(@pos).size
end

# Method for processing cursor movement
def process_cursor_move
return unless cursor_movable?
last_index = @index
cursor_down (Input.trigger?(:DOWN)) if Input.repeat?(:DOWN)
cursor_up (Input.trigger?(:UP)) if Input.repeat?(:UP)
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::SCROLL_SOUND) if @index != last_index
SceneManager.scene.refresh_info_window(@index) if @index != last_index
end

# Method for handling cursor movement
def process_handling
return unless open? && active
return process_ok if ok_enabled? && Input.trigger?(:C)
return process_cancel if cancel_enabled? && Input.trigger?(:B)
return process_right if handle?(:right) && Input.trigger?(:RIGHT)
return process_left if handle?(:left) && Input.trigger?(:LEFT)
end

# Method for handling cancel
def process_cancel
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::CANCEL_SOUND)
Input.update
deactivate
call_cancel_handler
end

# Method for handling ok
def process_ok
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::OK_SOUND)
Input.update
call_ok_handler
end

# Method for handling right
def process_right
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::SCROLL_SOUND)
Input.update
call_handler(:right)
end

# Method for handling left
def process_left
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::SCROLL_SOUND)
Input.update
call_handler(:left)
end

# Method for refreshing the window contents
def refresh
contents.clear
for i in 0..$game_party.get_all_items(@pos).size-1
draw_icon($game_party.get_all_items(@pos)[i].icon_index, 0, i * 24, true)
draw_text(0, i * 24, contents_width, 24, ($game_party.item_number_tts($game_party.get_all_items(@pos)[i], @pos)), 2)
end
end

end # TTS_Midrow_Window

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** NEW Class TTS_Botrow_Window
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class TTS_Botrow_Window < Window_Base

# Initializes the window
def initialize
super(0, 320, 544, 96)
self.z = 200
@textdata = nil
tts_window_configurations
end

# Method for setting the @item data
def set_item(index_window, index_scene)
@textdata = $game_party.get_all_items(index_scene)[index_window]
index_scene == 1 || index_scene == 0 ? @multiplicator = $game_party.vendor_penalty : @multiplicator = $game_party.vendor_price
refresh
end

# Method for create the price/value text
def text_price
neat_float = ""
if @textdata.price.is_a?(Float)
neat_float = (@textdata.price * @multiplicator).to_s
neat_float.gsub!(".") {","}
text_price = neat_float
else
text_price = (@textdata.price*@multiplicator).to_i
end
text_price
end

# Method for refreshing the window contents
def refresh
return if @textdata.nil?
contents.clear
draw_text(0, 0, contents_width, 24, @textdata.name, 0)
draw_text(0, 0, contents_width, 24, "#{TINY::TTS_VOCAB::VOC_VALUE}: #{text_price} #{TINY::TTS_VOCAB::VOC_CURRENCY}", 2)
draw_text_ex(0, 24, @textdata.description)
end

end # TTS_Botrow_Window

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** NEW Class TTS_Command_Window
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class TTS_Command_Window < Window_Command

# Initializes the window
def initialize
super(0, 160)
self.x = Graphics.width/2 - self.width/2
self.z = 201
tts_window_configurations
self.openness = 0
deactivate
end

# Method for starting the window
def start
clear_command_list
make_command_list
open
activate
end

# Method for returning width of self
def window_width
200
end

# Method for defining commandlist commands
def make_command_list
add_command(TINY::TTS_VOCAB::VOC_TRADE, :buy, get_buy_state)
add_command(TINY::TTS_VOCAB::VOC_CANCEL, :close, true)
end

# Method for enabling cancel command
def cancel_enabled?
return true
end

# Method for processing cancel command
def process_ok
if current_item_enabled?
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::OK_SOUND)
Input.update
deactivate
call_ok_handler
else
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::CANCEL_SOUND)
end
end

# Method for processing cancel command
def process_cancel
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::CANCEL_SOUND)
Input.update
SceneManager.scene.refresh_all_windows
close
deactivate
end

# Method for returing the buyable state
def get_buy_state
return true if $game_party.calc_price_vendor <= $game_party.calc_price_player && $game_party.calc_price_player != 0
return false
end

end # TTS_Command_Window

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** NEW Class TTS_Number_Window
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class TTS_Number_Window < Window_Selectable

# Initializes the window
def initialize
super(0, 160, 144, 72)
self.x = Graphics.width/2 - self.width/2
self.z = 201
tts_window_configurations
@index = 1
self.openness = 0
deactivate
end

# Method for starting the window and its max scroll numbers
def start(index_scene, index_window)
@type, @item_id = index_scene, index_window
@number = 1
define_maxima
refresh
activate
open
end

# Method for defining the maximum numbers of each item to buy
def define_maxima
@number_max = $game_party.item_number_tts($game_party.get_all_items(@type)[@item_id], @type) + 1
@type == 3 ? @item_max = $game_party.max_item_number(nil) : @item_max = 99999999
@item_max -= get_foreign_item_number if @type == 3
@number = 0 if @item_max <= 0
@item_max += 1
end

# Method for extracting item amounts of non selected windows
def get_foreign_item_number
item = $game_party.get_all_items(@type)[@item_id]
items_given = 0

for i in 0..2
inventory = $game_party.get_all_items(i)
item_pos = -1
found = false
inventory.each { |val|
item_pos += 1
if val.id == item.id && val.class == item.class
found = true
break
end
}
items_given += $game_party.item_number_tts($game_party.get_all_items(i)[item_pos], i) unless found == false
end
items_given
end

# Method for deactivating standard cursor processing
def process_cursor_move
nil
end

# Method for returning and processing amount number
def process_number_change
return unless active
if Input.repeat?(:UP) || Input.repeat?(:DOWN) || Input.repeat?(:RIGHT) || Input.repeat?(:LEFT)
return if @item_max == 0
@number = (@number + 1) % @number_max % @item_max if Input.repeat?(:UP)
@number = (@number - 1) % @number_max % @item_max if Input.repeat?(:DOWN)
@number = (@number + 10) % @number_max % @item_max if Input.repeat?(:RIGHT)
@number = (@number - 10) % @number_max % @item_max if Input.repeat?(:LEFT)
refresh
end
end

# Method for process handling
def process_handling
return unless active
return process_ok if Input.trigger?(:C)
return process_cancel if Input.trigger?(:B)
end

# Method for process ok command
def process_ok
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::OK_SOUND)
share_items
SceneManager.scene.refresh_all_windows
deactivate
close
end

# Method for process cancel command
def process_cancel
Audio.se_play("Audio/SE/" + TINY::TTS_GENERAL::CANCEL_SOUND)
SceneManager.scene.refresh_all_windows
deactivate
close
end

# Method for sharing items between hash inventories
def share_items
target = @type == 0 ? 1 : @type == 1 ? 0 : @type == 2 ? 3 : @type == 3 ? 2 : 0
$game_party.share_buffer_item($game_party.get_all_items(@type)[@item_id], @number, target)
$game_party.share_buffer_item($game_party.get_all_items(@type)[@item_id], -@number, @type)
end

# Method for refreshing the window contents
def refresh
contents.clear
draw_text(0, 0, contents_width, contents_height/2, "#{TINY::TTS_VOCAB::VOC_AMOUNT}", 1)
draw_text(0, contents_height/2, contents_width, contents_height/2, "#{@number}", 1)
end

# Method for updating the window
def update
super
process_number_change
end

end # TTS_Number_Window

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** NEW Class TTS_Scene
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class TTS_Scene < Scene_Base

# Initializes the scene
def initialize(vendor)
@vendor = vendor
end

# Method for starting the scene
def start
super
begin
$game_party.clear_all_tts_inventories
$game_party.set_buyable_items(vendor)
rescue
msgbox_p("This vendor does not exist. Closing scene")
return SceneManager.return
end
create_all_windows
create_all_handler
@background = Sprite.new
@background.bitmap = Cache.system(TINY::TTS_GENERAL::BACKGROUND)
select(0, 0)
end

# Method for returning actual vendor key
def vendor
@vendor
end

# Method for creating all scene windows
def create_all_windows
@info_window = TTS_Botrow_Window.new()

@tll_window = TTS_Toprow_Window.new(0)
@tl_window = TTS_Toprow_Window.new(1)
@tr_window = TTS_Toprow_Window.new(2)
@trr_window = TTS_Toprow_Window.new(3)

@mll_window = TTS_Midrow_Window.new(0)
@ml_window = TTS_Midrow_Window.new(1)
@mr_window = TTS_Midrow_Window.new(2)
@mrr_window = TTS_Midrow_Window.new(3)

@com_main = TTS_Command_Window.new()
@number_window = TTS_Number_Window.new()
end

# Method for setting all scene window handlers
def create_all_handler
instance_variables.each { |varname|
ivar = instance_variable_get(varname)
if ivar.is_a?(TTS_Midrow_Window)
ivar.set_handler(:cancel, method(:start_command_window))
ivar.set_handler(:ok, method(:start_number_window))
ivar.set_handler(:right, method(:right_scene_index))
ivar.set_handler(:left, method(:left_scene_index))
end
}
@com_main.set_handler(:close, method(:close_scene))
@com_main.set_handler(:buy, method(:accomplish_scene))
end

# Method for starting command window
def start_command_window
@depth = 1
@com_main.start
unselect
end

# Method for starting number input
def start_number_window
window = nil
instance_variables.select { |varname|
ivar = instance_variable_get(varname)
if ivar.is_a?(TTS_Midrow_Window) && ivar.active
window = ivar
end
}
return if window.item_max == 0
@depth = 1
@number_window.start(@index,window.index)
unselect
end

# Method for closing scene without inventory changes
def close_scene

for i in 0..$game_party.get_all_items(1).size-1
$game_party.share_buffer_item($game_party.get_all_items(1)[i], $game_party.item_number_tts($game_party.get_all_items(1)[i], 1), 0)
end

$game_party.clear_all_tts_inventories
@background.dispose
SceneManager.return
end

# Method for closing scene with inventory processes
def accomplish_scene

for i in 0..$game_party.get_all_items(2).size-1
$game_party.share_buffer_item($game_party.get_all_items(2)[i], $game_party.item_number_tts($game_party.get_all_items(2)[i], 2), 0)
end

TINY::TTS_VENDOR.refresh_vendors(@vendor, $game_party.get_new_vendor_value)
$game_party.clear_all_tts_inventories
@background.dispose
SceneManager.return
end

# Method for selecting index, depth of scene
def select(index, depth)
@index = index
@depth = depth
end

# Method for selecting depth of scene
def depth(depth)
@depth = depth
@depth
end

# Method for unselecting all item lists
def unselect
instance_variables.each do |varname|
ivar = instance_variable_get(varname)
ivar.deactivate if ivar.is_a?(TTS_Midrow_Window)
ivar.unselect if ivar.is_a?(TTS_Midrow_Window)
end
end

# Method for selecting next item list
def right_scene_index
@index = (@index + 1) % 4
unselect
end

# Method for selecting next item list
def left_scene_index
@index = (@index - 1) % 4
unselect
end

# Method for refreshing all scene windows
def refresh_all_windows
instance_variables.each do |varname|
ivar = instance_variable_get(varname)
ivar.refresh if ivar.is_a?(Window)
end
@depth = 0
end

# Method for refreshing info window data
def refresh_info_window(index_window, index_scene = @index)
@info_window.set_item(index_window, index_scene)
end

# Method for activating actual item list
def update_index
@mll_window.activate if @index == 0
@ml_window.activate if @index == 1
@mr_window.activate if @index == 2
@mrr_window.activate if @index == 3
end

# Method for updating the scene
def update
super
update_index if @depth == 0
end

end # TTS_Scene

#╔═=═══════════════════════════════════════════════════════════════════════════╗
#╠══════════════════════════════▲ END OF SCRIPT ▲══════════════════════════════╣
#╚═=═=═════════════════════════════════════════════════════════════════════════╝
 

tale

Volunteer
Veteran
Joined
Dec 16, 2016
Messages
534
Reaction score
869
First Language
English
Primarily Uses
N/A
Fixed script format, (Add-on) credit TinyMine.
For more details: https://forums.rpgmakerweb.com/index.php?threads/tinys-trade-system-tts.20243/
Note: There's an error for fitting both scripts in one post, that's why I made it separate.
The "Currency Addon"

Features :
- Makes it possible to trade with currencies
- makes it possible to add new currencies
- create your very own currencies and make them tradeable
Code:
#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ Tinys TTS Currency Addon
#║ By TinyMine
#║
#║ First Published/Erstveröffentlicht 27.11.2013
#║
#║ Visit : http://rpgmaker-vx-ace.de/ for further Information
#║
#║ Suggestions? Support? Bugs? Contact me in http://rpgmaker-vx-ace.de/
#║
#║ Credits required : TinyMine
#║ Commercial Use? : Contact me in http://rpgmaker-vx-ace.de/
#║ Editable? : Only by original editor TinyMine
#║
#║
#║ Version : 1.0 // 30.11.2013
#╚═=═=════════════════════════════════════════════════════════════════════════=#

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ ** ADDED USAGE INSTRUCTIONS **
#║
#║ For adding new currencies to player, use...
#║ █ give_currency(type, amount)
#║ Where type should be your defined currency in a string.
#║ where amount should be the amount.
#║
#║ For example
#║ give_currency("silver", 10000)
#║ or
#║ give_currency(":silver", 10000)
#║ or
#║ give_currency(1, 10000)
#║
#╚═=═=════════════════════════════════════════════════════════════════════════=#

#╔═=═══════════════════════════════════════════════════════════════════════════#
#║ ** NEW ITEM/COMMANDS FOR VENDORS BELOW **
#║
#║
#║ █ adding currencies to vendors
#║
#║ - "currency,id,amount"
#║
#║ You will configurate the ids by yourself.
#║
#║ █ adding default gold to vendors
#║
#║ - "currency,0,amount"
#║ or
#║ - "gold, amount"
#║
#║ 0 will always be the ID for the default currency, which is defined
#║ in database. Value will always be 1.
#║
#║ █ excluding specified currencies individually for each vendor
#║
#║ - "no currency ID"
#║
#╚=════════════════════════════════════════════════════════════════════════════#


# Check for compatibil version of main script
if $imported[:TINY_TTS] == nil
msgbox_p("You need to install *TTS (Tinys Trade System)* to use *TTS Currency Addon*")
elsif $imported[:TINY_TTS] < 1.15
msgbox_p("You need to install TTS Version 1.11 or higher to run TTS Currency Addon")
else
$imported[:TINY_TTSCA] = 1.0
#═=═=═════════════════════════════════════════════════════════════════════════=#
module TINY
module TTS_CURRENCY
#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** EDITABLE REGION ** Currency Addon General ** EDITABLE REGION **
#╚═=═=════════════════════════════════════════════════════════════════════════=#

# Defining the max gold/purse space for each currency
MAX_GOLD = 99999999

# Defining the name which will be used for the default gold
DEFAULT_NAME = "Gold"

# Defining the icon which will be used for the default gold
DEFAULT_ICON = 360

# Defining the description which will be used for the default gold
DEFAULT_DESCRIPTION = "The common gold bricekts from the northern kingdoms."


#═=═=═════════════════════════════════════════════════════════════════════════=#
CURRENCIES = { # Do not touch
#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** EDITABLE REGION ** Adding more Currencies for TTS ** EDITABLE REGION **
#╚═=═=════════════════════════════════════════════════════════════════════════=#

#█ EXAMPLE CURRENCIES

# ID of your currency # Always use the symbols (:name...etc.)
:silver => { :name => "Silver Rock",
:icon_index => 350,
:description => "These rocks are used along the southern countries\nfor trading.",
:price => 0.5
},


:khadra => { :name => "Khadra Coin",
:icon_index => 361,
:description => "Coins from the east countires. Very rare.",
:price => 4
}

#█ OWN CURRENCIES

# Add your own here








#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** END OF EDITABLE REGION ** BEWARE ** END OF EDITABLE REGION ** DONT! **
#║ █ ** Dont edit below this line, except... just don't **
#╚═=═=════════════════════════════════════════════════════════════════════════=#
} # end of currency hash

# Method for filling the new data $data_currency
def self.setup_currency_data
data_currency = []

default_currency = RPG::Currency.new

default_currency.id = 0
default_currency.name = DEFAULT_NAME
default_currency.icon_index = DEFAULT_ICON
default_currency.description = DEFAULT_DESCRIPTION
default_currency.price = 1

data_currency << default_currency

for i in 0..CURRENCIES.size-1 do
new_currency = RPG::Currency.new

new_currency.id = i + 1
new_currency.name = CURRENCIES[CURRENCIES.keys[i]][:name]
new_currency.icon_index = CURRENCIES[CURRENCIES.keys[i]][:icon_index]
new_currency.description = CURRENCIES[CURRENCIES.keys[i]][:description]
new_currency.price = CURRENCIES[CURRENCIES.keys[i]][:price]

data_currency << new_currency

end
data_currency
end

end # TTS_CURRENCY
end # TINY

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Module RPG::Currency
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class RPG::Currency

# Attr
attr_accessor :id, :name, :icon_index, :description, :price

# Initializes items of class
def initialize
@id = 0
@name = ""
@icon_index = 0
@description = ""
@price = 0
end

end # RPG::Currency

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Module DataManager
#╚═=═=════════════════════════════════════════════════════════════════════════=#
module DataManager

#Alias
class << self
alias_method :load_normal_database_tts_curr_tiny_1480, :load_normal_database
end

# Alias load_normal_database for creating a new data item
def self.load_normal_database
load_normal_database_tts_curr_tiny_1480
$data_currency = TINY::TTS_CURRENCY.setup_currency_data
end

end # DataManager

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Class Game_Interpreter
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class Game_Interpreter

# Command for adding new currencies to player
def give_currency(type, amount)
if type.is_a?(Integer) || type =~ /\d+/
type = type.to_i
else
type = TINY::TTS_CURRENCY::CURRENCIES.keys.index(type.downcase.to_sym).to_i+1
end
$game_party.purse[type.to_i] ||= 0
$game_party.purse[type.to_i] += amount.to_i
end

end # Game_Interpreter

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Class Game_Party
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class Game_Party

# Attr
attr_accessor :purse

# Alias
alias_method :get_inventory_curr_addon_tiny_1898, :get_inventory
alias_method :fill_vendor_inventory_curr_addon_tiny_00, :fill_vendor_inventory
alias_method :calc_price_vendor_curr_addon_tiny_774, :calc_price_vendor
alias_method :calc_price_player_curr_addon_tiny_2314, :calc_price_player
alias_method :get_new_vendor_value_curr_addon_tiny_11, :get_new_vendor_value
alias_method :get_all_items_curr_addon_tiny_777, :get_all_items
alias_method :clear_all_tts_inventories_curr_add_8, :clear_all_tts_inventories
alias_method :init_all_items_curr_addon_tiny_14, :init_all_items
alias_method :set_buyable_items_curr_addon_tiny_188, :set_buyable_items
alias_method :set_vendor_denies_curr_addon_tiny_400, :set_vendor_denies

# Overwrite max_gold
def max_gold
return TINY::TTS_CURRENCY::MAX_GOLD
end

# Alias get_inventory method for finding purses
def get_inventory(klass, index)
case index
when 0
return @purse if klass == RPG::Currency
when 1
return @purse_buffer_player if klass == RPG::Currency
when 2
return @purse_buffer_vendor if klass == RPG::Currency
when 3
return @purse_vendor if klass == RPG::Currency
end
get_inventory_curr_addon_tiny_1898(klass, index)
end

# Method for calc price of bought items
def calc_price_vendor
value_buffer = calc_price_vendor_curr_addon_tiny_774
@purse_buffer_vendor.keys.each { |id| value_buffer += ($data_currency[id].price * (@purse_buffer_vendor[id])) }
value_buffer
end

# Method for calc price of sold items
def calc_price_player
value_buffer = calc_price_player_curr_addon_tiny_2314
@purse_buffer_player.keys.each { |id| value_buffer += ($data_currency[id].price * (@purse_buffer_player[id])) }
value_buffer
end

# Alias set_buyable_items for checking for denies
def set_buyable_items(vendor)
set_buyable_items_curr_addon_tiny_188(vendor)
TINY::TTS_VENDOR.vendors[vendor].each { |item|
item =~ /gold, (\d+)/ ? fill_vendor_inventory("currency", "0", $1) : nil
}
end

# Alias fill_vendor_inventory method for adding currencies
def fill_vendor_inventory(type, id, amount)
fill_vendor_inventory_curr_addon_tiny_00(type, id, amount)
case type.downcase
when /currency\w*/
if id =~ /\d+/
id = id.to_i
else
id = TINY::TTS_CURRENCY::CURRENCIES.keys.index(id.to_sym).to_i+1
end
@purse_vendor[id.to_i] ||= 0
@purse_vendor[id.to_i] += amount.to_i
end
0
end

# Alias for filling up the denied currencies of each vendor
def set_vendor_denies(type, id)
set_vendor_denies_curr_addon_tiny_400(type, id)
case type.downcase
when /currency\w*/
if id =~ /\d+/
id = id.to_i
else
id = TINY::TTS_CURRENCY::CURRENCIES.keys.index(id.to_sym).to_i+1
end
@vendor_denies += "no #{type} #{id}"
end
0
end

# Alias get_new_vendor_value method for adding purses
def get_new_vendor_value
value = get_new_vendor_value_curr_addon_tiny_11
for i in 0..@purse_vendor.size
value.unshift("currency,#{@purse_vendor.keys[i]},#{@purse_vendor.values[i]}")
end
for i in 0..@purse_buffer_player.size
value.unshift("currency,#{@purse_buffer_player.keys[i]},#{@purse_buffer_player.values[i]}")
end
value
end

# Method for excluding denied currencies for actual vendor
def get_sellable_currencies
item_list = {}
@purse.each { |item, quant| item_list[item] = quant unless @vendor_denies.include?("no currency #{item}") }
item_list
end

# Alias get_all_items method for adding purse hash
def get_all_items(index)
all_items = get_all_items_curr_addon_tiny_777(index)
case index
when 0
get_sellable_currencies.keys.sort.collect {|id| all_items.unshift($data_currency[id]) }
when 3
@purse_vendor.keys.sort.collect {|id| all_items.unshift($data_currency[id]) }
when 1
@purse_buffer_player.keys.sort.collect {|id| all_items.unshift($data_currency[id]) }
when 2
@purse_buffer_vendor.keys.sort.collect {|id| all_items.unshift($data_currency[id]) }
end
all_items
end

# Method for fill up players gold after trade scene
def redefine_default_currency
@purse[0].nil? ? @gold = 0 : @gold = @purse[0]
@gold += + @purse_buffer_vendor[0] unless @purse_buffer_vendor[0].nil?
@purse.delete(0) if @gold == 0
end

# Alias for defining/clearing all tts hash inventories
def clear_all_tts_inventories
@purse[0] = @gold unless @gold == 0
@purse_buffer_player = {}
@purse_vendor = {}
@purse_buffer_vendor = {}
clear_all_tts_inventories_curr_add_8
end

# Alias init_all_items method for adding purse hash
def init_all_items
init_all_items_curr_addon_tiny_14
@purse = {}
end

end # Game_Party

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Class TTS_Number_Window
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class TTS_Number_Window

#Alias
alias_method :define_maxima_curr_addon_tiny_87, :define_maxima

# Alias define_maxima method changing the max item for currencies
def define_maxima
define_maxima_curr_addon_tiny_87
item = $game_party.get_all_items(@type)[@item_id]
@item_max += (TINY::TTS_CURRENCY::MAX_GOLD - $game_party.max_item_number(nil) - 1) if item.class == RPG::Currency
@number = 0 if @item_max <= 0
@item_max += 1
end

end # TTS_Number_Window

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Class TTS_Botrow_Window
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class TTS_Botrow_Window

#Alias
alias_method :text_price_curr_addon_tiny_283499, :text_price

# Alias text_price method for keep currency prices
def text_price
@multiplicator = 1 if @textdata.class == RPG::Currency
text_price_curr_addon_tiny_283499
end

end # TTS_Botrow_Window

#╔═=══════════════════════════════════════════════════════════════════════════=#
#║ █ ** OLD Class TTS_Scene
#╚═=═=════════════════════════════════════════════════════════════════════════=#
class TTS_Scene

#Alias
alias_method :accomplish_scene_curr_addon_tiny_1123, :accomplish_scene

# Alias accomplish scene method for add/sub gold from player gold
def accomplish_scene
$game_party.redefine_default_currency
accomplish_scene_curr_addon_tiny_1123
end

end # TTS_Scene

end # End of Version check

#╔═=═══════════════════════════════════════════════════════════════════════════╗
#╠══════════════════════════════▲ END OF SCRIPT ▲══════════════════════════════╣
#╚═=═=═════════════════════════════════════════════════════════════════════════╝
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Decided to focus on mapping for once. I've pumped out 15* new maps over the past two days' work, including two larger ones that involved some kinda fancy parallax stuff.

*should actually be 17 by the end of the night.
its been a while help
About to go live with a drawpile stream! Me and some fellow artists will be drawing things based off of prompts!
If I post an item for sale on fb for $750 and say it's in excellent condition, what is going through someone's mind to make them think it is remotely acceptable to offer $300 for it?
Well if you're going to create a JRPG, learn from the best. DRAGON QUEST XI S: Echoes of an Elusive Age - Definitive Edition purchased ^-^

Forum statistics

Threads
93,624
Messages
914,066
Members
123,199
Latest member
captianheadbutt
Top