Jump to content

Recommended Posts

EST - DYNAMIC SHOP

v 1.4

Creator name : Estriole

Introduction

this script can make dynamic shop. what is dynamic shop?
 it's shop that the item can be added freely. example usage:
 suikoden game:
 you have armor shop in your castle. then after visiting certain town armor shop...
 your armor shop will sell all armor that town armor shop sell too.

 

 from v1.1 above... ds games- master of monster lair:
 when you sell weapon/armor in weapon shop. you'll able to buy it in buy list.
 
 v1.1 : added feature to create shop that will add what party sold to buy list.
        can also set the type that will be added (ex: only item, only weapon, only armor)
 v1.2 : added feature for custom type (category) by adding notetags to item/weapon/armor

v 1.3 : rewritten part of the script. change the logic to make sure no duplicated items.
           also compacting the method, and changing the shop from $game_temp to $game_system
           so it can carry on save files. also create game_interpreter method
           to shorten the script calls.
 

 

Version History:

 

 

v 1.0 - 2013.01.04 => finish the script
 v 1.1 - 2013.01.05 => add sell add goods to shop feature. (can be based on category)
 v 1.2 - 2013.01.05 => add notetags for custom item/wep/armor category (to use to shop sell add goods feature)
 v 1.3 - 2014.05.28 => rewritten part of the script. change the logic to make sure no duplicated items.
                       also compacting the method, and changing the shop from $game_temp to $game_system
                       so it can carry on save files. also create game_interpreter method
                       to shorten the script calls.

 

 

 v 1.4 - 2014.06.05 => fix typo bugs that cause duplicated item. add simple sorting feature
                       use script call before calling the shop:
                       $game_system.dshop_sorting_rule = x
                       change x to these built in sorting rules:
                       :type         #will sort by type. item, weapon, armor
                       :id           #will sort by id. low id -> high id
                       :type_id      #will sort by type then by id
                       :rtype        #reverse of :type -> armor, weapon, item
                       :rid          #reverse of :id -> high id -> low id
                       :rtype_id     #sort by: armor, weapon, item, then low id -> high id
                       :rtype_rid    #sort by: armor, weapon, item, then high id -> low id
                       if you understand scripting you can add your own sorting rules.
                       also.. setting the sorting rule as :none or nil will deactivate that sorting rule



 

 

Features

- multiple "dynamic" shop. you can name them
 - add and remove goods to dynamic shop freely
 - can set the shop to behave this way. when the item sold. it will add item
   to buy list. can also set to only add certain category ("ALL","Item","Weapon","Armor")
   and also can set to use custom category assigned in notetags

How to Use

read the script header

