Make merchant to detect when you don't buy anything

I just finished Step 8: Creating Shops and noticed the message from the "travelling merchant" is always the same even if you don't buy anything.

Should I change the text for something more neutral like "Thanks for coming by" or is there a way to add text in case you don't spend gold?

Really noob and even dumb question since I'm still doing the built-in tutorials but I could not find anything about it.

Thanks in advance.
as a very basic solution you can save the amount of gold the party has as a variable before the shop processing, then after shop processing have a conditional branch where you see if the variable's changed, with a different bit of dialogue used depending on if any gold was spent or not
I generally use a more generic message that isn't the usual "thanks for buying" message, but you could easily set up a .kbranching message for if you buy or don't buy anything. It simply involves setting a variable at the beginning of the shop event that tracks your current gold, then check to see if the amount has gone down and customize a message based on that.

EDIT: Ninja'd.
as a very basic solution you can save the amount of gold the party has as a variable before the shop processing, then after shop processing have a conditional branch where you see if the variable's changed, with a different bit of dialogue used depending on if any gold was spent or not
I generally use a more generic message that isn't the usual "thanks for buying" message, but you could easily set up a .kbranching message for if you buy or don't buy anything. It simply involves setting a variable at the beginning of the shop event that tracks your current gold, then check to see if the amount has gone down and customize a message based on that.

EDIT: Ninja'd.

Thank you so much. After an hour and a half I made it work.. Slow learner here but it really was very fullfilling.

By the way, just a big IF that I guess it is harder to solve than to leave it like this or use a simpler solution but I'll take it as learning. What if the player buys something and then sells something else too and ends up with the same amount of gold? The text showing would be as if the player did not buy anything. Is there a way to avoid that case?

Thanks in advance again!
In that case, $gameParty.numItems() before the shop. Then check if it has changed. Now it still wouldn't work if the player sells the item then buys it back for the same amount of money But I guess in that case they technically didn't really buy anything.
In that case, $gameParty.numItems() before the shop. Then check if it has changed. Now it still wouldn't work if the player sells the item then buys it back for the same amount of money But I guess in that case they technically didn't really buy anything.
So I would add that at the same time that the Gold variable or instead of it? I guess if those two things are checked, the merchant would really know if you bought something. Unless the player has the same amount of money and items after the trade..
You would add both since $gameParty.numItems() just counts how many items you have. It can not detect if they are different items. Checking amount of gold should be fine though, This is a bit overkill. Unless you are working with small numbers it would be pretty rare to even get the same amount of money afterwards.
You would add both since $gameParty.numItems() just counts how many items you have. It can not detect if they are different items. Checking amount of gold should be fine though, This is a bit overkill. Unless you are working with small numbers it would be pretty rare to even get the same amount of money afterwards.
Yes, it is quite overkill I know, sorry. I guess it is enough with those two checkers. Thank you so much for answering this weird IF lol.
While I support the previous posts' recommendations of using some variables and checking them afterwards, if you want to be able to handle the rare edge case where it may not work due to buy/sell math balancing out, here is a plugin to do so:

Code:
/*:
* @plugindesc Sets a switch to ON if the party bought something in a shop,
* then to OFF whenever a new shop interaction starts.
* @author Zevia
*
* @help Specify the number of the switch to be reserved for confirming whether the
* party bought something in a shop.
* Whenever the shop Scene is initiated, the switch is set to OFF. If something
* is purchased, the switch is set to ON.
*
* @param switchNumber
* @text Confirm Buy Switch Number
* @type switch
* @desc The switch number to set ON if an item is purchased or
* OFF if not
* @default 15
*/

