Increasing a variable when an item is bought... but not decreasing when it's used/sold

Hi there! I'm looking for a way to count how many of an item a player purchases over time, but not have that count get reduced if they use or sell that item.

A quest requires the player to buy 3 healing potions. The current way I am counting it is by having a script that checks how many of the item a player has after they exit the shop that sells them and save that number to a variable. But that's not really ideal when if some of those items get used before they purchase more. For example, if the player buys 1 potion and leaves, the script will count 1. But if they use that potion, and then come back and buy 2 more, the variable will only have a count of 2, when I'd prefer it to have a count of 3.

Any ideas how I could script this?
This seems overly complicated to me. Why not have a conditional branch in the quest event that requires the player to have 3 healing potions before they can progress the quest?
You want the player to have to BUY 3 healing potions, but they can do anything with them, including selling them or using them? They don't have to give them to the quest-giver?
It seems like the best way to do this would be through a small plugin. Do you want the variable to go up only when the player buys something at a shop, or would you also like the variable to go up when the player gains the item by another mean (like a chest?).

Moved to JS Plugin Requests.

Assuming they can't sell potions at the shop, all you need to do is check how many they have before the shop and how many they have after the shop, and add the difference to your counter variable. This probably requires three variables - one to store how many they had before shopping, one to store how many they had after shopping, and one as the counter. Basically like this:

Code:
◆Control Variables:#0001 Before = The number of Potion
◆Shop Processing:Potion
◆Control Variables:#0002 After = The number of Potion
◆Control Variables:#0003 Counter += After
◆Control Variables:#0003 Counter -= Before

That'll work if you only have one shop that sells potions (or a very small number of shops)... if you have many, though, you'll probably want a plugin like MushroomCake said.
Just event a shopkeeper who only sells healing potions, then you can easily count how many were purchased with a single variable
You want the player to have to BUY 3 healing potions, but they can do anything with them, including selling them or using them? They don't have to give them to the quest-giver?

Correct. This quest is given as "It's dangerous out there, so you should get some healing potions to protect yourself." So they are more for the player than the quest giver.

It seems like the best way to do this would be through a small plugin. Do you want the variable to go up only when the player buys something at a shop, or would you also like the variable to go up when the player gains the item by another mean (like a chest?).

Currently the only way to get the potions is through one of two shops, you can't get them from drops or chests.

Assuming they can't sell potions at the shop, all you need to do is check how many they have before the shop and how many they have after the shop, and add the difference to your counter variable. This probably requires three variables - one to store how many they had before shopping, one to store how many they had after shopping, and one as the counter.

I have two shops that sell potions, so this could possibly work. However, you can sell potions at these shops. There wouldn't be much point in doing so, as you would essentially just be throwing away money by buying a potion for full price and then selling for half price. But it is still something the player can do.
Would you like the system to keep track of ALL items, including weapons and armors, or only consumables?
Really I just need it for this single item for a quest.

So far the script Solar_Flare put up above seems to be working well for me. I don't think I'll have to worry too much about players selling potions; if they're at the stage where they have so many potions that they want to sell some, they'll have already completed the quest by that point.

So for now, unless there are any other hiccups, I'm gonna roll with that script. Thanks so much!
Since it seems relevant, here's a link to a plugin of mine: view/download Cae_BuySellVar (Google Drive).

It lets you stick a notetag like <buy var: 12> in an item's notebox; the game should then automatically add 1 to the value of game variable 12 every time the player buys one of those items. 😮‍💨

No pressure though, the eventing approach is perfectly OK~ 🙏
@Damascus7 If your thread has been answered, please report it so a moderator can close it. Thank you.
@caethyril I like that! I may end up using that to save on time and script space. Thank you!

@MushroomCake28 I will do this, didn't see in the rules before.
@MushroomCake28 Do I just hit the report button on the top post, or is there a different one I use for closing threads? Haven't actually been asked to do this before and did not see it in forum rules.
Yup, it's the Report button right besides the edit button. Just report any of your post in this thread, a small box will appear asking you the reason for reporting the post, and you can just write "Thread solve, please close" or something similar, then click send. Et voila!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/increasing-a-variable-when-an-item-is-bought-but-not-decreasing-when-its-used-sold.122976/