Realistic Shop

MeisMe's Realistic Shop
[SIZE=2]Changing the shop face FOREVER


[SIZE=4]Introduction
[/SIZE][/SIZE][LEFT]A while ago, I wanted a shop with taxes, discounts, even a shopping cart. Well, now I can and so can you!

[CENTER]Instructions
[LEFT]Nothing could be simpler! Just copy and paste the whole script into a new section above 'Main'. Edit the @tax variable to the tax rate that YOU want for your game. When a time comes where a shop has a discount, or a different ate at which it buys or sells goods, just use the 'Script...' function and change them.
EG. $game_temp.buy_rate = 110 # Shop sells you goods at 110% of the database price.
When you are ready to make your purchase, press RIGHT, and select 'Finalize Purchase'. if you cannot afford the selected goods, select 'No' or hit ESC.
[/LEFT]

[/LEFT]
[/CENTER]

[spoiler=The code][code]#==============================================================================
# ** MeisMe's Realistic Shop
#------------------------------------------------------------------------------
# Created by MeisMe
# Buxfix by Daniel
# August 8, 2006
# Version 2
#==============================================================================


class Game_Temp
attr_accessor :buy_rate
attr_accessor :sell_rate
attr_accessor :discount
attr_accessor :tax
attr_accessor :cart_item
attr_accessor :cart_weapon
attr_accessor :cart_armor
attr_accessor :shop_type
alias mim_shop_old_initialize initialize
def initialize
mim_shop_old_initialize
@buy_rate = 100
@sell_rate = 50
@discount = 0
@tax = 7
clear_cart
@shop_type = 0
end
def clear_cart
@cart_item = {}
@cart_weapon = {}
@cart_armor = {}
end
def cart_cleared?
if (@cart_item == {} && @cart_weapon == {} && @cart_armor == {})
return true
end
return false
end
def item_number(item_id)
return @cart_item.include?(item_id) ? @cart_item[item_id] : 0
end
def weapon_number(weapon_id)
return @cart_weapon.include?(weapon_id) ? @cart_weapon[weapon_id] : 0
end
def armor_number(armor_id)
return @cart_armor.include?(armor_id) ? @cart_armor[armor_id] : 0
end
def gain_item(item_id, n)
if item_id > 0
@cart_item[item_id] = [[item_number(item_id) + n, 0].max, 99].min
end
end
def gain_weapon(weapon_id, n)
if weapon_id > 0
@cart_weapon[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
end
end
def gain_armor(armor_id, n)
if armor_id > 0
@cart_armor[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
end
end
def gain_items
for i in 1..$data_items.size
if item_number(i) > 0
$game_party.gain_item(i, item_number(i))
end
end
for i in 1..$data_weapons.size
if weapon_number(i) > 0
$game_party.gain_weapon(i, weapon_number(i))
end
end
for i in 1..$data_armors.size
if armor_number(i) > 0
$game_party.gain_armor(i, armor_number(i))
end
end
end
end
#==============================================================================
class Window_ShopCommand < Window_Selectable
def initialize
super(0, 64, 480, 64)
self.contents = Bitmap.new(width - 32, height - 32)
@item_max = 3
@column_max = 3
@commands = ["Buy", "Sell", "Exit"]
refresh
self.index = 0
end
def refresh
self.contents.clear
if $game_temp.shop_type == 0
for i in 0...@item_max
draw_item(i)
end
end
if $game_temp.shop_type == 1
self.contents.draw_text(4, 0, 324, 32, "You can only buy at this shop.")
self.index = -1
update_cursor_rect
end
if $game_temp.shop_type == 2
self.contents.draw_text(4, 0, 324, 32, "You can only sell at this shop.")
self.index = -1
update_cursor_rect
end
end
def draw_item(index)
x = 4 + index * 160
self.contents.draw_text(x, 0, 128, 32, @commands[index])
end
def update_cursor_rect
if $game_temp.shop_type == 0
super
end
if $game_temp.shop_type == 1 || $game_temp.shop_type == 2
self.cursor_rect.empty
end
end
end
#==============================================================================
class Window_ShopBuyBG < Window_Base
def initialize
super(0, 128, 320, 352)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 128, 32, 'Item Name')
self.contents.draw_text(4, 0, 284, 32, 'Marked Price', 2)
end
end
#==============================================================================
class Window_ShopBuy < Window_Selectable
def initialize(shop_goods)
super(0, 160, 320, 320)
@shop_goods = shop_goods
refresh
self.index = 0
self.opacity = 0
end
def item
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for goods_item in @shop_goods
case goods_item[0]
when 0
item = $data_items[goods_item[1]]
when 1
item = $data_weapons[goods_item[1]]
when 2
item = $data_armors[goods_item[1]]
end
if item != nil
@data.push(item)
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id) +
$game_temp.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id) +
$game_temp.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id) +
$game_temp.armor_number(item.id)
end
price = [[item.price * $game_temp.buy_rate / 100, 9999999].min, 0].max
if number >= 99
self.contents.font.color = disabled_color
else
self.contents.font.color = normal_color
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 192, y, 88, 32, price.to_s, 2)
end
end
#==============================================================================
class Window_ShopNumber < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 128, 320, 352)
self.contents = Bitmap.new(width - 32, height - 32)
@item = nil
@max = 1
@price = 0
@number = 1
end
#--------------------------------------------------------------------------
# * Set Items, Max Quantity, and Price
#--------------------------------------------------------------------------
def set(item, max, price)
@item = item
@max = max
@price = price
@number = 1
refresh
end
#--------------------------------------------------------------------------
# * Set Inputted Quantity
#--------------------------------------------------------------------------
def number
return @number
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_item_name(@item, 4, 96)
self.contents.font.color = normal_color
self.contents.draw_text(236, 96, 32, 32, "Ãà ¢Ã¢â€š ¬Ã¢â‚¬
Heh, you've been making this for a while, and frankly, I like it. =). Great work, MeisMe.
You finally finished it. I'll definitely test it out and recommend it to my MMO team.
Fixed an error on my behalf. I forgot to refresh the gold window after you purchase your goods. I urge everyone to re-paste the script into their project.
Double post, I know. However, I fixed another bug in which the weapons purchased would not be added to the inventory. Once again, please re-past the script into your game. Hopefully this is the last one :)
Hehehe, long time no see MeisMe. Another great script from thee! And its free. :D Sorry i felt like ryming. Very very very nice!
The final version is now out, which means I fixed the glitches, and made it so you can remove exact items from the cart.

