Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Callback onSell() function. If you wish, you can change certain Npc to use your onSell().
- function ShopModule:callbackOnSell(cid, itemid, subType, amount, ignoreCap, inBackpacks)
- local shopItem = nil
- for _, item in ipairs(self.npcHandler.shopItems) do
- if(item.id == itemid and item.subType == subType) then
- shopItem = item
- break
- end
- end
- if(shopItem == nil) then
- print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onSell - Item not found on shopItems list')
- return false
- end
- if(shopItem.sell == -1) then
- print('[Warning - ' .. getCreatureName(getNpcId()) .. '] NpcSystem:', 'ShopModule.onSell - Attempt to sell an item which is only buyable')
- return false
- end
- local parseInfo = {
- [TAG_PLAYERNAME] = getPlayerName(cid),
- [TAG_ITEMCOUNT] = amount,
- [TAG_TOTALCOST] = amount * shopItem.sell,
- [TAG_ITEMNAME] = shopItem.name
- }
- if(subType < 1 or getItemInfo(itemid).stackable) then
- subType = -1
- end
- if getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).itemid ~= 0 then
- local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
- local z = getContainerItemsById(bp, itemid)
- if #z >= amount then
- for i = 1, amount do
- doRemoveItem(z[i].uid)
- end
- local msg = self.npcHandler:getMessage(MESSAGE_SOLD)
- msg = self.npcHandler:parseMessage(msg, parseInfo)
- doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
- doPlayerAddMoney(cid, amount * shopItem.sell)
- if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
- self.npcHandler.talkStart[cid] = os.time()
- else
- self.npcHandler.talkStart = os.time()
- end
- return true
- else
- local msg = self.npcHandler:getMessage(MESSAGE_NEEDITEM)
- msg = self.npcHandler:parseMessage(msg, parseInfo)
- doPlayerSendCancel(cid, msg)
- if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
- self.npcHandler.talkStart[cid] = os.time()
- else
- self.npcHandler.talkStart = os.time()
- end
- return false
- end
- else
- doPlayerSendCancel(cid, "I only buy items that are inside a BackPack")
- if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
- self.npcHandler.talkStart[cid] = os.time()
- else
- self.npcHandler.talkStart = os.time()
- end
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement