Player Shop
On this page
Find personal shops and hired merchants on the current map, visit them and buy their listings. NPC shops use Shop instead.
enter() and buy() returning true means sent, not server-confirmed. Send once, then check the window, listing, mesos and inventory on later ticks. Do not repeat purchases every tick or assume unchanged state means it is safe to retry. Buying does not ask for confirmation.
Shop structure
| Property | Type | Description |
|---|---|---|
id | number | Positive unsigned 32-bit shop ID. Pass unchanged to enter(). |
kind | string | "personal" or "merchant". |
owner | string | Owner name. |
title | string | Shop title. |
x | number or nil | Map position; omitted when unavailable. |
y | number or nil | Map position; omitted when unavailable. |
Listing structure
| Property | Type | Description |
|---|---|---|
slot | number | 0-based shop row, not the Lua array index. Pass unchanged to buy(). |
item_id | number | Item template ID. |
name | string or nil | Omitted when item data is unavailable. |
bundles | number | Bundles remaining; zero or negative means sold. |
per_bundle | number | Items in each bundle. |
price | number | Mesos per bundle, not per item. |
stats | table or nil | Equip stats only; omitted for other items. |
Equip stats contains numeric str, dex, int, luk, hp, mp, watk, attack_power, matk, wdef, mdef, acc, avoid, speed, jump, crit_rate, crit_damage, upgrade_slots, and upgrade_count. req_level is optional. No required-job field is exposed.
watk is the item's Weapon Attack; attack_power is its separate Attack Power stat. crit_rate and crit_damage are the numeric Critical Rate and Critical Damage values shown in the item tooltip. upgrade_slots is the number of upgrades left and upgrade_count the number of successful upgrades so far (the item's +N), the same values as remaining_upgrade_count and current_upgrade_count on inventory items.
attack_power, crit_rate, crit_damage and upgrade_count may be absent on older core builds; check for nil before using them.
Functions
core.player_shop.get_shops() -> table<player_shop>
Available on CW
Returns visitable shops on the current map, or an empty array off-map. Each entry has id, kind, owner, title and optional x/y coordinates.
core.player_shop.enter(id: number) -> boolean, string?
Available on CW
Sends one visit request; true means sent, not opened. Poll is_open() on later ticks. id is a positive unsigned 32-bit integer from get_shops(); all scripts share a one-second visit limit.
Returns false, error on refusal. Validation order: no_shop (invalid ID), busy (a dialog is open or the visit limit applies), unavailable (character data unavailable), no_shop (shop no longer listed), then busy (another request prevents entering a personal shop).
core.player_shop.is_open() -> boolean
Available on CW
Returns whether a personal-shop or hired-merchant window is open, including your own shop.
core.player_shop.get_info() -> player_shop_info | nil
Available on CW
Returns kind ("personal" or "merchant"), owner and title, or nil when no shop window is open. Also returns is_owner, is_selling and state ("setup", "selling" or "unknown").
core.player_shop.get_items() -> table<player_shop_item> | nil
Available on CW
Returns listings from the open shop, or nil when none is open. Rows contain slot, item_id, bundles, per_bundle, price and optional name/stats; equip stats may omit req_level. slot is 0-based and price is mesos per bundle. Equip stats include watk (Weapon Attack), attack_power (Attack Power), crit_rate (Critical Rate) and crit_damage (Critical Damage). The critical stats use the tooltip's numeric values. upgrade_slots is upgrades left and upgrade_count is successful upgrades so far. attack_power, crit_rate, crit_damage and upgrade_count may be absent on older core builds.
The array may skip unavailable rows. Use each entry's slot, not its array index.
core.player_shop.buy(slot: number, bundles: number) -> boolean, string?
Available on CW
Sends one purchase request; true means sent, not bought. slot is the 0-based listing slot; bundles is an integer from 1 through 65535. Check items, mesos and inventory later to confirm the result; no confirmation prompt is shown.
Returns false, error on refusal. Validation order:
| Error | Meaning |
|---|---|
bad_slot | Slot is not an integer in 0..4294967295. |
bad_count | Bundles is not an integer in 1..65535. |
unavailable | Purchase support, character data or item data is unavailable. |
not_open | No shop window is open. |
own_shop | Shop belongs to this character or another character on this account. |
closed | Shop is not selling. |
bad_slot | Row does not exist or is malformed. |
bad_count | Sold row, more bundles than remain, more than one for a single-unit item, or total cost exceeds signed 64-bit range. |
restricted | Regional trade restrictions apply. |
not_enough_mesos | Not enough mesos for price multiplied by bundles. |
inventory_full | No empty slot in the item's inventory tab; possible stack merges do not count. |
busy | Another request is pending or purchases cannot be sent yet. |
core.player_shop.close() -> boolean
Available on CW
Leaves the open shop window and returns true, or returns false if none is open.
core.player_shop.get_fm_room() -> number | nil
Available on CW
Returns 0 at Free Market Entrance (80002000), 1..11 in Free Market rooms (80002001..80002011), or nil elsewhere. This reads the current room; it does not travel.
Own a personal store
Creating or managing a hired merchant is not supported. Set the store title when calling create(); changing an existing store's title is not supported.
Owner requests are shared across scripts. Send one request, retain its request_id, and poll get_result() on later ticks before sending another. true, request_id means sent, not accepted. false, reason means no request was sent. A successful result confirms the requested state change; check the current shop and listings before the next action.
A request times out after 10 seconds. A timeout leaves its outcome uncertain and blocks further owner requests until the map or character changes. Do not automatically retry it. A map or character change cancels a pending request. Avoid manually changing the shop or running another store script during a pending request.
get_info() also returns is_owner and is_selling booleans and state ("setup", "selling" or "unknown"). Use stop() to close your store and track its result; close() leaves the shop window.
core.player_shop.create(permit_slot: number, title: string) -> boolean, number | string
Available on CW
Sends a request to open a personal-store setup window at the current position using the permit in permit_slot. Returns true, request_id when sent, or false, reason when refused; poll get_result() before stocking the store.
permit_slot is the permit's positive position in the Cash inventory tab (5), not its item ID. The title must be nonempty, pass the game's text restrictions, and fit in 50 bytes after encoding as Windows-1252. The character must be able to use that personal-store permit here. Hired-merchant permits are not supported.
core.player_shop.add_item(inventory_tab: number, position: number, bundles: number, per_bundle: number, price: number) -> boolean, number | string
Available on CW
Sends a request to list inventory stock in your personal store while it is in setup. Returns true, request_id when sent, or false, reason; price is mesos per bundle, not per item.
Use the inventory item's numeric tab (1 through 5, or 6 for the Deco tab) and position (1 through 32767). bundles, per_bundle and price are positive whole numbers. Each count and bundles * per_bundle must be at most 9999; bundles * price must be at most 499999999999. You must have the full quantity. Single-unit items, including equipment, require both bundles and per_bundle to be 1. Cash items, items that cannot be traded and items with an expiration are refused. Listing an item does not ask for confirmation; verify the item, quantity and price before calling.
core.player_shop.remove_item(shop_slot: number) -> boolean, number | string
Available on CW
Sends a request to remove a listing from your personal store in setup. shop_slot is the 0-based slot from get_items(), not the Lua array index. Returns true, request_id when sent, or false, reason.
core.player_shop.start() -> boolean, number | string
Available on CW
Sends a request to start selling the listings in your personal store. Requires setup state and at least one listing. Returns true, request_id when sent, or false, reason; wait for a succeeded result and check is_selling before treating the store as active.
core.player_shop.stop() -> boolean, number | string
Available on CW
Sends a request to close your personal store in setup or selling state. Returns true, request_id when sent, or false, reason; wait for a succeeded result and confirm the shop window has closed.
core.player_shop.get_result() -> player_shop_result
Available on CW
Returns the latest owner-request result shared by all scripts. Match request_id to the ID returned by your action; this does not track visit or purchase requests.
| Field | Type | Meaning |
|---|---|---|
request_id | number | Request identifier; 0 before any request. |
operation | string | "create", "add_item", "remove_item", "start" or "stop"; empty before any request. |
status | string | "idle", "pending", "succeeded", "rejected", "timed_out" or "cancelled". |
sent | boolean | Whether the request was sent; not proof of success. |
server_code | number | Numeric rejection code, or -1 when none is available. |
reason | string | Refusal/cancellation reason, or empty when none is available. |
Local refusals include bad_slot, not_permit, bad_title, bad_count, bad_price, not_enough_items, untradeable, item_expiring, shop_full, empty_shop, restricted, busy, unavailable, no_character, no_shop, not_owner, not_setup and merchant_unsupported. A local_refusal return can have more specific text in get_result().reason; argument validation may leave the previous result unchanged.
reason may contain a machine-readable reason or display text. Treat unknown reasons as failures. Do not interpret an unknown rejection code as a placement error. System chat text from on_system_message is supplementary and is not correlated to a request.
Open setup once and check the result
This example opens setup only. It does not list or sell inventory, move the character or retry a failed placement. Replace the permit slot with the intended permit's inventory position.
local shop = core.player_shop
local request_id = nil
local attempted = false
function on_tick(stage)
if stage ~= core.stage.FIELD then return end
if not shop or type(shop.create) ~= "function" or type(shop.get_result) ~= "function" then
if not attempted then
core.log_warning("Store setup is unavailable in this core")
attempted = true
end
return
end
if not attempted then
attempted = true
local sent, result = shop.create(1, "My store")
if not sent then
core.log_warning(tostring(result))
return
end
request_id = result
end
if not request_id then return end
local result = shop.get_result()
if result.request_id ~= request_id then
core.log_warning("Another store request replaced the result")
request_id = nil
elseif result.status ~= "pending" then
core.log(result.status .. ": " .. result.reason)
request_id = nil
end
endRead listings without buying
local items = core.player_shop.get_items()
if items then
for _, item in ipairs(items) do
core.log(string.format("slot %d: %s, %d mesos per bundle",
item.slot, item.name or tostring(item.item_id), item.price))
end
endClose the shop before equipping gear. Check API availability before calling these functions on an older core or another game.