Skip to content
smartargs
VantageDocumentation

Vendors reference

The vendor component, the vendor asset and its stock lines, and the live stock a shop window reads. For how to use it, see Vendors.

VtVendor

Component. Add it with Add Component → Vantage → Vendors → VtVendor.

A shop on an NPC. Holds this instance’s stock, prices items from their value and the vendor definition’s multipliers, sells to and buys from a customer, and restocks on a timer. Opt in through VtUnitDefinition.useVendor; VtUnit attaches it.

Inspector fields

Field Type Default Range Description
Vendor (vendor) VtVendorDefinition None What this NPC sells and how it prices. Required.
Interact Radius (interactRadius) float 3 ≥ 0 Distance within which the player can trade. The walk-to-interact flow stops here.

Scripting API

Member Description
IReadOnlyList<VtVendorStockState> Stock { get; } Live stock, one entry per line of the definition, in authored order.
event Action<VtUnit> OnVendorOpened Fires when a player interacts with the vendor. Open your shop window here.
event Action<VtUnit, VtItemDefinition, int, int> OnBought Fires after a purchase: (customer, item, count, total paid).
event Action<VtUnit, VtItemDefinition, int, int> OnSold Fires after the vendor bought from a player: (customer, item, count, total received).
event Action OnStockChanged Fires whenever a stock count or restock timer changed, including restocks and replication.
void Initialize() Cache the sibling unit and seed stock from the definition. Safe to call more than once; call it right after adding the component from code.
int GetStock(VtItemDefinition item) Units of item left, -1 for unlimited, 0 when sold out or not carried.
bool Sells(VtItemDefinition item) True when the vendor carries item at all.
VtCurrencyDefinition GetCurrency(VtItemDefinition item) Currency a trade in item uses: the vendor’s, else the item’s. Null means no trade.
int GetBuyPrice(VtItemDefinition item) Price per unit the customer pays, or 0 when the item is not carried.
int GetSellPrice(VtItemDefinition item) Price per unit the vendor pays for item.
bool IsWithinReach(VtUnit customer) True when customer stands within interactRadius plus the interact tolerance from the tuning asset.
bool CanBuy(VtUnit customer, VtItemDefinition item, int count, out VtVendorFailureReason reason) Whether customer could buy count of item right now. Pure query; the first failing reason comes back.
bool CanSell(VtUnit customer, VtItemDefinition item, int count, out VtVendorFailureReason reason) Whether the vendor would buy count of item from customer right now. Pure query.
bool TryBuy(VtUnit customer, VtItemDefinition item, int count, out VtVendorFailureReason reason) Sell count of item to customer: charges the wallet, adds to the inventory, reduces stock. On a predicting client the request is forwarded and this returns false with VtVendorFailureReason.AuthorityNotLocal.
bool TrySell(VtUnit customer, VtItemDefinition item, int count, out VtVendorFailureReason reason) Buy count of item from customer: removes from the inventory and credits the wallet. Forwards on a predicting client.
void Tick(float deltaTime) Advance restock timers. Runs on the authority only.
void ApplyStockFromNet(IReadOnlyList<VtVendorStockState> snapshot) Replace the live stock with snapshot, matched by item. Used by loading and replication; not authority-gated.
void CopyStockTo(List<VtVendorStockState> buffer) Copy the live stock into buffer for saving or sending.

VtVendorDefinition

Asset. Create it with Create → Vantage → Vendors → Vendor Definition.

Authored shop: what an NPC sells, how it prices, and whether it buys. Assign it to a unit definition with VtUnitDefinition.useVendor checked; VtUnit attaches a VtVendor that keeps the per-instance stock. Definitions are shared, so two merchants with the same asset have separate stock counts.

Inspector fields

Field Type Default Range Description
Id (id) string Empty Stable string identifier for save files and tooling. Convention: ‘vendor..’.
Display Name (displayName) string Empty Name shown on the shop window.
Currency (currency) VtCurrencyDefinition None Currency this vendor trades in. Empty = each item’s own value currency.
Buy Price Multiplier (buyPriceMultiplier) float 1 ≥ 0 What the player pays, as a multiple of the item’s value. 1 = list price.
Sell Price Multiplier (sellPriceMultiplier) float 0.25 ≥ 0 What the vendor pays for the player’s items, as a multiple of the item’s value. 0.25 = a quarter.
Buys Items (buysItems) bool On Whether the vendor buys items from the player at all.
Stock (stock) VtVendorStockEntry[] Empty What is for sale. One line per item.

VtVendorStockEntry

Serializable class.

One line of a vendor’s stock: what it sells, at what price, how many, and how fast it restocks. Authored inline on a VtVendorDefinition.

Inspector fields

Field Type Default Range Description
Item (item) VtItemDefinition None Item for sale. Required.
Price Override (priceOverride) int 0 ≥ 0 Price per unit at this vendor. 0 = the item’s value times the vendor’s buy multiplier.
Stock (stock) int -1 ≥ -1 How many the vendor holds. -1 = unlimited.
Restock Seconds (restockSeconds) float 0 ≥ 0 Seconds after the stock drops below full until it refills to Stock. 0 = never restocks. Counts in simulation time.

VtVendorStockState

Struct.

Live stock of one item at one vendor instance. Read through VtVendor.Stock; replicated and saved through VtVendor.ApplyStockFromNet.

Scripting API

Member Description
VtItemDefinition Item The item this line sells.
int Remaining Units left. -1 = unlimited.
float RestockRemaining Seconds until the line refills, or 0 when full or never restocking.

Enums

VtVendorFailureReason

Why a VtVendor.CanBuy, VtVendor.CanSell, VtVendor.TryBuy or VtVendor.TrySell call refused.

Value Description
None The trade can go ahead.
VendorNull The vendor component has no definition.
ItemNull No item, or a count of zero.
NotSold The vendor does not carry this item.
OutOfStock The vendor holds fewer than asked.
NoPrice The item has no value currency and no price override.
NoWallet The customer has no wallet.
CannotAfford The customer cannot pay.
NoInventory The customer has no inventory.
InventoryFull The purchase would not fit in the customer’s inventory.
NotSellable The item is not sellable, or the customer holds fewer than offered.
VendorDoesNotBuy This vendor does not buy from players.
TooFar The customer is farther from the vendor than its interact radius allows.
AuthorityNotLocal Not the authority; the request was forwarded.