In my RPG I've developed a nifty commodity trading system using events. I used this in conjunction with Shopoholic (thanks cmpsr2000,) though with some clever manipulation you can probably use it without that script.
The first thing I did was designate a switch that allows the player to trade. This, essentially, is the "membership" switch (kind of like buying a BJ's or COSCO membership card)
Next, I create an item for each commodity to be traded. Realistically you can use any item, armor, or weapon, but for the sake of control I made new ones.
The next step involves creating 4 common events: Commodity_Prices, Commodity_Flux, Supply_Flux, and Demand_Flux
Commodity_Prices sets the purchase price for commodities from the commodities trader, which is essentially an event-based shop. It is necessary to have the commodity trader be event-based because of certain variables that affect supply and demand price modifiers.
Commodity_Flux adjusts prices you can sell commodities for based on the number of commodities bought and the number of commodities currently in your inventory. What this boils down to is the more you sell of something, the less that thing is going to be worth. Supply_Flux will help restore the value of items over time so this value loss will never be permanent, but it prevents the player from milking a commodity in an unrealistic manner.
Supply_Flux, as mentioned above, restores over time the value of a commodity that was lost from the Commodity_Flux event.
Finally, Demand_Flux is an optional event that adjusts the demand of a specific commodity for all shops in a given map. It's optional because you can also individually adjust the demand variables at each shop by inserting a variable change before the shop call, but this acts as sort of a simplified catch-all method.
The Commodity_Prices event is set up like the following:
(Trigger: Parallel, Switch: (any switch that is always ON))
Control Variables: [0001:WheatValue] = 100
#This sets the base value of the commodity. In this case, the base value of wheat (excluding supply and demand factors) is 100 gold.#
Control Variables: [0010:Random] = Random No. (10...110)
#This variable is used to adjust the price of the commodity to a random value between 10% and 110% of the base value.#
Control Variables: [0001:WheatValue] *= Variable [0010:Random]
#This multiplies the base wheat value by the random value modifier.#
Control Variables: [0001:WheatValue] /= 100
#This reduces the size of the variable to a more relevant scale (since RPGMaker VX doesn't handle fractions well)#
#Repeat these actions for each commodity you intend to implement, followed by a wait period (I set my wait period to 15 minutes)#
Commodity_Flux - Here we will set up the price of the item in the database for selling to shops. This one's a real brain-twister, so bear with me.
(Trigger: NONE! This event is called by other events)
Control Variables: [0002:WheatBase] = 100
#This is set to the base value of the commodity (same as the first action in Commodity_Prices)#
Control Variables: [0100:Var2] = Variable [1000:WheatSupply]
#Var2 is a holding variable for doing arithmetic. WheatSupply is a variable that is added to when a commodity is purchased from the commodity trader (an event-based shop) - I'll explain later#
Control Variables: [0100:Var2] -= [Wheat Crate] in Inventory
#Basically, this subtracts the number of Wheat Crates you have in your inventory from the number of Wheat Crates you've purchased from the commodity trader.#
Control Variables: [0101:Var1] = Variable [0100:Var2]
Control Variables: [0101:Var1] *= 10
Control Variables: [0101:Var1] *= Variable [0002:WheatBase]
Control Variables: [0101:Var1] *= Variable [0003:WheatDmnd]
Control Variables: [0101:Var1] /= 10000
#A whole bunch of arithmetic. WheatDmnd is a variable to be determined in the Demand_Flux event or at a given shop.#
Conditional Branch: Variable [0101:Var1] >= Variable [0002:WheatBase]
--Control Variables: [0101:Var1] = Variable [0002:WheatBase]
#This ensures that the event doesn't increase the value of a commodity over the base price. This can happen when Supply_Flux restores value and the player hasn't sold very much of a commodity.#
Script: Price_Edit.item(xx, $game_variables)
#This last action modifies the database, adjusting the price of the specified item xx (where xx is the ID number of the item) to the given variable (Var1). If using armor or weapons as a commodity, replace "item" in Price_Edit.item with "armor" or "weapon" as necessary.#
Supply_Flux â€“ This event will restore over time the value lost from the Commodity_Flux event.
(Trigger: Parallel, Switch: (any switch that is always ON))
Control Variables: [1000:WheatSupply] *= 10
Control Variables: [1000:WheatSupply] /= Random No. (9...18)
#That's it! Adjusting the variable this way helps avoid problems with RPGMaker VX rounding down to 0.#
Demand_Flux â€“ In short, this event will adjust the demand levels for all commodities in a given map.
(Trigger: NONE. This is also a called event.)
Conditional Branch: Variable [9999:MapID] = = 1
--Control Variables: [0003:WheatDmnd] /= Random No. (50...150)
#The MapID variable can be set in a separate event. I won't go into the details on how to do that here unless people request it â€“ it should be simple enough. The random values are the percentage rate that demand will affect the price of the item. This does not determine TOTAL PRICE, but is added to the other factors (i.e. Supply)#
That's it for common events.
Next is setting up the event shops for purchasing commodities. I chose to give each commodity its own individual shop, but you could certainly consolidate them by usinng choice branches.
Here's how you set up the event shops:
New event, Priority: Same as Characters, Trigger: Action Button
Show Text: "Commodity: Wheat"
"Current Price: \V"
Conditional Branch: Switch [2222: CommodityMember] == ON
#Only use this if you are using a membership switch#
-- Show Text: "Purchase how many?"
-- Input Number: [0055: CountBuy], 2 digit(s)
--Conditional Branch: Variable [0055: CountBuy] > 0
#The player uses the number input to choose how much of a commodity he wants. If the number is greater than zero, the event continues#
---- Control Variables: [0090: TempPrice] = Variable [0055: CountBuy]
---- Control Variables: [0090: TempPrice] *= Variable [0001: WheatVal]
---- Control Variables: [0091: CurrentGold] = Gold
#Setting up variables to check how much the transaction will cost and whether the player will have enough gold for it.#
---- Conditional Branch: Variable [0090: TempPrice] <= Variable [0091: CurrentGold]
------ Change Gold: - Variable [0090: TempPrice]
------ Change Items: [Wheat Crate], + Variable [0055: CountBuy]
#Completes the transaction by subtracting the gold and adding the wheat crates#
------ Show Text: "Wheat Crate x\V purchased!"
------ Control Variables: [1000: WheatSupply] += Variable [0055: CountBuy]
#Adds to the supply variable for use with the common events set up previously#
------ Control Variables: [0055 CountBuy] = 0
------ Show Text: "You don't have enough money!"
---- Branch End
---- Show Text: "Transaction Cancelled!"
-- Branch End
-- Show Text: "You must be a member to purchase commodities!"
And that's it! Simple, right? Now go ahead and try it and let me know if it works or if you run into trouble!