Skip to content

rq.shop ​

since 0.2.0 changed 2.35.0

Adds stock to Frostbuy, the item shop, and reports purchases.

The game refills the shop's stock in Tアイテム屋 every time the shop opens. The first on_stock, in_stock or stock wraps the end of that function so on_stock callbacks run right after the game's own refill. The calls take an item number or a text id.

lua
rq.shop.on_stock(function()
  if not rq.shop.in_stock(306) then rq.shop.stock(306) end -- Skill Again
end)

Functions ​

NameSummary
rq.shop.installWraps the end of Tアイテム屋 so on_stock callbacks run and stock works.
rq.shop.in_stockReturns whether an item is already on sale in the shop.
rq.shop.stockPuts one item on sale, through the game's Tアイテム屋/入荷品.
rq.shop.restocksReturns whether the shop puts another copy of an item on sale on the next visit, once the one on sale is bought.
rq.shop.restockPuts the next copy of an item on sale now, as the next visit would.
rq.shop.nextReturns the copies of an item the shop would sell one after another: the one on sale now, then one for each rq.shop.restock.
rq.shop.donationsReturns the donations count and Frostbuy's reward goal (◆寄付, ◆寄付ボーナス).
rq.shop.set_donationsWrites the donations count, and the reward goal when given.

rq.shop.install ​

lua
rq.shop.install() -> boolean

since 0.2.0 changed 2.35.0

Wraps the end of Tアイテム屋 so on_stock callbacks run and stock works.

Not needed since 2.35.0: each call that needs it places it the first time, and raises this call's error there when it cannot. Calling it still does no harm.

ReturnsTypeDescription
okbooleantrue when the hook is in place; a failure raises an error.

Changed in 2.35.0: Not needed: on_stock, in_stock and stock make it.

rq.shop.in_stock ​

lua
rq.shop.in_stock(no) -> boolean

since 0.2.0 changed 0.9.0 changed 2.35.0

Returns whether an item is already on sale in the shop.

It asks the game whether an instance of that item has the shop's existence value, 6.

ParameterTypeDescription
nointeger|stringAn item number or text id.
ReturnsTypeDescription
stockedbooleantrue when the shop already sells it.

Changed in 0.9.0: Accepts a text id.

Changed in 2.35.0: Answers without rq.shop.install; before it, it always said false.

rq.shop.stock ​

lua
rq.shop.stock(no) -> integer

since 0.2.0 changed 0.9.0 changed 0.26.0 changed 2.35.0 changed 2.47.0

Puts one item on sale, through the game's Tアイテム屋/入荷品.

Raises an error for an unknown item, or for a value that is not a number or a text id.

ParameterTypeDescription
nointeger|stringAn item number or text id.
ReturnsTypeDescription
iiintegerThe new instance, or 0 when the shop already had the item or the game refused it.

Changed in 0.9.0: Accepts a text id.

Changed in 0.26.0: An unknown item raises an error instead of closing the game.

Changed in 2.35.0: No rq.shop.install needed; it raised an error before it.

Changed in 2.47.0: While the shop shows, the item is on its list at once (it waited for the next visit).

rq.shop.restocks ​

lua
rq.shop.restocks(no) -> boolean

since 2.49.0

Returns whether the shop puts another copy of an item on sale on the next visit, once the one on sale is bought.

These are the game's own rules (Tアイテム屋, which refills the stock once a visit): an item whose restock count (◆アイテム補充数) is not 0 (most weapons and armor, the special items the second world adds, some held items such as the Capture Rope), Forbidden Talent (304) from the third world on, and Forbidden Talent - Weak (305) once quest 20 is cleared. It is false for the items the game sells only while the player owns none (Skill Again, the Character Ticket, Tama's items), once, or never, and for a mod's item: a mod restocks its own items in rq.shop.on_stock or on_buy.

Raises an error for a value that is not a number or a text id.

lua
if rq.shop.restocks(304) then rq.log("Forbidden Talent comes back on every visit") end
ParameterTypeDescription
nointeger|stringAn item number or text id.
ReturnsTypeDescription
restocksbooleantrue when the next visit puts another on sale.

See also: rq.shop.restock

rq.shop.restock ​

lua
rq.shop.restock(no) -> integer

since 2.49.0

Puts the next copy of an item on sale now, as the next visit would.

When rq.shop.restocks(no) is true and none is on sale, it calls rq.shop.stock(no): the game's Tアイテム屋/入荷品 adds 1 to the restock count and makes the copy, so a weapon or armor comes a level higher (① to ⑨, at the game's price), and an open shop lists it at once. Otherwise it does nothing. With it a mod can sell several copies in one visit, one rq.item.buy after another.

Raises an error for a value that is not a number or a text id.

lua
local no = rq.item.number(ii)
if rq.item.buy(ii, { ask = false }) then rq.shop.restock(no) end
ParameterTypeDescription
nointeger|stringAn item number or text id.
ReturnsTypeDescription
iiintegerThe new instance, or 0 when the item does not restock, one is already on sale, or the game refused it.

See also: rq.shop.next

rq.shop.next ​

lua
rq.shop.next(no, n) -> rq.ShopCopy[]

since 2.49.0

Returns the copies of an item the shop would sell one after another: the one on sale now, then one for each rq.shop.restock.

