local config = {
actionid = 20000,
itemid = 2671,
amount = 1,
price = 5
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.actionid == config.actionid then
if getPlayerMoney(cid) >= config.price then
if getPlayerFreeCap(cid) >= getItemWeightById(config.itemid, config.amount) then
local itemToAdd = doCreateItemEx(config.itemid, config.amount)
if doPlayerAddItemEx(cid, itemToAdd, 0) == TRUE then
if config.amount > 1 then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought " .. config.amount .. "x " .. getItemDescriptions(config.itemid).plural .. " for " .. config.price .. " gold.")
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Bought " .. config.amount .. "x " .. getItemNameById(config.itemid) .. " for " .. config.price .. " gold.")
end
doPlayerRemoveMoney(cid, config.price)
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have no room to take it.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enough capacity, " .. config.amount .. " " .. getItemDescriptions(config.itemid).plural .. " weigh " .. getItemWeightById(config.itemid, config.amount) .. " oz.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enough money, " .. config.amount .. " " .. getItemDescriptions(config.itemid).plural .. " cost " .. config.price .. " gold.")
end
else
return FALSE
end
return TRUE
end