(function(module) {
    'use strict';

    var Zevia = module.Zevia || {};

    var switchNumber = parseInt(PluginManager.parameters('ConfirmShopBuy').switchNumber);
    if (isNaN(switchNumber)) {
        throw new Error(
            'Configuration Error: ConfirmShopBuy requires a valid switch number to be' +
            ' specified in the setup parameters'
        );
    }
    Zevia.SceneShopCreate = Scene_Shop.prototype.create;
    Scene_Shop.prototype.create = function() {
        Zevia.SceneShopCreate.call(this);
        $gameSwitches.setValue(switchNumber, false);
    };

    Zevia.SceneShopBuy = Scene_Shop.prototype.doBuy;
    Scene_Shop.prototype.doBuy = function(number) {
        Zevia.SceneShopBuy.call(this, number);
        $gameSwitches.setValue(switchNumber, true);
    }
})(window);

You'll want to copy it into a file called ConfirmShopBuy.js (or change the 'ConfirmShopBuy' in the Plugin to whatever you feel like naming it). Alternatively, you may click here and save this link as a .js file.

In the setup, pick an unused switch in your game to use. Every time a new shop scene is started, the switch is set to OFF. If the party buys anything, the switch is set to ON until another shop scene is started. You can also manually set the switch OFF after doing whatever you want post-scene, if you prefer.

May have compatibility issues with Plugins that overwrite the create and doBuy methods of the Shop Scene. If placing this Plugin beneath other Plugins doesn't solve the problem, someone will need to write a compatibility fix.
Oh right. The tutorial. I had a bit of a laugh with that as I changed the generic text.

I dunno, it might be better just to make a choice. "Yes I'll browse your shop." or " No, I want some beer!"

If they don't shop then he can yell " You cheapskates!"

Well this way may be simpler but it'll save you a few headaches instead of using a Control Variable.
I dunno, it might be better just to make a choice. "Yes I'll browse your shop." or " No, I want some beer!"

If they don't shop then he can yell " You cheapskates!"

Well this way may be simpler but it'll save you a few headaches instead of using a Control Variable.

It seems reductive to suggest that OP should not try to accomplish their goal because it’d be easier to do something that the OP has already acknowledged as a solution (a generic message) but wants to improve/iterate upon (a message based on actually buying something).

Especially when they have already received a great gamut of replies from evented solutions to a custom plugin.

That, and… if you think using variables is a headache, maybe either invest heavily into painkillers or just quit while you’re ahead.

I was actually thinking of a way that it might work. Went into MZ to work on it, trying to find a way to check the Gold and then change the Variable so that he says something different if the Gold is equal to what it was before. Even if it is, I concur that it wouldn't change anything if the Gold was the same.

I just suggested something simple for simplicity's sake, since I assume he's new to the Application.

Get off my case.
I was looking into the code for you just to see if you could do it in-game, but I don't see an option that checks Gold. There is a Conditional Branch that checks if your Gold Amount is higher or lower than a given amount but since you'll be getting stuff with the Gold, that doesn't much help if it changes.

You're better off with that Plug In @Zevia gave you. Sorry if I couldn't help further.
I was looking into the code for you just to see if you could do it in-game, but I don't see an option that checks Gold. There is a Conditional Branch that checks if your Gold Amount is higher or lower than a given amount but since you'll be getting stuff with the Gold, that doesn't much help if it changes.
Thus the point of the variables.
I wrote a plugin for this type of thing, once upon a time. I only tested it in MZ, but I'm fairly certain it works in MV as well. It will let you determine whether or not the player bought anything or sold anything, as well as the amount of currency they spent/earned.
I understand that part @Sword_of_Dusk. A variable needs to have a base though. And you need the Variable to change in order to generate a different response. In this case, I don't think there is a way to check if the value of the Gold has changed between the Shopping trip, at least with the basic stuff. It requires plugins which these fine folks seem to have.
Gold is in the Control variable->Game Data->Other
While I support the previous posts' recommendations of using some variables and checking them afterwards, if you want to be able to handle the rare edge case where it may not work due to buy/sell math balancing out, here is a plugin to do so:

Code:
/*:
* @plugindesc Sets a switch to ON if the party bought something in a shop,
* then to OFF whenever a new shop interaction starts.
* @author Zevia
*
* @help Specify the number of the switch to be reserved for confirming whether the
* party bought something in a shop.
* Whenever the shop Scene is initiated, the switch is set to OFF. If something
* is purchased, the switch is set to ON.
*
* @param switchNumber
* @text Confirm Buy Switch Number
* @type switch
* @desc The switch number to set ON if an item is purchased or
* OFF if not
* @default 15
*/