Each copy is read from the game's own creation at the restock count it would have (an instance made quietly, read and deleted, and the count put back), so its level, name, price and stats are the game's, with a mod's rq.item.edit and the world's bonus. A weapon's or armor's copies go up a level each, up to ⑨; past it, and for an item whose data does not follow the count, the last copy repeats without another instance. One copy when the item does not restock (rq.shop.restocks), none when none is on sale. It only reads: buying is rq.item.buy, then rq.shop.restock, one copy at a time.

Raises an error for a value that is not a number or a text id, or an n that is not a whole number of 1 or more.

lua
local cost = 0
for _, c in ipairs(rq.shop.next(90, 5)) do cost = cost + c.price end -- the next 5 Buster Swords
ParameterTypeDescription
nointeger|stringAn item number or text id.
n (optional)integerHow many copies, 1 or more. Default 1.
ReturnsTypeDescription
copiesrq.ShopCopy []The copies, the one on sale first; empty when none is on sale.

rq.shop.donations ​

lua
rq.shop.donations() -> integer, integer

since 2.23.0

Returns the donations count and Frostbuy's reward goal (◆寄付, ◆寄付ボーナス).

DONATE in the vault adds to the count. On a visit, when Frostbuy's talk about donations has been seen and the count is at the goal or above, she gives one reward and the goal goes up by 25. A world transfer sets the count to 0 and the goal to 25.

lua
local count, goal = rq.shop.donations()
rq.log(("donated %d, next reward at %d"):format(count, goal))
ReturnsTypeDescription
countintegerThe donations count.
goalintegerThe count at which Frostbuy gives her next reward.

See also: rq.shop.set_donations

rq.shop.set_donations ​

lua
rq.shop.set_donations(count, goal)

since 2.23.0

Writes the donations count, and the reward goal when given.

Frostbuy reads both on a visit (see rq.shop.donations). Two things to know:

  • A count at the goal or above gives a reward on the next visit. To set a count without one, set the goal above it, as (count // 25 + 1) * 25 does.
  • While her talk about donations has not been seen, a count other than 0 plays the talk on a visit and sets the goal to 25. Mark it seen with rq.scene.seen to skip it.

Raises an error for a count or goal that is not a whole number, 0 or more.

lua
local count = 60
rq.shop.set_donations(count, (count // 25 + 1) * 25) -- 60, next reward at 75
ParameterTypeDescription
countintegerThe donations count.
goal (optional)integerThe reward goal. Default: kept as it is.

See also: rq.shop.donations

Events ​

NameSummary
rq.shop.on_stockRegisters a function that runs after the game refills the shop's stock.
rq.shop.on_buyRegisters a function that runs after each Frostbuy purchase.
rq.shop.on_can_buyRegisters a function that can refuse a Frostbuy purchase before it happens.

rq.shop.on_stock ​

lua
rq.shop.on_stock(fn) -> fun()

since 0.2.0 changed 0.9.0 changed 0.23.0 changed 2.35.0

Registers a function that runs after the game refills the shop's stock.

It runs on every shop open. Up to 16 callbacks. An error in a callback is written to the log and the others still run.

ParameterTypeDescription
fnfun()Adds stock, usually with rq.shop.stock.
ReturnsTypeDescription
removefun()Removes this callback.

Changed in 0.9.0: Keeps every mod's callback (before, the last one replaced the others).

Changed in 0.23.0: Returns a remover.

Changed in 2.35.0: Wraps the shop itself; before rq.shop.install it never ran.

See also: rq.shop.stock

rq.shop.on_buy ​

lua
rq.shop.on_buy(fn) -> fun()

since 0.9.0 changed 0.23.0 changed 2.49.0

Registers a function that runs after each Frostbuy purchase.

It wraps the end of T_Shop@buyItem the first time it is used, so it needs no install. It runs for rq.item.buy too, so a mod's purchase counts as the player's drag. Use it to count purchases, and raise the next price in on_stock. Up to 16 callbacks; an error in one is written to the log.

lua
rq.shop.on_buy(function(ctx)
  rq.log("bought", ctx.name, "for", ctx.price)
end)
ParameterTypeDescription
fnfun(ctx: rq.BuyCtx )Gets the purchase.
ReturnsTypeDescription
removefun()Removes this callback.

Changed in 0.23.0: Returns a remover.

Changed in 2.49.0: Runs for rq.item.buy too.

rq.shop.on_can_buy ​

lua
rq.shop.on_can_buy(fn) -> fun()

since 2.50.0

Registers a function that can refuse a Frostbuy purchase before it happens.

It runs when the player drags an item from the shop's rack onto the vault or a party member, before the game checks the money and asks "Purchase ...?", and for rq.item.buy. Return false and a text to refuse: the game's notice shows the text (none for nil or ""), the item stays on the rack and nothing is paid. Return true or nil to let it go on. The first refusal wins. Use it for an item that may be bought only at some times; to take an item off the rack, use rq.shop.on_stock. An error in a callback is logged once per text, and the purchase goes on.

Raises an error when fn is not a function.

lua
rq.shop.on_can_buy(function(ctx)
  if ctx.id == "mymod:ticket" and rq.game.gold() < 100000 then
    return false, "Come back with 100,000 Gold."
  end
end)
ParameterTypeDescription
fnfun(ctx: rq.CanBuyCtx ): (boolean|nil, string?)Gets the purchase; returns false and a text to refuse.
ReturnsTypeDescription
removefun()Removes this callback.

See also: rq.shop.on_buy, rq.item.buy