• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ TFS 1.3 8.60

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,297
Reaction score
127
Hello, i got problem with npc not selling things in backpacks...

If you say trade to npc, etc rune shop, you can see you can mark bird to ''buy with backpacks"
i try buy 20x runes with backpack, after some try to fix code. i get this error now
Lua:
Lua Script Error: [Npc interface]
(Unknown scriptfile)
data/npc/lib/npc.lua:38: attempt to call method 'addItem' (a nil value)
stack traceback:
        [C]: in function 'addItem'
        data/npc/lib/npc.lua:38: in function 'doNpcSellItem'
        data/npc/lib/npcsystem/modules.lua:1084: in function 'callbackOnBuy'
        data/npc/lib/npcsystem/npchandler.lua:268: in function 'processModuleCallback'
        data/npc/lib/npcsystem/npchandler.lua:464: in function 'onBuy'
        data/npc/lib/npcsystem/modules.lua:1184: in function <data/npc/lib/npcsystem/modules.lua:1184>

Can someone please help out ?
 
Solution
looks fine, i dont have 1.3 but 1.4 seems to use
Lua:
ITEM_SHOPPING_BAG = 23782
if you are using 8.6 spr/dat there is probably no item with this id try to change all
Code:
ITEM_SHOPPING_BAG
to
Code:
ITEM_BAG
in npc/lib/npcsystem/modules.lua
looks fine, i dont have 1.3 but 1.4 seems to use
Lua:
ITEM_SHOPPING_BAG = 23782
if you are using 8.6 spr/dat there is probably no item with this id try to change all
Code:
ITEM_SHOPPING_BAG
to
Code:
ITEM_BAG
in npc/lib/npcsystem/modules.lua
 
Solution
post your doNpcSellItem function in data/npc/lib/npc.lua

This is my npc.luna in libs

Lua:
-- Including the Advanced NPC System
dofile('data/npc/lib/npcsystem/npcsystem.lua')
dofile('data/npc/lib/npcsystem/customModules.lua')

isPlayerPremiumCallback = Player.isPremium

function msgcontains(message, keyword)
    local message, keyword = message:lower(), keyword:lower()
    if message == keyword then
        return true
    end

    return message:find(keyword) and not message:find('(%w+)' .. keyword)
end

function doNpcSellItem(cid, itemId, amount, subType, ignoreCap, inBackpacks, backpack)
    local amount = amount or 1
    local subType = subType or 0
    local item = 0
    local player = Player(cid)

    if ItemType(itemId):isStackable() then
        local stuff
        if inBackpacks then
            stuff = Game.createItem(backpack, 1)
            item = stuff:addItem(itemId, math.min(100, amount))
        else
            stuff = Game.createItem(itemId, math.min(100, amount))
        end

        return player:addItemEx(stuff, ignoreCap) ~= RETURNVALUE_NOERROR and 0 or amount, 0
    end

    local a = 0
    if inBackpacks then
        local container, b = Game.createItem(backpack, 1), 1
        for i = 1, amount do
            local item = container:addItem(itemId, amount, subType)
            if table.contains({(ItemType(backpack):getCapacity() * b), amount}, i) then
                if player:addItemEx(container, ignoreCap) ~= RETURNVALUE_NOERROR then
                    b = b - 1
                    break
                end

                a = i
                if amount > i then
                    container = Game.createItem(backpack, 1)
                    b = b + 1
                end
            end
        end

        return a, b
    end

    for i = 1, amount do -- normal method for non-stackable items
        local item = Game.createItem(itemId, subType)
        if player:addItemEx(item, ignoreCap) ~= RETURNVALUE_NOERROR then
            break
        end
        a = i
    end
    return a, 0
end

local func = function(cid, text, type, e, pcid)
    local npc = Npc(cid)
    if not npc then
        return
    end

    local player = Player(pcid)
    if player:isPlayer() then
        local creature = Creature(cid)
        creature:say(text, type, false, pcid, creature:getPosition())
        e.done = true
    end
end

function doCreatureSayWithDelay(cid, text, type, delay, e, pcid)
    if Player(pcid):isPlayer() then
        e.done = false
        e.event = addEvent(func, delay < 1 and 1000 or delay, cid, text, type, e, pcid)
    end
end

function doPlayerSellItem(cid, itemid, count, cost)
    local player = Player(cid)
    if player:removeItem(itemid, count) then
        if not player:addMoney(cost) then
            error('Could not add money to ' .. player:getName() .. '(' .. cost .. 'gp)')
        end
        return true
    end
    return false
end

function doPlayerBuyItemContainer(cid, containerid, itemid, count, cost, charges)
    local player = Player(cid)
    if not player:removeMoney(cost) then
        return false
    end

    for i = 1, count do
        local container = Game.createItem(containerid, 1)
        for x = 1, ItemType(containerid):getCapacity() do
            container:addItem(itemid, charges)
        end

        if player:addItemEx(container, true) ~= RETURNVALUE_NOERROR then
            return false
        end
    end
    return true
end

function getCount(string)
    local b, e = string:find("%d+")
    return b and e and tonumber(string:sub(b, e)) or -1
end
 
looks fine, i dont have 1.3 but 1.4 seems to use
Lua:
ITEM_SHOPPING_BAG = 23782
if you are using 8.6 spr/dat there is probably no item with this id try to change all
Code:
ITEM_SHOPPING_BAG
to
Code:
ITEM_BAG
in npc/lib/npcsystem/modules.lua
oke il try it,
Post automatically merged:

looks fine, i dont have 1.3 but 1.4 seems to use
Lua:
ITEM_SHOPPING_BAG = 23782
if you are using 8.6 spr/dat there is probably no item with this id try to change all
Code:
ITEM_SHOPPING_BAG
to
Code:
ITEM_BAG
in npc/lib/npcsystem/modules.lua
Fixed all this , was shooping bag, changed to bag


this error here now

Lua:
Lua Script Error: [Npc interface]
(Unknown scriptfile)
data/npc/lib/npc.lua:38: attempt to call method 'addItem' (a nil value)
stack traceback:
        [C]: in function 'addItem'
        data/npc/lib/npc.lua:38: in function 'doNpcSellItem'
        data/npc/lib/npcsystem/modules.lua:1084: in function 'callbackOnBuy'
        data/npc/lib/npcsystem/npchandler.lua:268: in function 'processModuleCallback'
        data/npc/lib/npcsystem/npchandler.lua:464: in function 'onBuy'
        data/npc/lib/npcsystem/modules.lua:1184: in function <data/npc/lib/npcsystem/modules.lua:1184>



Instead of ITEM_SHOPPING_BAG i put ITEM_BAG. Did reload and this error...
 
Last edited:
looks fine, i dont have 1.3 but 1.4 seems to use
Lua:
ITEM_SHOPPING_BAG = 23782
if you are using 8.6 spr/dat there is probably no item with this id try to change all
Code:
ITEM_SHOPPING_BAG
to
Code:
ITEM_BAG
in npc/lib/npcsystem/modules.lua
Oke i did server restart,RR , and its working . Thanks alot.

How do i make it sell with ANY ID backpack i set ? Now is bag, i want to make it sells with Backpack not with bag
 
Back
Top