or open spoiler belos

 

 

  how to use:
 ===============================================================================
 1)to call dynamic shop. use script call:
 
 d_shop(shop_name,purchase_only,sell_add_goods_type)
 
 shop_name[required] => the name you assign for that dynamic shop
 purchase only => set this to true if you want the shop to cannot sell item
                  default set to false
 sell_add_goods_type => "All" => will add all item/weapon/armor sold to buy list
                        "Item" => will add only item sold to buy list
                        "Weapon" => will add only weapon sold to buy list
                        "Armor" => will add only armor sold to buy list
                        not case sensitive. if left nil/blank it will not add
                        anything to buy list
                        
                        you could also create your custom category
                        by adding notetags to item/weapon/armor. example in item1
                        we add notetags:
                        <shop_cat: potion>
                        notetags not needed to case sensitive with category.
                        then when we set sell_add_goods_type to "Potion" then
                        when we sell item1. it will add it to buy list. other item don't
                        
                        and of course we have reserved word not to use:
                        all, item, weapon, armor, none
                        
 some example usage:
 -) since only shop_name is required you can skip the other
 d_shop("Castle Ugly Shop")
 will call "Castle Ugly Shop" and party can sell items.
 if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
 
 -) can set the sold item to added to buy list
 d_shop("Castle Ugly Shop",false,"ALL")
 will call "Castle Ugly Shop" and party can sell items.
 if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
 then every item/weapon/armor sold will added to buy list.

 -) can set to add only "item" sold to added to buy list. weapon and armor not
 d_shop("Castle Ugly Shop",false,"Item")
 will call "Castle Ugly Shop" and party can sell items.
 if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
 then every item (only) sold will added to buy list. weapon and armor will be ignored
 
 -) can use custom category you defined in notetags.
 d_shop("Castle Ugly Shop",false,"Sword")
 will call "Castle Ugly Shop" and party can sell items.
 if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
 then every item/weapon/armor that have notetags <shop_cat: sword>
 sold will added to buy list.
   
 ===============================================================================
 
 2)to add goods to your dynamic shop.
 
 use this script call:

 d_shop_add_goods(shop_name,goods,price)

 shop_name[required] => the name you assign for the dynamic shop. if the name haven't been assigned it will create new one
 goods [required] => item you want to add for example $data_items[1], $data_weapons[1], $data_armors[1], etc.
 price => if you want to set the price. if blank it will use default price set in database

 example usage:
 d_shop_add_goods("Goldsmith",$data_weapons[10],1000)
 will add to "Goldsmith" shop. weapon id 10 in database. with the price 1000.
 
 ===============================================================================
 
 3) to remove goods for you dynamic shop.
 
 use this script call:
 
 d_shop_rem_goods(shop_name,goods)
 
 shop_name[required] => the name you assign for the dynamic shop. if the name haven't been assigned it will create new one
 goods [required] => item you want to remove for example $data_items[1], $data_weapons[1], $data_armors[1], etc.

 example usage:
 d_shop_rem_goods("Goldsmith",$data_weapons[10])
 will remove weapon id 10 in database from "Goldsmith" shop.
 
 ===============================================================================

 4) to activate sorting rules for the shop
 use script call before calling the shop:
 $game_system.dshop_sorting_rule = x
 change x to these built in sorting rules:
 :type         #will sort by type. item, weapon, armor
 :id           #will sort by id. low id -> high id
 :type_id      #will sort by type then by id
 :rtype        #reverse of :type -> armor, weapon, item
 :rid          #reverse of :id -> high id -> low id
 :rtype_id     #sort by: armor, weapon, item, then low id -> high id
 :rtype_rid    #sort by: armor, weapon, item, then high id -> low id
 if you understand scripting you can add your own sorting rules.
 also... setting the sorting rule as :none or nil will deactivate that sorting rule

 ===============================================================================
 
 5) profit $$$
 
 ===============================================================================
 
 i also set that whenever you add item/weapon/armor to certain dynamic shop.
 it will search for that shop goods. if it contain same item/weapon/armor it will
 be overwritten. so if you first add item1 for 100 gold. shop will sell it for 100 gold
 later you add item1 for 10 gold. then the price will be changed to 10 gold.
 

 

 

 

Script

http://pastebin.com/X1QZ4e3D

 

Screenshots
not needed (unless someone ask for it. i hope not :D)

 

Demo

https://www.dropbox.com/s/eku6s5hwpxko3vu/EST_DYNAMIC_SHOP.rar

 

Credit and Thanks
- Estriole

- Nate McCloud for pointing bugs in v 1.2

 

Licences

see my sig. valid for all my scripts.

 

Author's Notes

Feel free to report any bugs.

Edited by estriole

Share this post


Link to post
Share on other sites

@sidbot: glad this script help.

 

just want to make things clear. incase someone misunderstood. the sell things add item to buy list feature i added is the one like DS game - master of monster lair.

so when we sell short sword to the weapon shop. the short sword appear in shop buy list. and we can buy it INFINITELY from then on.

 

and i also still don't know about compatibility with individual equipment script or heavy shop modification script that add shop stock to that item (something like you can only buy 3 of that item. then every x time it restocked. i think i've seen that script somewhere). so if anyone use that with this script. information about compatibility (and link to the script if possible) is appreciated. :D

Edited by estriole

Share this post


Link to post
Share on other sites

