MZ Is it possible to check if something was purchased from a shop?

Question ^
I should add: "something" as in, the opposite of "nothing was bought".
You could store the party's gold to a variable before you call Shop Processing, then compare that amount afterward.
If you want to check a specific item, you could use Control Variables -> Game Data -> Item to get the count before, then check it after to see if it has increased, e.g.

◆Control Variables:#0001 check = The number of Potion ◆Shop Processing:Potion : :Super Potion ◆Control Variables:#0001 check -= The number of Potion ◆Control Variables:#0001 check *= -1 ◆If:check > 0 ◆Text:None, None, Window, Bottom : :You bought \v[1] Potion(s)! ◆ :End
(I multiply by -1 here because it's "before - after", which is negative if "after" is more than "before".)

If it's a Purchase-Only shop then you could use a similar approach, but count the total items in the party inventory instead. You can do that with Control Variables -> Script:

$gameParty.allItems().reduce((a, c) => a + $gameParty.numItems(c), 0)

Otherwise it's a bit tricky: you'd either need to remember all items in the inventory before, then check for differences after, or use a plugin to toggle a switch or something when the player buys an item. In that case you might be interested in my plugin, Cae_AutoSwitchVars:
It has a variety of useful triggers, including Buy/Sell parameters and item-specific notetags. 👋
You could store the party's gold to a variable before you call Shop Processing, then compare that amount afterward.

There is always a tiny chance you could buy some and sell some and end up with the same amount of gold.

If you want to check a specific item

Nope, I want to check if no purchase has been made.
There is always a tiny chance you could buy some and sell some and end up with the same amount of gold.
Seems statistically unlikely, but then there are the code options caethyril offered.

Nope, I want to check if no purchase has been made.
She did recommend the AutoSwitchVars plugin specifically for that. 😉
My game doesn't have shops, so I'm not entirely sure how they work, but from a bit of poking around in the code this should be solvable with a fairly simple plugin.

JavaScript:
var _Scene_Shop_doBuy = Scene_Shop.prototype.doBuy;
Scene_Shop.prototype.doBuy = function(number){
    _Scene_Shop_doBuy.call(this, number);
    $gameSwitches.setValue(42, true);
}
This will set the switch 42 to true whenever the player buys anything. Just set that switch to false before starting the shop, and check after it's closed.

Similarly, you can do:
JavaScript:
var _Scene_Shop_doSell = Scene_Shop.prototype.doSell;
Scene_Shop.prototype.doSell = function(number){
    _Scene_Shop_doSell.call(this, number);
    $gameSwitches.setValue(42, true);
}
To set a switch whenever the player sells anything.
The VisuStella core plugins have an option to turn a switch on when you make a shop purchase, if memory serves.
The VisuStella core plugins have an option to turn a switch on when you make a shop purchase, if memory serves.
I can't seem to find it. I'd prefer to stick to VS plugins only as otherwise things can't get messy real fast IMO.

@Mac15001900 I'll try it, thank you.

1669277693176.png
@Mac15001900 - functionally OK, but I'd recommend a couple of additions:
  • Add a header with (at least) a @target MZ directive to suppress a Plugin Manager warning (which can otherwise hide other, useful warnings, e.g. about load order).

  • Scope the aliases locally to avoid naming conflicts with other plugins.
E.g.
JavaScript:
/*:
 * @target MZ
 */
;(function() {
  var _Scene_Shop_doBuy = Scene_Shop.prototype.doBuy;
  Scene_Shop.prototype.doBuy = function(number){
    _Scene_Shop_doBuy.call(this, number);
    $gameSwitches.setValue(42, true);
  }
})();

(For the record, cross-compatibility is one of my primary goals when I write plugins, and I've never had a bug report for AutoSwitchVars...probably because it's the simplest one of my MZ plugins.)
I can't seem to find it. I'd prefer to stick to VS plugins only as otherwise things can't get messy real fast IMO.

@Mac15001900 I'll try it, thank you.

View attachment 245794
Items and Equips Core.

1669348642573.png
Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-check-if-something-was-purchased-from-a-shop.152853/