OnPlayerShopDeal
A deal is about to be done - every line at once; return false to call it off.
Asked last: every line was checked - the stock, what the player carries, the purse that changes hands - and passed
OnPlayerSell / OnPlayerBuy; the items and the money move right after this returns anything but false, so it is
the place for what must happen only when a deal is really done. deal.lines lists the sales first, then the purchases,
one line per item class: {class=, amount=, price=, buy=} (price in Groschen a piece, buy true for a purchase).
deal.cost is what the purchases cost and deal.proceeds what the sales bring; the player pays the difference, or is
paid it. A deal on the shop panel is one line; the trade screen’s “Close deal” sends the whole basket.
Syntax
Section titled “Syntax”function OnPlayerShopDeal(pid, shop, deal) -- ...end| Parameter | Type | |
|---|---|---|
pid |
number | the player |
shop |
number | the shop |
deal |
table | {lines = {{class=, amount=, price=, buy=}, ...}, cost=, proceeds=} |
Returns
Section titled “Returns”false calls the deal off - nothing moves; anything else (or nothing) lets it through
Example
Section titled “Example”-- a receipt in the chat, and no more than three swords a dealfunction OnPlayerShopDeal(pid, shop, deal) local swords = 0 for _, line in ipairs(deal.lines) do if line.buy and GetItemInfo(line.class).category == "MeleeWeapon" then swords = swords + line.amount end end if swords > 3 then SendClientMessage(pid, COLOR_RED, "Three blades at a time.") return false end SendClientMessage(pid, COLOR_SERVER, string.format("Paid %.1f, got %.1f Groschen.", deal.cost, deal.proceeds))endSee also
Section titled “See also”OnPlayerBuy · OnPlayerSell · CreateVendor · SetShopBuyPrice · the Shops and vendors group of the index