I was just about to make a request topic for a script like this! And Master of the Monster Lair was also the game I was thinking of when I decided I wanted to add a shop system like it. Thank you! Just one thing, though...is it possible to make certain items not function with this script (such as items that are one-of-a-kind, so if you sell them, they can't be bought back, or items that have no purpose other than selling)?

 

EDIT: I found a bug! Everything you sell to the shop after the first appears twice in the shop list!

 

I noticed that if I comment out the ESTRIOLE.shop_add_xxx lines, then each item appears only once and immediately, but are not there the next time I open the shop. If I comment out the @buy_window.add_new_goods(@item) line, then each item appears only once and appears consistently on subsequent visits to the shop...but they don't appear during the same visit. But if I leave them both alone, then after the first item I sell, every other item will appear in the shop twice.

 

EDIT2: Correction, the doubling only seems to occur if selling things to a shop that has already been created. Furthermore, exiting to the title screen without saving, loading the game back up, and accessing the shop does not restore the shop to its state at the time of saving. It's the same as it was when you quit the game. I believe THAT occurs because you set up dynamic shops in Game_Temp, which isn't saved in save files.

 

This script has potential, but it needs a bit of work. Thank you for laying the groundwork, however!

Edited by Nate McCloud

Share this post


Link to post
Share on other sites

@nate: thanks for pointing that out. maybe i'll modify this script later to use the $game_system and check all those bugs you mentioned. :D. and maybe rewrite it. since this script is written long time ago (january 2013) to fulfil the request of someone in this community. and no feedback after that. so i missed that bugs.

 

really thank you nate. i'll add you to the credit list if later i rewrite/fix this script :D.

Share this post


Link to post
Share on other sites

Thank you greatly. :D I'm glad I was able to help debug. I tried just shifting it over to $game_system, but that ended up with some Game_Interpreter errors.

 

As for the three methods of adding and removing items, weapons, and armors, I would like to suggest adding a fourth method for each, and making the first three methods for each just run the fourth method with the parameters you passed it, plus the type.

 

For example...

 

 

 def self.shop_add_item(shop_name,id,price=nil)
shop_add(shop_name,id,0,price)
end

def self.shop_add_weapon(shop_name,id,price=nil)
shop_add(shop_name,id,1,price)
end

def self.shop_add_armor(shop_name,id,price=nil)
shop_add(shop_name,id,2,price)
end

def self.shop_add(shop_name,id,type,price=nil)
use_def_price = price.nil?? 0 : 1
specify_price = price.nil?? 0 : price
flag = false
$game_temp.dynamic_shop[shop_name] = [] if !$game_temp.dynamic_shop[shop_name]
$game_temp.dynamic_shop[shop_name].each do |item|
$game_temp.dynamic_shop[shop_name].delete(item) if item[0] == type && item[1] == id
end
$game_temp.dynamic_shop[shop_name].push([type,id,use_def_price,specify_price,flag])
end

 

Something to that effect would be good for adding items/weapons/armors. It would certainly cut down on the number of lines of code. Makes it user-friendly, while still allowing those who want to do it the more direct way (with fewer subroutines) to just use shop_add and specify the type themselves. You could also go through the do_sell function and replace

ESTRIOLE.shop_add_item(@sell_add_new_goods,@item.id)
with

ESTRIOLE.shop_add(@sell_add_new_goods,@item.id,0)
and do the same with ESTRIOLE.shop_add_weapon and ESTRIOLE.shop_add_armor.

 

I would also like to suggest, if possible, making it so that you can choose to have only items of specific categories show up from a particular list. So, for example, I can have a single master list of everything that can be sold, but can open up instances of that shop that only show the weapons, the armor, etc. Though, it may be better to just use separate shops for that...

Edited by Nate McCloud

Share this post


Link to post
Share on other sites

updated the script to v 1.3

rewrite most part of the script and make it easier to use.

also create game_interpreter method for shortening the script call. (super short now)

 

now you can use:

 

 

 how to use:
 ===============================================================================
 1)to call dynamic shop. use script call:
 
 d_shop(shop_name,purchase_only,sell_add_goods_type)
 
 shop_name[required] => the name you assign for that dynamic shop
 purchase only => set this to true if you want the shop to cannot sell item
                  default set to false
 sell_add_goods_type => "All" => will add all item/weapon/armor sold to buy list
                        "Item" => will add only item sold to buy list
                        "Weapon" => will add only weapon sold to buy list
                        "Armor" => will add only armor sold to buy list
                        not case sensitive. if left nil/blank it will not add
                        anything to buy list
                        
                        you could also create your custom category
                        by adding notetags to item/weapon/armor. example in item1
                        we add notetags:
                        <shop_cat: potion>
                        notetags not needed to case sensitive with category.
                        then when we set sell_add_goods_type to "Potion" then
                        when we sell item1. it will add it to buy list. other item don't
                        
                        and of course we have reserved word not to use:
                        all, item, weapon, armor, none
                        
 some example usage:
 -) since only shop_name is required you can skip the other
 d_shop("Castle Ugly Shop")
 will call "Castle Ugly Shop" and party can sell items.
 if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
 
 -) can set the sold item to added to buy list
 d_shop("Castle Ugly Shop",false,"ALL")
 will call "Castle Ugly Shop" and party can sell items.
 if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
 then every item/weapon/armor sold will added to buy list.

 -) can set to add only "item" sold to added to buy list. weapon and armor not
 d_shop("Castle Ugly Shop",false,"Item")
 will call "Castle Ugly Shop" and party can sell items.
 if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
 then every item (only) sold will added to buy list. weapon and armor will be ignored
 
 -) can use custom category you defined in notetags.
 d_shop("Castle Ugly Shop",false,"Sword")
 will call "Castle Ugly Shop" and party can sell items.
 if "Castle Ugly Shop" not exist then it will call empty shop (sell only)
 then every item/weapon/armor that have notetags <shop_cat: sword>
 sold will added to buy list.
   
 ===============================================================================
 
 2)to add goods to your dynamic shop.
 
 use this script call:

 d_shop_add_goods(shop_name,goods,price)

 shop_name[required] => the name you assign for the dynamic shop. if the name haven't been assigned it will create new one
 goods [required] => item you want to add for example $data_items[1], $data_weapons[1], $data_armors[1], etc.
 price => if you want to set the price. if blank it will use default price set in database

 example usage:
 d_shop_add_goods("Goldsmith",$data_weapons[10],1000)
 will add to "Goldsmith" shop. weapon id 10 in database. with the price 1000.
 
 ===============================================================================
 
 3) to remove goods for you dynamic shop.
 
 use this script call:
 
 d_shop_rem_goods(shop_name,goods)
 
 shop_name[required] => the name you assign for the dynamic shop. if the name haven't been assigned it will create new one
 goods [required] => item you want to remove for example $data_items[1], $data_weapons[1], $data_armors[1], etc.

 example usage:
 d_shop_rem_goods("Goldsmith",$data_weapons[10])
 will remove weapon id 10 in database from "Goldsmith" shop.
 
 ===============================================================================
 
 4) profit $$$
 
 ===============================================================================
 
 i also set that whenever you add item/weapon/armor to certain dynamic shop.
 it will search for that shop goods. if it contain same item/weapon/armor it will
 be overwritten. so if you first add item1 for 100 gold. shop will sell it for 100 gold
 later you add item1 for 10 gold. then the price will be changed to 10 gold.

 

 

 

