Skip to content

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.

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=}

false calls the deal off - nothing moves; anything else (or nothing) lets it through

-- a receipt in the chat, and no more than three swords a deal
function 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))
end

OnPlayerBuy · OnPlayerSell · CreateVendor · SetShopBuyPrice · the Shops and vendors group of the index