Shop Manager

Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

This script enhances the game shop, providing useful options that allow you to customize each shop good individually.

This script provides functionality for remembering a shop’s “state”. Each shop is uniquely identified by a shop ID, and if you visit the same shop repeatedly, you should see the same settings as when you left. For example, if a shop holds 10 potions, and you bought 5, then you can expect that the next time you visit the shop, it will only have 5 potions remaining.

The Shop Manager provides the following functions for setting up shops

  • Hide conditions – hide goods from being displayed
  • Disable conditions – prevent goods from being selected
  • Price formulas – use a formula to set the price of an item

Additional shop-related functionality can be easily added using the Shop API.
Note that one event can only have one shop, because all of the information is tied to that event.

Download

Script: download here

Plugins

Sell Only Shop – You can only sell items in this shop.
Common Event Shop – set up common event items for sale
Learn Skill Shop – buy and learn skills directly from shops
Tactics Ogre Crafting Shop

Usage

Managing Shops

The shop manager allows you to assign an ID to your shop. This is the name that you will use to refer to a specific shop throughout the game.

The ID can be anything you want, but you may want to use something that is easy to remember and organize.

To access a specific shop, you first start by making a script call

get_shop(YOUR_SHOP_ID)

Followed by the shop processing command. Here is an example of how it might look:

shopManager2

If you ever need to refer to a specific shop in a different event, you can simply use the same shop ID.

Shop Options

This script provides a number of built-in shop options for you to customize your shop goods for each shop.

Each shop option requires you to pass in a “good ID”, which is basically the order that the items appear in your “shop processing” list. The shop good at the top of the list has a good ID of 1, the next has a good ID of 2, and so on.

All shop options must be set before the shop processing command.

The following variables are available for all formulas:

v - game variables
s - game switches
p - game party

Hiding Goods

You can prevent a shop good from appear in the shop list by using a “hide formula”. To set a hide formula for a particular good, use the script call

hide_good(good_id, hide_formula)

Disabling Goods

Disabling a shop good means the player can’t buy it, but it will still appear on the list. The default windows simply change the color of the good to indicate that it can’t be selected. You can disable a shop good using a “disable formula”, and can be set using the script call

disable_good(good_id, hide_formula)

Price Formulas

Each shop good can have a custom price by defining a “price formula”. The price is evaluated when the player visits the shop, so it is dynamically generated based on the current game state. To set a price formula, use the script call

price_good(good_id, price_formula)

shopManager1

Adding shop goods

You can add shop goods programmatically using script calls. To add a shop good, use

add_shop_good(good_id, item_type, item_id)
add_shop_good(good_id, item_type, item_id, price)

Where the good_id is the ID that will be assigned to this shop good, the item_type is one of :item, :weapon, or :armor, and the item_id is the ID of the item. If the price is not specified, then the default price is used. Note that price formulas are not available in this script call unfortunately.

Developers

Here are some specifications that I have written.

Have a look through each class to see what is available for use.
If you have any suggestions that will improve the base script (ie: this),
I will consider adding them.

Shop Manager

This module serves are the interface for all shop-related queries. It handles
how shops are stored for you so that it is easy to properly obtain a reference
to a shop.

Game Shop

This script treats a shop as a concrete object. A shop is created the first
time it is accessed, and will be stored with the game for the remainder of
the game.

A very basic shop is provided, which manages what items are available for sale.
All shops are stored in a global Game_Shops hash in $game_shops

Managing shops

This script assumes shops are only called through events or common events.
Troop events are not supported.

A shop, by default, is identified by a map ID and an event ID.
Shops that are called via common events will have a map ID of 0.

If you specify a custom shop ID using the get_shop call, then that will be the shop ID that is used instead of the map ID and event ID.

In order to determine whether a normal event or a common event called the
shop, the “depth” of the interpreter is used.

When depth = 0, then it is a normal event
When depth > 0, then it is a common event