extra credit for Nate McCloud for pointing the bugs in v 1.2

Edited by estriole

Share this post


Link to post
Share on other sites

Awesome! Unfortunately, though, the duplication bug is still there.

To reproduce the bug:
1. Call the script to open a dynamic shop.
2. Sell something to them that they'll add to their shop.
3. Exit the shop.
4. Call the script to open that same shop.
5. Sell something else to them. That and anything else you sell to that shop from that point forward will appear twice in the shop list.

EDIT: Estriole, I fixed it! Holy crap, I fixed the duplication bug! (Well, WE did, actually--you did most of the work, I just found and added in some missing code.)

When you added "if !chk = old_goods rescue false" to the end of the .push(array) in ESTRIOLE.shop_add_goods, you forgot to also add one to the end of the .push(array) in @buy_window.add_new_goods. When I did that, the duplication bug disappeared!

All that's missing now is a way to sort the array by item type, custom category, and ID, in that order.

EDIT2: Got that covered (sorta--don't think I'll be able to cover custom categories). At the end of ESTRIOLE.shop_add_goods, after the .push(array) line, add this:

$game_system.dynamic_shop[shop_name].sort_by! { |i| [i[0], i[1]] }

And at the end of @buy_window.add_new_goods, also after the .push(array) line, add this:

