function onUse(cid, item, fromPosition, itemEx, toPosition)
local cfg =
{
[23001] = {backpackid = 2000, rune = 7618, charges = 1, cost = 1000},
[23002] = {backpackid = 2001, rune = 7620, charges = 1, cost = 1000},
[23003] = {backpackid = 2002, rune = 7588, charges = 1, cost = 2000},
[23004] = {backpackid = 2003, rune = 7589, charges = 1, cost = 1600},
[23005] = {backpackid = 2004, rune = 7591, charges = 1, cost = 3800},
[23006] = {backpackid = 5949, rune = 7590, charges = 1, cost = 2400},
[23007] = {backpackid = 1998, rune = 8472, charges = 1, cost = 3800},
[23008] = {backpackid = 1999, rune = 8473, charges = 1, cost = 6200},
[23009] = {backpackid = 3940, rune = 2268, charges = 7, cost = 6520},
[23010] = {backpackid = 7342, rune = 2293, charges = 7, cost = 7000},
[23011] = {backpackid = 10519, rune = 2260, charges = 1, cost = 200}
}
-- Variables --
local price = cfg[item.uid].cost
local types = cfg[item.uid].rune
local count = cfg[item.uid].charges
local bag = cfg[item.uid].backpackid
local name = getItemNameById(types)
local backpack_weight = getItemWeightById(bag,1)
local potions_weight = getItemWeightById(types,20)
local total_weight = backpack_weight + potions_weight
-- End --
if getPlayerMoney(cid) > price then
if getPlayerFreeCap(cid) > total_weight then
addBackpack = doCreateItemEx(bag,1)
for i=1,20 do
doAddContainerItem(addBackpack, types, count)
end
local addItemToPlayer = doPlayerAddItemEx(cid, addBackpack , 0)
if addItemToPlayer == RETURNVALUE_NOERROR then
doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
doSendAnimatedText(fromPosition, "Bought!", TEXTCOLOR_RED)
doPlayerRemoveMoney(cid, price)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have purchased a backpack of ".. name .."s for ".. price .." gold.")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don\'t have enough space in your backpack to put there a backpack of ".. name .."s.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. total_weight .." oz. to take a backpack of ".. name .."s.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need ".. price .." gold coins for a backpack of ".. name .."s.")
end
return TRUE
end