(function(module) {
    'use strict';

    var Zevia = module.Zevia || {};

    var switchNumber = parseInt(PluginManager.parameters('ConfirmShopBuy').switchNumber);
    if (isNaN(switchNumber)) {
        throw new Error(
            'Configuration Error: ConfirmShopBuy requires a valid switch number to be' +
            ' specified in the setup parameters'
        );
    }
    Zevia.SceneShopCreate = Scene_Shop.prototype.create;
    Scene_Shop.prototype.create = function() {
        Zevia.SceneShopCreate.call(this);
        $gameSwitches.setValue(switchNumber, false);
    };

    Zevia.SceneShopBuy = Scene_Shop.prototype.doBuy;
    Scene_Shop.prototype.doBuy = function(number) {
        Zevia.SceneShopBuy.call(this, number);
        $gameSwitches.setValue(switchNumber, true);
    }
})(window);

You'll want to copy it into a file called ConfirmShopBuy.js (or change the 'ConfirmShopBuy' in the Plugin to whatever you feel like naming it). Alternatively, you may click here and save this link as a .js file.

In the setup, pick an unused switch in your game to use. Every time a new shop scene is started, the switch is set to OFF. If the party buys anything, the switch is set to ON until another shop scene is started. You can also manually set the switch OFF after doing whatever you want post-scene, if you prefer.

May have compatibility issues with Plugins that overwrite the create and doBuy methods of the Shop Scene. If placing this Plugin beneath other Plugins doesn't solve the problem, someone will need to write a compatibility fix.

Thank you so much for your answer and your plugin but I think I am a real noob since I was not able to make it work...

1698246348902.png


ConfirmShop is number 15 switch. I tried different approaches but could not make it work. The switch is always OFF unless I manually make it ON. I am sorry if I forgot to do something... ^^'

I wrote a plugin for this type of thing, once upon a time. I only tested it in MZ, but I'm fairly certain it works in MV as well. It will let you determine whether or not the player bought anything or sold anything, as well as the amount of currency they spent/earned.
On the other hand I somehow made this plugin work first try even though I thought it would be harder! Just used the "gold spent" variable and made a conditional branch in case the gold spent is 0 and that was all.

1698247037602.png


Really thankful for the plugins, saved both with your names on it in case I have to credit in the far future!

I was looking into the code for you just to see if you could do it in-game, but I don't see an option that checks Gold. There is a Conditional Branch that checks if your Gold Amount is higher or lower than a given amount but since you'll be getting stuff with the Gold, that doesn't much help if it changes.

You're better off with that Plug In @Zevia gave you. Sorry if I couldn't help further.

I'll keep the "choice" option in my mind as well as the "gold variable" option. Both are elegant in their simplicity!

Thank you very much to everyone that came by and leave a comment, a tip or way to improve. I think I've learned A LOT more in these past 24h than in a full week lol.
Thank you so much for your answer and your plugin but I think I am a real noob since I was not able to make it work...

ConfirmShop is number 15 switch. I tried different approaches but could not make it work. The switch is always OFF unless I manually make it ON. I am sorry if I forgot to do something... ^^'
I have nigh-on the exact same event and it works with a default project for me:
Capture.PNG

If you hit F8 while you're playtesting, you can open up the developer console and take a look for red error text perhaps suggesting that there's a problem with the configuration.

Perhaps also double check that the file is named, exactly, "ConfirmShopBuy.js".

Alternatively, if you're using both mine and Arthran's plugins together, it could be that they're conflicting with each other since they're designed around similar logic.

But! If Arthran's is working without issue and does what you need, I'd say just remove mine from your project and go with that.
I find that trying to help someone by going into the editor and trying different approaches helps me to learn about how things work.

Original thread: https://forums.rpgmakerweb.com/threads/make-merchant-to-detect-when-you-dont-buy-anything.162366/