Trade
Use core.trade to request regular or cash trades, manage a regular trade offer, and control which incoming invitations may be accepted automatically.
A true result from a networked trade action means the request was submitted from a valid client state. Confirm the result after the trade updates. Opening the native prompt and changing the allowlist complete locally.
Trade targets may be a character name or positive character ID. Targets passed to request() or request_cash() must be present in the current field.
Functions
core.trade.is_open() -> boolean
Returns whether a regular trade is open.
core.trade.is_cash_open() -> boolean
Returns whether a cash trade is open.
core.trade.is_trading() -> boolean
Returns whether either trade type is open.
core.trade.is_accept_pending() -> boolean
Returns whether an earlier regular-trade acceptance is still pending.
core.trade.get_state() -> number | nil
Returns the current regular-trade stage, or nil when no regular trade is open. Treat this value as observational.
core.trade.request(target: string | number) -> boolean, string?
Requests a regular trade with the target.
core.trade.request_cash(target: string | number) -> boolean, string?
Requests a cash trade with the target. Returns an error when its required entry item is unavailable.
core.trade.put_meso(amount: number) -> boolean, string?
Places Mesos into the open regular trade. The in-game Meso prompt does not need to be open, and this function never opens it.
amount must be a positive integer, no greater than the character's current Meso balance, and no greater than the game's cap of 9999999999999. Returns false, error_message when no regular trade is open, the amount exceeds the balance, or the trade is already confirming.
core.trade.put_item(item_or_tab_id: table | number, count_or_position?: number, count?: number) -> boolean, string?
Places an inventory item into the open regular trade. It accepts two call forms, and which argument holds count depends on the form you use.
| Call form | Parameters |
|---|---|
put_item(item, count?) | item — an item record from a core.inventory getter such as get_all_items(). It must contain tab_id and position. count is the second argument. |
put_item(tab_id, position, count?) | tab_id — inventory category: 1 Equip, 2 Use, 3 Setup, 4 Etc, 5 Cash. position — the 1-based slot within that tab. count is the third argument. |
count defaults to the whole held stack when omitted. It must not exceed the held quantity, and it is capped at 65535.
Returns false, error_message when no regular trade is open, the item is not found, the trade item list is full, or the trade is already confirming.
core.trade.put_item_by_id(item_id: number, count?: number) -> boolean, string?
Finds a matching inventory item and places it into the open regular trade.
core.trade.accept() -> boolean, string?
Accepts the open regular trade when another acceptance is not pending.
core.trade.cancel() -> boolean, string?
Cancels the open regular or cash trade.
Allowlist
Allowlisted invitations are accepted automatically. Names are matched case-insensitively; names and character IDs are stored separately. The allowlist lasts for the current Violet session.
core.trade.allowlist.add(target: string | number) -> boolean, string?
Adds a character name or ID.
core.trade.allowlist.remove(target: string | number) -> boolean, string?
Removes a character name or ID.
core.trade.allowlist.contains(target: string | number) -> boolean, string?
Returns whether the exact name or ID is allowlisted.
core.trade.allowlist.get_all() -> table
Returns { names = string[], ids = number[] }.
core.trade.allowlist.clear() -> boolean
Removes every allowlisted name and ID.
core.trade.allowlist.add("ExampleCharacter")
local ok, err = core.trade.request("TradePartner")
if not ok then
core.log(err)
end