Increase variable when buying from shop

TriceratopsX

Veteran
Veteran
Joined
May 2, 2016
Messages
264
Reaction score
404
First Language
English
Primarily Uses
RMMV
Alright, so I'm trying to keep track of how much the player has bought from a shop in my game, y'know for stuff like "every 100 purchases you get a free potion!" but I'm not quite sure how to make it keep track of what the player's bought. (Aside from possibly brute forcing it by making a conditional branch check to see if the player has any more of items x, y, or z, after the shop menu in the event and if yes than increasing the variable) But I didn't know if there was a better way to accomplish what I'm planning.

As always any help is appreciated! :D
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,039
Reaction score
10,259
First Language
Czech
Primarily Uses
RMMV
It looks like an easy plugin to make. I might try it if you want.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,314
Reaction score
315
First Language
German
Primarily Uses
RMMV
With help of the Forums i could get this Scriptline which checks the current amount of all items (not the equiped ones, but thats not needed here)
You check how many Items before shop Visit Eventcommand, and you check again after the shop, than you compare the amount and safe it to a 3rd variable. than check if 3rd variable is 100 for example, than add a potion as gift.

The Scriptline checks the amount of items from id 1 to 100, if you have less than 100item ids this will result in game crash, so make sure to put the right number there.
Code:
$gameVariables.setValue(1, 0 )
for (var a = 1; a <= 100; a++) {  $gameVariables.setValue(1, $gameVariables.value(1) +
$gameParty.numItems($dataItems[a], false) ) }
Eventcommand Shop
Code:
$gameVariables.setValue(2, 0 )
for (var a = 1; a <= 100; a++) {  $gameVariables.setValue(2, $gameVariables.value(2) +
$gameParty.numItems($dataItems[a], false) ) }
Now Var2 sub Var1 = The difference in Items.
Var3 add Var2 (the amount of items bought)
if var3 equal or more 100? if yes add poition and set var3 to 0.
This should work in theory.

The Code Works, but the moment i finished it i realised a big Problem. What if the player not only Buys items but also Sells some, than
the number comparsion would not work anymore.
So you would maybe need a Plugin which changes how the shop works. Not sure.
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,397
Reaction score
878
First Language
EN
Primarily Uses
RMMV
Here's a typical eventing solution, though as Bex notes, if you can buy & sell at the shop then it'll see "2 bought and 1 sold" as +1. Depends whether you need that sort of distinction.
Code:
◆Comment:Number of potions now
◆Control Variables:#0001 potion count = The number of Potion
◆Comment:Enter shop
◆Shop Processing:Potion
◆Comment:Number of potions now - original number of potions
◆Control Variables:#0001 potion count *= -1
◆Control Variables:#0001 potion count += The number of Potion
◆If:potion count ≥ 5
  ◆Comment:Bought at least 5 potions!
  ◆Text:Actor1(0), Window, Bottom
  :    :Wow you really like potions, don't you?
  :    :Here's another one for being such a good
  :    :customer!
  ◆Change Items:Potion + 1
  ◆
:End
I have a notetag-based plugin for it here, but to give others a chance to contribute I'll wait 'til tomorrow to upload~ :kaothx:
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,314
Reaction score
315
First Language
German
Primarily Uses
RMMV
@caethyril please, no need to tease us with waiting :kaocry:. Iam sure your Plugin solves mostly all if not everything.
 

TriceratopsX

Veteran
Veteran
Joined
May 2, 2016
Messages
264
Reaction score
404
First Language
English
Primarily Uses
RMMV
@Bex & @caethyril Well the shop was going to be purchase only anyway (It's sorta connected to the plot? The shopkeeper's... Unique) so at the very least we don't have to work around the player selling anything back to him
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,397
Reaction score
878
First Language
EN
Primarily Uses
RMMV
Okies here's my take on it: view/download file (Google Drive)
It only adjusts variable values on buy/sell, so you'll still need some basic pre-/post-shop setup eventing for the "here's a bonus!" stuff.

@Bex Just trying to encourage others to step in if they want; like Poryg said, this is a fairly simple plugin request. I think I phrased it badly, though. :kaoslp:
 
  • Like
Reactions: Bex

TriceratopsX

Veteran
Veteran
Joined
May 2, 2016
Messages
264
Reaction score
404
First Language
English
Primarily Uses
RMMV
@caethyril Thanks a bunch! I do have a question though, do you know whether or not this and Yanfly's "shop menu plugin" are compatible with each other? See I'm using that plugin because Yanfly's "more currency plugin" doesn't work without it, and I'm using that for the same shop, I would use this for and depending on how nice the plugins play with each other I might go ahead with brute force eventing it instead.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,397
Reaction score
878
First Language
EN
Primarily Uses
RMMV
It looks like it should work if you load mine after Yanfly's Shop Menu Core; Yanfly still uses doBuy/doSell but overrides the default method. :)
 

TriceratopsX

Veteran
Veteran
Joined
May 2, 2016
Messages
264
Reaction score
404
First Language
English
Primarily Uses
RMMV
Ok thanks, I figured it probably wouldn't be an issue but since I'm not javascript savvy (yet) I like to make sure beforehand
 

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

Latest Threads

Latest Profile Posts

In today's seminar:
Presenter: In the past, there was a saying, "One who has tuberculosis is doomed for life." But now-
Everyone: *starts coughing in unision*
Gosh... Today seems too much like a good day to do nothing....

I need to keep myself focused...! :kaoback:
javascript'ing essentials.

So, what can I do solve this problem, guys? The plugin is MOG_Weather and I have several Yanfly plugins too.

Forum statistics

Threads
93,697
Messages
914,710
Members
123,295
Latest member
AndrewBromas
Top