Merchant System

I am trying to create a merchant class in my game but I am having trouble creating a common event to monitor the party's money and convert money gain to exp gain.

I would prefer to do it using variables instead of using a script.

Does anyone have any suggestions?

Thank you!
show us a screenshot of your common event - that is usually simply by using an old value variable and a new value variable and checking in a parallel process with waits.
Thanks Andar for the reply. I got a round about way of it to work, but it's no where near the most refined. When I tried to have it just check the currency it would keep giving me levels so I implemented it checking for an item and convert it back into gold which works for the most part but even if I sell stuff for a lose in profit I still gain exp, and you don't get the gold converted until you leave the shop, which defeats selling and buying in a smooth motion. Also is there a way to change an item's sell price per shop?

Merchant Common Event.png

Merchant Shop Script.png

Merchant Items.png
Why not have a variable, "Last Gold", and have a Parallel Process check every 30 frames or so to see if the party's current gold is higher than that (Conditional Branch: Script: $game_party.gold > $game_variables[22])?

If it is higher, play a sound effect and/or show a message, then increase the Merchant's (or Party's) EXP by (current gold minus last gold - you can do this with variables), then set "Last Gold" to the current party gold.

You can even remove the need for a lag-inducing Parallel Process (and increase the precision of the check to Every Frame) by using Hime's Page Conditions script.

This will grant an accurate amount of EXP when you gain gold by any method (in battle, by selling items, from an event, etc.).  As far as requiring a "profit", that's something that you'd have to figure out from a game mechanics standpoint, since in most games you always take a loss when selling items.
Thank you Wavelength, how would you set the variables for last gold vs current gold? Mine keeps getting overwritten to the current amount.  Got the variables for that figured out, thank you so much! 

And any idea on how to set a different item sell price per shop?

Merchant gold.png
Thank you Wavelength, how would you set the variables for last gold vs current gold? Mine keeps getting overwritten to the current amount.  Got the variables for that figured out, thank you so much! 

And any idea on how to set a different item sell price per shop?
You're welcome!  Glad you like it.

The last two methods in Scene_Shop are:

#-------------------------------------------------------------------------- # * Get Purchase Price #-------------------------------------------------------------------------- def buying_price @buy_window.price(@item) end #-------------------------------------------------------------------------- # * Get Sale Price #-------------------------------------------------------------------------- def selling_price @item.price / 2 endYou could hack it and run a big case branch for different shops (tracked with a variable) and different items inside the selling_price method.  Or you could request/commission a script to set it up with different rules of your choosing to make the process more easily scalable.  This is something I'd only work on as a commission, but I wouldn't be too surprised if you found someone willing to do it for free in Requests.
Hmm, I have an idea in mind but scripting is something that I have only just begun to touch on, what kind of syntax would you use for condition branch? Or could you point me in the direction of a good ruby tutorial?

Okay. So I have a variable that spits a random number between 0 and 3 and I set up the 4 different shops. Then I set my shop script (theoretically) so each random number divides or multiplies the base selling price by an amount of my choosing. However it doesn't give me any gold when I sell items. In other words my script is broken. Good news is my game doesn't crash yet.

Merchant Sale Price.png

Merchant Random # Var.png
Yeah, your code is malformed.

Use something like:

Code:
def selling_priceif $game_variables[2] == 0  @item.price / 4elsif $game_variables[2] == 1  @item.price * 2elsif $game_variables[2] == 2  @item.price / 10else  @item.price / 2endend
I suggest you add a wait(60) to the shop common event.


By default, parallel processes run once per frame, that is sixty times per second - a common event like that would create some lag for no return, because you don't need the shop number rerolled sixty times per second.


The wait command makes the parallel processes skip the number of frames - with a wait(60) the shop number would be rerolled about once per second, that should be enough for your purposes...
Yeah, your code is malformed.

Use something like:

def selling_priceif $game_variables[2] == 0  @item.price / 4elsif $game_variables[2] == 1  @item.price * 2elsif $game_variables[2] == 2  @item.price / 10else  @item.price / 2endend
Ah, okay. I tried to search online but I just couldn't seem to find the correct syntax phrase to use. I think I might be able to use the same (or similar) concept for buying items, instead of my current one which is, in my event I have chained conditional branches verifying the current variable number with Four different shops set up. I might be able to do it with just One shop. Thank you Wavelength for all of your help!

Thank you Andar for the wait(60) suggestion, it helps a lot, I keep forgetting about it since it's on a different page than what I have been working with.

Other than crafting (which I think I can figure out on my own) are there any other "merchant" elements that I shouldn't forget for a good merchant game?

Edit: I got the shops to work for both buying and selling. However now the common event for checking gold and giving exp doesn't work.

Merchant Play.png

Merchant Gold CE.png

Merchant Shop Script.png
Other than crafting (which I think I can figure out on my own) are there any other "merchant" elements that I shouldn't forget for a good merchant game?
I think customers and markets with shifting tastes would be nice features, and ways to control the supply of goods that you have to offer are always welcome.  You could also look to Recettear which has a lot of cool merchant elements in it.

Edit: I got the shops to work for both buying and selling. However now the common event for checking gold and giving exp doesn't work.
That's probably because you're requiring Switch 1 to be active for the Parallel Process event to work, and I don't see anywhere that you set it On.
 

I think customers and markets with shifting tastes would be nice features, and ways to control the supply of goods that you have to offer are always welcome.  You could also look to Recettear which has a lot of cool merchant elements in it.

That's probably because you're requiring Switch 1 to be active for the Parallel Process event to work, and I don't see anywhere that you set it On.
I have it set to turn on Switch 1 with the start of the game, on like an intro screen.

Merchant Start Up.png

And as you can see in my previous post it can read the first part of the common even (Set player gold to Variable 1) but it doesn't seem to read the conditional branch of it.

Merchant Play.png

Merchant Gold CE.png
Oh, I see why now.  You are setting Variable 1 to the party's Gold.  Then you are comparing the party's Gold to Variable 1!  Well they are going to be equal every single time.

Here's what you want to do:

(top of event)

If Party's Gold > Variable "Last Gold"

Set Variable "Holder" equal to Money

Subtract the value of Variable "Last Gold" from Variable "Holder"

Gain EXP equal to Variable "Holder"

Set Variable "Last Gold" equal to Party's Gold

End

Wait 30 Frames

(bottom of event)

If you choose values for the payer's current and previous gold, you can see why this event setup will work and your screenshotted setup won't.

Original thread: https://forums.rpgmakerweb.com/threads/merchant-system.41791/