The shop processing should be handled appropriately depending on the depth

This script assumes that an event is triggered through “normal” interaction;
that is, you can only interact with events within a map. Any events that should
be treated as the same event should be done as a common event call.

Shop Goods

Rather than storing all goods as a simple array of values, this script
provides a Game_ShopGood class. You can use this to store any additional
information that you want.

All shop related scenes and windows MUST provide support for handling shop
goods. While backwards compatibility is provided for the default scripts,
additional methods have been defined to allow you to retrieve the currently
selected shop good.

Shop Options

Since there isn’t actually a way to setup individual shop goods, external
approaches must be used. There is not much specification here yet, so it
is up to you how you wish to populate your ShopGood objects.

I have provided the following method in Game_Interpreter that you can
use for setting up shop goods

def setup_good(good, id)
end

It receives a ShopGood object as its first parameter, and the good ID as its second.
More information on shop options can be found here

Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

You may also like...

65 Responses

  1. Dangime says:

    I’m having a little trouble with the shop manager I hope you can help me with. A few of my items seem to complete fail to interact with the shop manager for some reason. Usually if there’s an error in the code, the error is fatal and obvious, but I’ve been over there buy, sell, and hide lines serveral times and can’t identify what’s making them basically ignore the interaction with the shop manager when 50 other times are doing so just fine. Have you had any other time when someone described something like this happening? The items just appear as normal (at standard price, not hidden) instead of interacting with the shop manager.

    I’m the guy that had you make the add on script that tracks the number of items sold if you remember.

    • Hime says:

      Try to find a way to reliably reproduce the issue. It probably isn’t a random thing.

      • Dangime says:

        Is there perhaps some maximum numner of items the shop manager was designed to stop at? I am asking quite a bit, and all the items that are having problems have item IDs of 50+. None of the earlier ones show any problems.

        • Hime says:

          I don’t think there are such limitations. So when you add an item with ID 60 (and only that item), it just doesn’t show up?

          • Dangime says:

            The problem started with item ID 49, and none of them after that point properly reacted to shop manager. Scripts targeted for them to hide, or adjust buy or sell prices didn’t do anything. The items just appeared on the shop list as normal at standard prices.

  2. Anonymous says:

    Google Translator:

    I get this error: “253:. In ‘get_shop’ Undefined method ‘[]’ for nil: NilClass, NoMethodError”
    Any ideas??

    • Anonymous says:

      I add: This occurs when I use a regular store.

      • Hime says:

        What is a “regular store”? Does this occur in a new project? How are you calling your shop?

        • Anonymous says:

          Sorry. I mean a “normal store”, in other words, a default store.

          • Hime says:

            Does the error occur in a new project? How are you calling the store?

          • Anonymous says:

            1_ No, not a new project.
            2_ It has no name, my question is not how to set up a new store.

            Sorry, my question is which or if there is a “call script” that allows me to use the “default store” of the program. I was testing some things, but it always gives me an error

          • Hime says:

            If it does not occur in a new project then you need to determine whether it is a compatibility issue with another script. If the issue occurs in a new project then it may be an issue with the script, but so far I have not had any issues opening a “default store” through events.

          • Anonymous says:

            Thanks for everything. You were right, the problem was the inconsistency he had with another script, but then put it down, and was solved.

  3. JohnL says:

    Welp, i made a multiple choice shop (you choose what shop you can go to in choices), and the first shop (or the other shop if you select that first) works fine, but when i choose the other shop, it opens the first shop you opened.

    WELP??

    • Hime says:

      In order to have multiple shops in a single event, you must use the get_shop script call detailed in the instructions on this page. Otherwise, the script will default to some generated shop ID which is based on the event ID and map ID, which doesn’t support multiple shops in a single event on its own.

  4. Ron says:

    So I’m having an issue that I’ve just spent three hours trying to figure out, but I just can’t seem to get past it. I’m trying to use the Tactics Ogre Crafting Shop script, which calls for both Info Pages Window, and Shop Manager. But whenever the game tries to call the TOCraftingShop script, I get a Shop Manager crash message. Specifically this:

    Script ‘Shop Manager’ line 271: NameError Occurred.
    Uninitialized constant Game_TOCraftingShop

    The line of error is: return Object.const_get(shop_type.to_sym)

    I’ve currently have the scripts stacks as follows:

    Shop Manager
    Info Windows Pages
    Tactics Ogre Crafting System

    I’ve also toyed with rearranging them (with TOCraftingShop always on the bottom) because at this point nothing’s going to hurt something that’s already not working for me lol.

    Of Note: I don’t have any other equipment or shop altering scripts. The only other scripts I’m using are Yanfly’s Sideview Battlers/Enemy HP Bars and MogEx’s Battle Hud. I hope this is enough information, if not I’ll gladly supply more, I just need some help, and any suggestions are appreciated.

  5. Dangime says:

    I am getting an error that says unexpected * when I reach the 10th entry on my shop. I don't understand the problem since it's just a cut/paste of the last 9…so I wonder if you can see a syntax error here or maybe there's a problem with double digit item ids?

    <code>
    price_good(10, "v[21] + v[22] + v[23] + 100
    *
    455 / 100")
    </code>

    • Hime says:

      You can't split up your formula like that since the interpreter is very strict on where you break lines. Consider removing those spaces to try to squeeze it on one line, or just move the whole formula onto a second line)

      • Dangime says:

        Well I don't want a page break…but the script box for the editor is tiny! Is there somewhere else I can edit these?

        Even formated as….

        price_good(10, "v[21] + v[22] + v[23] + 100
        * 455 / 100")

        It's the same problem.

  6. Ben says:

    due to the shops being identified by event_id, I have problems when a single event offers two different shops, based on a player's choice. ("Would you like to buy goods, or are you here for information?" asks the NPC, opening up either a normal shop, or common event shop, as appropriate.)

    I see why this happens, in ShopManager.setup_shop, and am going to modify your script, for my game, to allow override IDs to be provided in the event…

    I'm not asking for help – I can work around this myself – but I wanted to let you know that this is a possible bug.

    P.S. thanks for all the scripts you make! RPG Maker is made better thanks to scripters such as yourself!

    • Ben says:

      actually, in case you are curious, I've opted to do this:

      in your Game_Interpreter.command_302 override, I added this line, near the top:

      shop_id = @shop_id || shop_event_id

      I then pass this shop_id along, instead of shop_event_id, in this line:

      shop = ShopManager.setup_shop(shop_map_id, shop_id, goods, @params[4], shop_type)

      finally, I reset @shop_id to nil in your Game_Interpreter.clear override

      this allows the event to override the id, when needed, by adding a script block containing @shop_id = "my unique id here"

      I hope this is helpful to you; thanks again 🙂

      • Hime says:

        I like the backwards compatibility where if a user doesn't specify an ID, then it will default to the event ID.
        I will go with that as the solution, since thinking about it again, if you’re specifying your own ID, then it’s up to you how you wish to organize your ID’s.

  7. Virex says:

    So, i'm a noob to this whole scripting/notetag deal. I'm using this shop manager script and i wanna use it to it's full potential, but i can't seem to figure out how to create the formulas i need.

    How do you set up so that it requires a switch?? And I wanna set it up to disable if the player already has a item/weapon/armor.

    • Hime says:

      You'd first set up your shop as usual. Then you would add the appropriate script calls before the shop processing command. The reason why the shop is set up is so that you know the order that the items are placed. So if you want to make it so that the first item on the list is disabled if a switch 9 is not ON, you would write

      disable_good(1, "s[9]")
      

      And if you you want to make it so that item 3 is disabled if the party has weapon 4, you would write

      disable_good(3, "$game_party.has_item?($data_weapons[4])")
      

      Unfortunately you will likely run into problems with not having enough space to fit it on a line so you need to do some tricks to condense it to something like

      w = "$data_weapons[4]"
      s = "$game_party.has_item?(#{w})"
      disable_good(3, s)
      
      • Virex says:

        Thank you so much Hime for taking the time to respond, honestly didn't expect such a fast response. But i'm getting an error. I just tried to implement the switch using my own information. disable_good(5, &quot;s[1]&quot;) I'm getting error

        Script 'Game_Interpreter' line 1411: SyntaxError occurred.

        I have Yanfly's ShopOptions script in my game as well. Would that have an affect?

        • Hime says:

          No, it's wordpress trying to be helpful and replacing quotation marks with something else.

          Try again.

          • Virex says:

            so it's working but when switch 1 is OFF, the item is disabled. but wen i turn it ON it's still disabled.

          • Hime says:

            Then it's not working. Have you tried it without yanfly's scripts

          • Virex says:

            I opened up a new project to see if it would work. I got it. Thanks a ton.

          • Virex says:

            So if I wanted to to disable a good if actor 1 has an item equiped would I write

            disable_good(2, "$game_actors[1].equip? (#{w})

  8. Blank5 says:

    I'm having an issue where calling a shop with a common event will call the same shop regardless of which common event called it. Is this intended? If so I was wondering if there was a quick tweak that would allow common event ID to be taken into account when creating a shop ID.
    Awesome script by the way. I really like the common event shop add-on.

    • Hime says:

      That is how it is supposed to work, and that's what happens for me. This isn't happening for you?

      • Blank5 says:

        Sorry for the unclear post. The issue is I have multiple shops I want to be called using different common events. Whatever common event shop gets accessed first in the game seems to be the one that gets set up as the one and only common event shop. If the player then tries to access what I want to be a separate common event shop it instead loads the original even though the two are called using two separate common events.

        • Blank5 says:

          I just realized my post was unclear again, when I use the terminology "common event shop" I'm referring to a shop called by a common event, not a shop that sells common event items. Sorry again, and thanks for the help!

  9. RJ says:

    Would it be possible if, say, there was only a buy (or only sell) shop option where the player wouldn't have to click into
    Buy -> Itemlist -> Cancel (return to Buy/Cancel menu)
    but rather automatically entered the Buy list (and cancel would close the shop)?

    Basically, bypass the Buy/Cancel menu and directly go into the list of goods for sale, if the shop is buy-only/sell-only.
    Another thing is would it be possible to change the Buy/Sell menu text per shop set up to say, for example "See Mark's Wares", and another would say "Shop Jane's Weapons", etc.

    • Hime says:

      Look for a script that modifies shops to bypass the buy/sell/cancel selection. I don't have one that does that.

  10. fiblo says:

    It worked! You're a genius! Thank you.

  11. fiblo says:

    I'm having an issue with the Shop Manager when loading from a save file.

    In my game, you can only save through events. When you load a save file, you are still in the event, and there is an option to go to the shop (before exiting the event).

    After a save file is loaded, if the player chooses shop processing prior to exiting the event, there is an error. If the player exits the event first, then re-enters the enter and chooses shop processing, the error does not occur.

    I tried to troubleshoot the error, thinking maybe I needed to refresh or initialize the item database to fix it. I didn't have any luck. The RGSS console says:

    Game_Interpreter:1411:in 'eval':undefined method '[]' for nil:NilClass, NoMethodError
    from <eval>:1:in 'command_355'
    from Game_Interpreter:1411:in 'eval'
    from Game_Interpreter:1411 in 'command_355'
    from Game_Interpreter:197:in 'execute_command'
    from Game_Interpreter:103:in 'run'
    from Game_Interpreter:60: in 'block in create_fiber'

    • Hime says:

      Post a screenshot of your event.

      • fiblo says:

        http://imgur.com/ZIvNfk2

        It is easy to duplicate the error using the event shown in the screenshot.

        Playtest, save the game, then exit the game. Playtest again, load the save, then choose the shop option. The error occurs during shop processing.

        • Hime says:

          I don't have a proper solution to this without overwriting things.

          Add this below the script

          class Game_Interpreter
            def marshal_dump
              [@depth, @map_id, @event_id, @list, @index + 1, @branch, @shop_options]
            end
          
            def marshal_load(obj)
              @depth, @map_id, @event_id, @list, @index, @branch, @shop_options = obj
              create_fiber
            end
          end
          
          • fiblo says:

            I added it at the end of the Shop Manager script. The error is now:

            http://imgur.com/jV2GptZ

          • Hime says:

            Hmm ok I've updated the script to address the issue. The problem now is that when you reload your game, anything that was processed before is gone, so if you have custom shop related logic, you need to make sure they done after the save.

            You can take out the temp fix from before.

  12. Revali Senai says:

    I'm having problem with the rest of shop items having the same sell price as the first item on the list. I used sell only script call before the shop processing and nothing more. I then tried to use sell_good and good_price to specify the price but it didn't work. What am I doing wrong? .

    • Hime says:

      If you're using sell-only shop you only need to use price_good instead of sell_price. I don't think sell-only shop is compatible with it the sell price formulas but it doesn't matter in this case.

      • Revali Senai says:

        I noticed when I remove the call script for the sell only shop, the price issue goes away.
        Here's how I have it set up:
        Script:@shop_type="SellOnlyShop"
        Script:price_good(1, "50")
        price_good(2, "200")
        price_good(3, "500")
        Shop Processing [item 1]
        [item 2]
        [item 3]
        The item buy price is accurately shown in the shop command, but the sell price for item 1-3 all become 50 or the amount I set for the first item.

        Thanks so much for the quick response..

  13. RabidPiglet says:

    Hey Hime – I am quite new at this and I am attempting to utilize your Shop Manager and Learn Skill Shop. I have a vanilla setup going with adding both your scripts under the module field, each time I go to run a test I get the following error:

    Script ‘ShopManager’ line 353: NameError occurred

    undefined method ‘reserve_common_event’ for class ‘Game_Temp’

    Using my amateur eyes, I don’t see anything wrong – but I\ll be honest, I am not sure what I am looking for exactly. Any help would be appreciated.

    Thank you

  14. I’m trying to add this script into my project, but it keeps giving me a NoMethodError.

    A fairly up-to-date script list can be found here: http://gamemakere.wordpress.com/2013/05/22/a-quick-thank-you/

    I’ve tried erasing Yanfly’s Shop Options, as I figured a conflict would most likely be there, but that did not work. Other than that, I haven’t tried much, scripting is still something that is far beyond my ken.

  15. BloodTheDhamphir says:

    I keep getting an error coming from line 280 saying the stack level is too deep. I don’t know what is causing it.

    The way I have my materials set up is.
    Info Pages Window
    Tactics Ogre PSP Crafting System
    Shop Manager
    Tactics Ogre Crafting Shop

    I have not modified any of the other scripts.

  16. CT_Bolt says:

    Awesome script! Working great so far… Any way you might be able to incorporate the script below in the future for example the store has no stock left it would turn into a sell-only store.

    http://www.rpgmakervxace.net/topic/558-sell-only-shop-ported-from-vx/

    • xtsukihime says:

      Looks simple enough. I am still considering what to do about the scene, since my future plans include handling different types of shops with their own scenes. A SellOnly shop would be an example, where you setup your goods and then say “this shop is sell only”.

  1. March 12, 2014

    […] Shop Manager has been updated to support custom sell price formulas for a shop. By default, the selling price […]

  2. August 4, 2014

    […] update has been made to the Shop Manager to address a major limitation that developers may have found quite […]

Leave a Reply

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax