CommerceLua table
Shops, cash-shop products, market listings, auction prices, and memberships.
These experimental advanced calls are members of game. Their names include the leading underscore. An installed runtime may not provide every call; check type(game._cash_shop_products) == "function" before using it and handle unavailable results as nil, error.
A request returning true does not confirm a purchase, sale, listing, cancellation, or delivery. Inspect the game's shop, inventory, currency, and sales list afterward. Do not automatically repeat a transaction because its result is not visible on the same tick. These calls can spend currency or remove inventory items.
| Task | Calls | Related reference |
|---|---|---|
| Buy or sell at a shop | Shop requests | Inventory |
| Read cash-shop products or request a purchase | Cash shop | Memberships |
| Read a quote or clear a stored quote | Auction prices | Market listings |
| List, remove, refresh, or settle sales | Market listings | Request timing |
Shops
game._shop_buy_request(product_id, quantity)
Parameters: Exactly two Lua integers: the product ID for the current shop and the quantity to purchase. The function does not apply a positive-range check to these arguments. Supply the game's current product ID and a positive quantity within the signed 32-bit range; do not rely on larger values or negative quantities.
Returns: true when the client accepts the purchase request, false when it rejects the request, or nil, error when the character session, shop data, or purchase action is unavailable.
The product ID identifies a shop product, not an inventory item UID. This call uses the current shop context; it does not open a shop or select an NPC. A successful request does not guarantee stock, affordability, delivery, or an inventory update.
game._shop_sell_request(item_uid, quantity)
Parameters: Exactly two Lua integers: a nonzero signed 64-bit inventory item UID and a positive quantity. Use the uid from a fresh inventory snapshot, not the item's type ID.
Returns: true when the client accepts the sale request; false when it rejects the request or no NPC shop is active; or nil, error for invalid arguments, unavailable character or shop data, or an unavailable sale action.
The function does not confirm that the requested quantity belongs to the item or that the item is eligible for sale. Validate your selection against the current inventory and shop first, then check inventory and currency after the request.
Cash shop
game._cash_shop_products()
Parameters: None.
Returns: An ordered array of product records, an empty array when the available list is empty, or nil, error when the character, cash shop, or product list is unavailable or cannot be read consistently. A successful array contains at most 500 records.
| Field | Type | Meaning |
|---|---|---|
id | Integer | Positive cash-shop product ID |
purchased_count | Integer | Reported purchase count for this product |
obj | Integer | Reserved compatibility token; it can be 0 and should be ignored |
Use id, not obj, with the purchase request. These rows do not contain prices, currency types, stock, purchase limits, names, or a promise that a product is currently purchasable. purchased_count is not a remaining-purchase count.
function on_start()
if type(game._cash_shop_products) ~= "function" then
log.warn("Cash-shop product API unavailable")
return
end
local products, err = game._cash_shop_products()
if not products then
log.warn(err)
return
end
for _, product in ipairs(products) do
log.info(string.format("Product %d: purchased %d",
product.id, product.purchased_count))
end
endThis example only reads products; it does not buy anything.
game._cash_shop_purchase_request(goods_id, quantity)
Parameters: Exactly two Lua integers: a cash-shop product ID and quantity. Only signed 32-bit argument values are used by the purchase action. Use positive values from 1 to 2147483647; the call does not reject every out-of-range value before it reaches that action.
Returns: true when the client accepts the purchase request, false when it rejects the request, or nil, error when the character, cash shop, or purchase action is unavailable.
Use a current id from game._cash_shop_products(). The product list does not supply the cost or validate your purchase quantity. Check the actual offer and currency in the game before sending a request. true does not confirm that currency was spent or that goods were granted.
Auction prices
Market trade_type arguments are integers from 0 to 3. These are category selectors, not server IDs. Category labels are not supplied by this API; use the category appropriate to the game's current market context.
game._item_auction_prices(trade_type)
Parameters: One integer market category from 0 to 3.
Returns: A price record, or nil, error for an invalid category or when a corresponding quote is unavailable.
| Field | Type | Meaning |
|---|---|---|
uid | Integer | Positive identity associated with the quoted item; check that it matches the item you intended |
current_lowest_price | Integer | Stored average unit-price value under a legacy field name |
average_price | Integer | Stored latest average unit-price value |
The price fields are integer projections; ordinary fractional values lose their fractional part. Despite its name, current_lowest_price is not a guarantee of the lowest available listing or an executable purchase price.
This reads a stored response for the category. It does not search for an item or request a quote, and it returns no item type ID, currency metadata, timestamp, or freshness flag. A response can reflect an earlier item selection. Do not price a new sale from this record unless you have independently confirmed the quote belongs to that item and is current.
game._invalidate_item_auction_prices(trade_type)
Parameters: One integer market category from 0 to 3.
Returns: true when the category's stored quote is cleared, including when there was nothing to clear; false when the category cannot currently be resolved; or nil, error for invalid arguments.
This changes only the stored snapshot. It does not request a replacement quote or cancel a game transaction. A later price read remains unavailable until another corresponding response arrives. Clearing a category is shared with other scripts reading that category.
Market listings
game._market_listing_rows(trade_type)
Parameters: One integer market category from 0 to 3.
Returns: An array of up to 20 sales-list records, an empty array when a received list is empty, or nil, error for an invalid category, unavailable list, unavailable clock, or invalid listing age.
| Field | Type | Meaning |
|---|---|---|
item_id | Integer | Positive item type ID |
sale_id | Integer | Positive listing identity; pass it unchanged when removing that listing |
listed_age | Integer | Whole elapsed seconds since the listing's reported start time |
quantity | Integer | Positive listed quantity |
price | Integer | Reported nonnegative price; no currency or per-unit label is supplied |
listed_age is not time remaining or a Unix timestamp. The list preserves the order of the stored response and is not a general marketplace search API.
The call does not refresh the list. It has no response timestamp or generation field, so a successful read alone does not establish that a preceding sale or removal has finished. Do not interpret an unavailable read as an empty sales list.
function on_start()
if type(game._market_listing_rows) ~= "function" then
log.warn("Market-list API unavailable")
return
end
local listings, err = game._market_listing_rows(0)
if not listings then
log.warn(err)
return
end
for _, listing in ipairs(listings) do
log.info(string.format("Item %d: quantity %d, price %d, age %ds",
listing.item_id, listing.quantity,
listing.price, listing.listed_age))
end
endgame._invalidate_market_listings(trade_type)
Parameters: One integer market category from 0 to 3.
Returns: true when the stored list is cleared, including when no list was stored; false when the category cannot currently be resolved; or nil, error for invalid arguments.
This does not delete any listings in the game or fetch a replacement list. After clearing, list reads are unavailable until a corresponding response arrives. Other scripts reading the same category see the cleared snapshot too.
game._market_sales_refresh_request(trade_type)
Parameters: One integer market category from 0 to 3.
Returns: true when the client's refresh action was invoked, or nil, error for invalid arguments or unavailable character, market, or refresh action.
The game can decline to send a refresh because of its current state or timing rules. true therefore does not prove a request was sent or a new list received. On a later tick, read game._market_listing_rows() and inspect the game's sales list. Avoid a refresh on every tick.
game._trade_sell_request(trade_type, item_uid, quantity, total_price)
Parameters: Exactly four Lua integers. trade_type is from 0 to 3; item_uid, quantity, and total_price must be positive signed 64-bit integers.
item_uid identifies a current inventory item. total_price is the price for the requested quantity as a whole, not a unit-price argument. Use a fresh inventory snapshot and the correct market category.
Returns: true when the client accepts one listing request; false when it rejects the request or the category has no available market; or nil, error for invalid arguments or unavailable character, market, or listing action.
The call does not verify item ownership, eligibility, quantity, affordability of fees, or the final listing state. Check the item and displayed fees before submission, then verify the inventory and sales list afterward. Do not submit another listing merely because the previous one has not appeared yet.
game._market_listing_removal_request(trade_type, sale_id, item_id, item_count)
Parameters: Exactly four Lua integers: category from 0 to 3, the listing's sale_id, positive item type ID from 1 to 2147483647, and a positive signed 64-bit count.
Use sale_id, item_id, and quantity from the same current listing record; quantity supplies item_count. Keep the listing identity unchanged. Do not substitute an inventory UID, reconstruct a listing ID, or combine values from different rows.
Returns: true when the client accepts the removal request; false when it rejects the request or the category has no available market; or nil, error for invalid arguments or unavailable character, market, or removal action.
A returned true does not prove cancellation or item return. Verify the listing and inventory afterward.
game._market_trade_settlement_request(trade_type)
Parameters: One integer market category from 0 to 3.
Returns: true when the client's settlement action was invoked, or nil, error for invalid arguments or an unavailable character, market, or settlement action.
This requests settlement of completed market trades. It does not return delivery details or the amount received, and true does not confirm delivery. Check the game's settlement view, currency, and inventory afterward.
game._select_market_listing_item_request(trade_type, item_token)
Parameters: Exactly two Lua integers: category from 0 to 3 and a positive current market item-selection token.
Returns: true when the client's item-selection action was invoked, or nil, error for invalid arguments, an unavailable item or market, an unsupported action, or a token that is no longer current.
This is a restricted item-selection interface, not a sale request. The published inventory snapshot's object field is a UID action token and is not the selection token this function expects. That snapshot currently provides no compatible selection token. Do not substitute object, uid, an item type ID, or a calculated value. For a UID-based listing request, use game._trade_sell_request().
Selection tokens, when supplied by a compatible runtime integration, are ephemeral. Do not persist them, perform arithmetic on them, or reuse them after inventory or character changes. A successful selection does not create a listing.
Memberships
game._active_subscription_types()
Parameters: None.
Returns: An array containing the currently active supported membership types, an empty array when none of those types are active, or nil, error when subscription state is unavailable.
The supported type IDs are 1, 4, and 35. Matching types are returned in that order. The list is not an enumeration of every subscription product, and this interface supplies no product names, expiry times, remaining duration, or renewal status. An empty array only means none of the three supported types was reported active.
function on_start()
if type(game._active_subscription_types) ~= "function" then
log.warn("Membership API unavailable")
return
end
local types, err = game._active_subscription_types()
if not types then
log.warn(err)
return
end
for _, membershipType in ipairs(types) do
log.info("Active membership type: " .. tostring(membershipType))
end
endgame._membership_type_source()
Parameters: None.
Returns: The first matching supported membership type in the available membership records (1, 4, or 35), 0 when no supported match is selected, or nil, error when the records are unavailable.
This selects a type from the recorded membership list. It does not check whether that membership is currently active or return the highest tier. Use game._active_subscription_types() when your decision depends on active status. Neither call purchases, renews, or cancels a subscription.
Background market summaries
These calls require an updated client. Check that each function exists before using it. Market can stay closed while a script requests public summaries. Queries are read-only; purchase calls spend currency.
game.market_query(trade_type)
Exactly one integer from 0 through 3. Returns a positive local request ID or
nil, error. Use 2 for ordinary Market. Other values refer to other market
services and are not interchangeable. Only one summary query can be pending.
The returned ID confirms that the request started, rather than that data arrived.
game.market_snapshot(request_id, first, limit)
A positive request ID, optional one-based first row (default 1, maximum 32769),
and optional row limit (default 256, from 1 through 512). Returns nil, error
or a table with request_id, server_id, status, total, next,
age_seconds, error_code, error_detail, and rows.
Statuses are pending, ready, failed, timed_out, session_changed,
or unknown. Rows contain item_id, minimum_unit_price, and sale_count.
The minimum unit price can be fractional. next = 0 ends paging. Read the same
request on later ticks until it settles; never resend a request solely because
its reply is delayed. An empty ready result is valid.
This feed contains currently listed item types for the selected service, rather than every item definition or every region. Listing count is current market depth, rather than completed-sales volume. It cannot establish realized profit. Use game data to add definition names and grades.
Offers and purchase requests
game.market_offers_query(trade_type, item_id)
Ordinary market type 2 and a positive item ID. Returns a positive local
request ID or nil, error. Requests individual offers for that item. Completion
includes the pages collected by the client; do not assume the result covers
unlimited service pages.
game.market_offers_snapshot(request_id, first, limit)
A positive request ID, optional one-based first row (default 1), and optional
row limit (default 256). Returns nil, error or a snapshot with status, error
fields, quote age, total, rows, and next. Wait for status = "ready"
before acting on the offers. Rows expose offer_id, item_id, quantity,
total_price, and unit_price. offer_id identifies a row within that request.
It is not a reusable sale identifier.
game.market_buy(request_id, offer_id, quantity, unit_cap, remaining_budget)
A ready offers request, its offer ID, a positive integer quantity, a maximum
unit price, and remaining total budget. Returns accepted, quoted_cost or
nil, error. It requires a fresh quote, sufficient offered quantity, a valid
expiry margin, and a cost within both limits. A request can be consumed only
once. The currently tested purchase path buys whole offered lots; scripts should
select a lot whose quantity fits the desired amount.
Acceptance confirms dispatch, rather than purchase completion. Confirm the purchase response and inventory delivery before logging a successful purchase, playing a success sound, or reducing a target's remaining quantity. Never replay an uncertain purchase. A stale, rejected, or unavailable offer is not a fill.