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).
Syntax
Section titled “Syntax”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 |
Returns
Section titled “Returns”false refuses the purchase; anything else (or nothing) lets it through
Example
Section titled “Example”-- one sword per customerfunction 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) endendSee also
Section titled “See also”OnPlayerSell · CreateShop · SetShopItem · GetPlayerMoney · the Shops and vendors group of the index