Enjoy :)
Good Job Meisme

1) Why did you add all of those new methods to Game_Temp they would have fit better in Scene_Shop ;)

but other than that the script is coded pretty well
Thank you Trickster. It's always good to get praise from a scripter of your talents. ^_^
Hmm, interesting.
Do you think this would work in conjunction with the economy script?
I like the whole checkout thing....its a pretty awesome idea, but im not sure I like the taxes, It just doesnt seem right for an rpg in my game. But nonetheless, this is an awesome script! Well done.
If you don't like taxes, just set the @tax variable to 0 in the script :)
I'm going to bump this.
All we need now is for a shop to sell the stuff it get's from you.
Just what I was looking for! A script to have shops with different prices. (For shops in different countries.)
A very nice script... I'm not sure on how taxes fit into the 17th century of Japan's history, but I'll find that out ^_^

A suggestion would be to set the cart window active by pressing A, not the right key... I did that and it works nice, I didn't like the way you handled it... I don't know how this is going to work in 'normal' games compared to mine, which uses A/Shift in nearly every menu window ^_^

Congrats on that script, I'll definately use this, with crediting myself only for the edits :P j/k
Hey, that looks pretty neat :)
Wow. MeisMe has done it once again.
Outstanding job, top notch I say.

I'd use that. In fact, i'd hit that.
Really ncie script i wuld like to try this in my game. But whould this be possible to apply a different tax rate for each shop.
You can change all the values of the shop: the buy/sell rate, the discount and the tax.
$game_temp.buy_rate = 100 # How much the shop charges per item
$game_temp.sell_rate = 50 # How uch the shop will give you for an item
$game_temp.discount = 0 # The discount rate, subtracted after the goods are added up
$game_temp.tax = 7 # The tax rate, added after the discount has been subtracted
$game_temp.shop_type # 0=Buy/sell 1=Buy only 2=Sell only
Expand to see the code.
This is excellent. Great job - using this in my game. ^^
Can you impliment a way to put a tax on particular items?
that way, you can have trade routs in the game.
Hi. I'm pretty new to RPG Maker XP, but I was thinking that maybe you could modify it so that people had to use the 'Call Script' event to actually activate the script. That way, they could make several slight modifications to the script, put them as completely seperate scripts, and activate those modifications when certain conditions are met.

One way this could work is that if someone using this script has a seasons system or something like that, they could make it even more realistic by having different prices and taxes for certain items in each season. Some fish, for example, may only be in certain bodies of water at certain times, so depending on how easy they are to catch, the prices could be different. It's just a thought, but it could work...I think.
great script! this is perfect for my game. one thing I had to fix was the A- japanese symbol thing that appears next to the number of the amount of the items you are going to buy. just had to edit 2 messages, nothing major. So if you want to remove that at all, I'm just letting you know it's there ;)
Pretty, cool, man. Keep up the good work, hope to hear from you again, soon.....
Is there a way you could make it so you can see how the items selected compare to the items equipped? I'm using Guilamme777's multi-slot script, but it looks like even with the default battle system there is no way to see the difference between what is equipped and what is selected?

I know it may be hard, as a suggestion, and I have no idea how to code this, you might add another option aside from buy/sell and make it like 'try-on', and then you can't buy anything in that window but you can see how it affects you. In fact, I'm going to post this in the script request forum, maybe someone can make a patch for this.
Silencer actually DerVVulfman made a patch for the multi equip script.

http://www.rmxp.org/forums/showthread.php?t=17264
Oh I know, I was actually using it until I used MeisMe's script, it isn't compatible with his shop..
Problem, might just be me...

Great code, all amazing except the above link ^.
Hmm... The change of database encoding when we switched servers must have messed up some of my coding. I'll change it when I get home. Thanks for pointing it out.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=7246