@shop_goods.sort_by! { |i| [i[0], i[1]] }

That will sort the shop items first by type, then by ID, whenever a new item is added to the shop.

Edited by Nate McCloud

Share this post


Link to post
Share on other sites

Awesome! Unfortunately, though, the duplication bug is still there.

 

To reproduce the bug:

1. Call the script to open a dynamic shop.

2. Sell something to them that they'll add to their shop.

3. Exit the shop.

4. Call the script to open that same shop.

5. Sell something else to them. That and anything else you sell to that shop from that point forward will appear twice in the shop list.

 

EDIT: Estriole, I fixed it! Holy crap, I fixed the duplication bug! (Well, WE did, actually--you did most of the work, I just found and added in some missing code.)

 

When you added "if !chk = old_goods rescue false" to the end of the .push(array) in ESTRIOLE.shop_add_goods, you forgot to also add one to the end of the .push(array) in @buy_window.add_new_goods. When I did that, the duplication bug disappeared!

 

All that's missing now is a way to sort the array by item type, custom category, and ID, in that order.

 

EDIT2: Got that covered (sorta--don't think I'll be able to cover custom categories). At the end of ESTRIOLE.shop_add_goods, after the .push(array) line, add this:

$game_system.dynamic_shop[shop_name].sort_by! { |i| [i[0], i[1]] }

And at the end of @buy_window.add_new_goods, also after the .push(array) line, add this:

@shop_goods.sort_by! { |i| [i[0], i[1]] }

That will sort the shop items first by type, then by ID, whenever a new item is added to the shop.

actually... you don't have to add that if. since i already add return above it when the old goods.

but i do some mistakes there. instead of old_goods i use @old_goods.

 

change the line above that push array in window shop buy:

 

return if @old_goods

to

 

return if old_goods

 

simple and ridiculous mistake :D.

 

i'll fix it later.

 

for the sorting part. i don't cover that before because i think that should be handled in another shop script.

because i'm worry about the conflict with other people shop script that have sorting feature.

but i guess adding that with some setting in configuration to turn it on/off didn't hurt. m

maybe i'll add some feature to choose sorting type rule by store too if i have time.

Share this post


Link to post
Share on other sites

Ah...yes, changing that did the trick. @_@ I guess the fix was simpler than I thought.

Ahh, okay. Yeah, probably might be best to put, like, a constant at the top of the script that will switch the script's built-in sort function on or off, and maybe build in some pre-defined sorting methods that can be chosen from in another constant.

Share this post


Link to post
Share on other sites

updated the script to v.1.4

 v 1.4 - 2014.06.05 => fix typo bugs that cause duplicated item. add simple sorting feature
                       use script call before calling the shop:
                       $game_system.dshop_sorting_rule = x
                       change x to these built in sorting rules:
                       :type         #will sort by type. item, weapon, armor
                       :id           #will sort by id. low id -> high id
                       :type_id      #will sort by type then by id
                       :rtype        #reverse of :type -> armor, weapon, item
                       :rid          #reverse of :id -> high id -> low id
                       :rtype_id     #sort by: armor, weapon, item, then low id -> high id
                       :rtype_rid    #sort by: armor, weapon, item, then high id -> low id
                       if you understand scripting you can add your own sorting rules.
                       also... setting the sorting rule as :none or nil will deactivate that sorting rule
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×