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

Status
Not open for further replies.

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
100
Reaction score
23
First Language
English
Primarily Uses
RMMV
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?
 

HumanNinjaToo

The Cheerful Pessimist
Veteran
Joined
Apr 18, 2013
Messages
1,226
Reaction score
603
First Language
English
Primarily Uses
RMMV
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?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
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?
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,685
First Language
English
Primarily Uses
RMMZ
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.

 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
533
Reaction score
235
First Language
English
Primarily Uses
RMMV
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.
 

Restart

Veteran
Veteran
Joined
Mar 15, 2019
Messages
523
Reaction score
415
First Language
English
Primarily Uses
RMMV
Just event a shopkeeper who only sells healing potions, then you can easily count how many were purchased with a single variable
 

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
100
Reaction score
23
First Language
English
Primarily Uses
RMMV
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.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,685
First Language
English
Primarily Uses
RMMZ
Would you like the system to keep track of ALL items, including weapons and armors, or only consumables?
 

Damascus7

Veteran
Veteran
Joined
Jul 21, 2019
Messages
100
Reaction score
23
First Language
English
Primarily Uses
RMMV
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!
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,115
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
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. :kaophew:

No pressure though, the eventing approach is perfectly OK~ :kaothx:
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,685
First Language
English
Primarily Uses
RMMZ
@Damascus7 If your thread has been answered, please report it so a moderator can close it. Thank you.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,685
First Language
English
Primarily Uses
RMMZ
@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!
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,372
Reaction score
8,536
First Language
English
Primarily Uses
RMMV

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.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,033
Messages
1,018,441
Members
137,820
Latest member
georg09byron
Top