Skip to content

OnPlayerBuy

The player is about to buy from a shop - return false to refuse.

The stock and the purse were checked already: amount is available and the player can pay amount x price. Return false and nothing moves (say why with SendClientMessage); anything else lets the items and the money go. The class is the item’s GUID (GetItemInfo names it).

function OnPlayerBuy(pid, shop, class, amount, price)
-- ...
end
Parameter Type
pid number the buyer
shop number the shop
class string the item’s class GUID
amount number how many
price number Groschen a piece

false refuses the purchase; anything else (or nothing) lets it through

-- one sword per customer
function OnPlayerBuy(pid, shop, class, amount, price)
local info = GetItemInfo(class)
if info and info.category == "MeleeWeapon" and (GetPlayerData(pid, "swords") or 0) >= 1 then
SendClientMessage(pid, COLOR_RED, "One blade is enough for you.")
return false
end
if info and info.category == "MeleeWeapon" then SetPlayerData(pid, "swords", 1) end
end

OnPlayerSell · CreateShop · SetShopItem · GetPlayerMoney · the Shops and vendors group of the index