# Setting up vendors

***

To have a inventory component be set to vendor, you will want to go into the component settings and set <mark style="color:purple;">**InventoryType**</mark> to <mark style="color:purple;">**Vendor**</mark>.

Right now, the system only considers items that are children of <mark style="color:yellow;">**IDA\_Currency.h**</mark> as viable currencies that can be exchanged for a vendor item. \
Prices are calculated inside <mark style="color:yellow;">**FL\_InventoryFramework.h**</mark> -> <mark style="color:red;">**GetItemPrice**</mark>, and the function that evaluates if a player can afford an item is <mark style="color:yellow;">**AC\_Inventory.h**</mark> -> <mark style="color:red;">**CanAffordItem**</mark>. Remember, you can override an items price inside their override settings.

The system by default has an array of currencies which players can use to buy items, but it does not by default provide a way of allowing the player to select which currency to use to buy or sell an item. It simply uses the first available currency it can find. It's up to you to implement that sort of logic.

Most games tend to have vendors keep track of how much money the vendor has, then when you sell an item to the vendor they spend their own currency and grant it to the player. There are three vendors in the demo, each showing a different way of handling the vendor logic.

If a logic error occurs, for example trying to give the player currency, but they do not have enough space in their inventory, you can call a delegate called <mark style="color:red;">**CurrencyAdditionFailed**</mark>. This is where you might want to implement some sort of mail system or queue system, as it feels pretty bad for players when they sell an item and they don't get their currency for it. The demo does not include any system for handling this problem.

There are many ways of handling vendor behaviour. Nearly every game handles it slightly differently, which is why the framework does not try to handle any of this logic for you at a C++ level.

Instead, there are three points in the system where you can inject your own custom logic and rules for handling vendor interactions.

1. The function <mark style="color:yellow;">**AC\_Inventory.h**</mark> -> <mark style="color:red;">**CanAffordItem**</mark> will call a interface function <mark style="color:yellow;">**I\_Inventory.h**</mark> -> <mark style="color:red;">**MeetsCurrencyCheck**</mark>, this simply asks the owner of the component what they value the item as.
2. You can make a child of <mark style="color:yellow;">**BP\_AC\_Inventory**</mark> and override the <mark style="color:red;">**CanAffordItem**</mark> function to implement your own custom logic.
3. The buyer and seller will receive a delegate on both the server and client either after or before the transaction, the notify is handled inside of <mark style="color:yellow;">**WBP\_Tile**</mark> -> <mark style="color:red;">**PerformDrop**</mark> -> MoveItem. The delegate is where you would perform any currency exchange, and since the vendor belongs to the server, it's allowed to call <mark style="color:red;">**TryAddNewItem**</mark> if you want to give either the vendor or player currency after the transaction.

## Using the crafting system as a vendor

A fascinating trick some people have done is using the crafting system as a "vendor". Technically, this is more performant and could potentially be easier to manage. But the vendor will not have a grid of any sorts and will require you to setup most of the logic.

This simply revolves around creating the illusion to the player that they are "buying" items, where in reality they are crafting them and using currency as the crafting ingredient.
