The vendor is an interactable actor the player can use to buy and sell items. Each vendor can have their own set of items, with customized restocking rules and both buy and sell multipliers. In this version vendor buyable items can be saved between sessions, there is also a new row driven vendor window which is replacing the previous grid one. This new interface makes it easier to have many items on the vendor.
How to add a Vendor
To add a vendor to your level drag out an instance of BP_Interactable_Vendor in the Blueprints/Interactables/ folder.
By default you should see a gray cube. You can replace this mesh with your own static mesh, or if you would like to show a humanoid hide the cube and add a skeletal mesh.
The demo content also contains two vendor examples for you. A simple humanoid instead of the cube which uses the Quinn character. This one is the BP_Interactable_VendorNPC blueprint in the /Demo/Interactables/Vendors/ folder. The other example is the Wandering Merchant, which will walk around a nav volume and pause for a moment if a player interacts with it. The wandering merchant blueprint BP_WanderingMerchant can be found in the same /Demo/Interactables/Vendors/ folder.
These blueprints are just the initiators, the logic for everything related to buying and selling items is part of the AC_Inventory_Vendor component attached to these actors. This component can be found in the Blueprints/Components/Systems/ folder.
Configuring the Vendor Component
The AC_Inventory_Vendor component found in the Blueprints/Components/Systems/ folder has the following customizable variables:
RememberBuyableItemChanges? - Set to true if you want the vendor to remember current item stocks between game sessions. If set to false the vendor will restart each time the game starts. It is important to use the unique identifier bpi on your actor when using this feature. You will need to respond to the method with a unique identifier for this vendor. This is used for the save game created to remember the vendor’s buyable items.
SellPriceMultiplier - The multiplier applied to the Item’s sell price as defined in the DT_Items data table for each item using the SellPrice variable.
BuyPriceMultiplier - The multiplier applied to the Item’s buy price as found in the BuyableItems array on this component.
BuyableItems - The definitions for the items that can be purchased from this vendor. See the next part “Buyable Items” for a breakdown of its variables.
Buyable Items
Configuring the Buyable Items of a vendor occurs on the AC_Inventory_Vendor component attached to the actor. Select this component then find the BuyableItems array. This array is where we store the information about the items we want the player to be able to buy from this vendor.
Here is a breakdown of each of the variables available for the BuyableItems:
BuyItemRowName - The row name of the item as it appears in the DT_Items data table. This is the item the vendor will offer to the player.
BuyItemOverrideData - Optionally override the dynamic data of your items.
BuyItemQuantity - The number of the item the player will receive when they buy this item.
BuyPriceCost - The numeric cost value for this buyable item. If the BuyPriceCostItem is not a currency this value will be truncated to act as an integer.
BuyPriceCostItem - The item row name of the item or currency used with the BuyPriceCost to define the price of the item to the player.
VendorCurrentQuantity - The starting quantity of the item available on the vendor. Set to -1 for unlimited.
VendorRestockPerQuantity - The amount of current quantity added to the item on each restocking event, if you are restocking this item.
VendorRestockMaxQuantity - The max quantity this vendor should stock up of an item before stopping.
VendorRestockSpeed - When set to a value greater than 0 the vendor will use this value as the number of seconds between each restock this buyable item. Leaving the value at 0 will keep the item from restocking.
I changed the Buyable Items but it is reverting to the previous ones when I press play, how do I fix that?
This is happening because you are using the save option, and on begin play it is reloading the saved data. If you make changes to the buyable items for your vendor, and you are using the RememberBuyableItemChanges? boolean, you will need to reset your vendor so it can properly integrate the new data from your change.
To do this you should call the ResetVendor function inside the vendor component. There is also a reset button in the demo content that can be used to reset all vendors currently loaded in the world.
Sellable Items
The price of sellable items is defined in the DT_Items data table for each item using the SellPrice variable. If this variable is set to 0 the item can not be sold at a vendor. If this value is greater than zero then that will be the base price the player can receive for selling the item at a vendor who also has a sell multiplier set to 1.
The SellPrice is the amount, and the item given to the player in that amount is defined by the SellCurrency. You can set this to an item row name, it does not need to be a currency.
For example if you want to give the player a piece of Raw Meat for each Burnt Meat you can do this. Or you can give them a currency like gold instead. The choice is yours, and it is defined per item.
Restocking Vendors
Restocking of buyable items is defined when you create the criteria for your buyable item (see above). Restocking will only occur if the VendorRestockSpeed (the number of seconds between each restocking) and VendorRestockPerQuantity (the number of additional items added per restocking which is added to the current inventory count).
Vendor Multipliers
The vendor component also lets you define a SellPriceMultiplier and BuyPriceMultiplier.
When the player sells an item, the SellPriceMultiplier of the vendor is multiplied against the base sellPrice defined for the item in the DT_Items data table, and this is the amount offered to the player.
When a player buys an item the BuyPriceMultiplier of the vendor is multiplied against the BuyPriceCost as defined in the BuyableItem definition for the item.
Customizing the Vendor Window
The vendor window and widgets can be found in the UIs/Vendor/ folder. The UI_Vendor is the parent window, and the UI_Vendor_Buy and UI_Vendor_Sell are the content of the Buy and Sell tabs. The UI_Vendor_Buy_item and UI_Vendor_Sell_Item are the rows shown in their related tab for each item.
The Window Title Text, Icon, Open and Close Sounds are set using the VendorWindowTitle, VendorWindowIcon, VendorWindowOpenSound and VendorWindowOpenSound variables found in the Vendor blueprint.
View the Sounds chapter to learn how to customize the other sounds.