• 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+ data/npc/lib/npcsystem/modules items[itemid] == nil error

henkas

Well-Known Member
Joined
Jul 8, 2015
Messages
993
Solutions
5
Reaction score
55
Code:
Lua Script Error: [Npc interface]
(Unknown scriptfile)
data/npc/lib/npcsystem/modules.lua:1014: [ShopModule.onSell] items[itemid] == nil
stack traceback:
    [C]: at 0x555555661da0
    [C]: in function 'error'
    data/npc/lib/npcsystem/modules.lua:1014: in function 'callbackOnSell'
    data/npc/lib/npcsystem/npchandler.lua:265: in function 'processModuleCallback'
    data/npc/lib/npcsystem/npchandler.lua:469: in function 'onSell'
    data/npc/lib/npcsystem/modules.lua:1077: in function <data/npc/lib/npcsystem/modules.lua:1077>


data/npc/lib/npcsystem/modules.lua:1014: in function 'callbackOnSell'
Lua:
    -- Callback onSell() function. If you wish, you can change certain Npc to use your onSell().
    function ShopModule:callbackOnSell(cid, itemid, subType, amount, ignoreEquipped, _)
        local shopItem = self:getShopItem(itemid, subType)
        if shopItem == nil then
            error("[ShopModule.onSell] items[itemid] == nil")
            return false
        end

        if shopItem.sell == -1 then
            error("[ShopModule.onSell] attempt to sell a non-sellable item")
            return false
        end

        local parseInfo = {
            [TAG_PLAYERNAME] = getPlayerName(cid),
            [TAG_ITEMCOUNT] = amount,
            [TAG_TOTALCOST] = amount * shopItem.sell,
            [TAG_ITEMNAME] = shopItem.name
        }

        if not isItemFluidContainer(itemid) then
            subType = -1
        end

        if doPlayerRemoveItem(cid, itemid, amount, subType, ignoreEquipped) then
            local msg = self.npcHandler:getMessage(MESSAGE_SOLD)
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
            doPlayerAddMoney(cid, amount * shopItem.sell)
            self.npcHandler.talkStart[cid] = os.time()
            return true
        else
            local msg = self.npcHandler:getMessage(MESSAGE_NEEDITEM)
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            doPlayerSendCancel(cid, msg)
            self.npcHandler.talkStart[cid] = os.time()
            return false
        end
    end

data/npc/lib/npcsystem/npchandler.lua:265: in function 'processModuleCallback'
Code:
    -- UnGreeting callback function.
    function FocusModule.onFarewell(cid, message, keywords, parameters)
        if parameters.module.npcHandler:isFocused(cid) then
            parameters.module.npcHandler:onFarewell(cid)
            return true
        else
            return false
        end
    end

data/npc/lib/npcsystem/npchandler.lua:469: in function 'onSell'
Lua:
    function TravelModule.onConfirm(cid, message, keywords, parameters, node)
        local module = parameters.module
        if not module.npcHandler:isFocused(cid) then
            return false
        end

        if shop_npcuid[cid] ~= Npc().uid then
            return false
        end

        local npcHandler = module.npcHandler

        local cost = shop_cost[cid]
        local destination = Position(shop_destination[cid])

        local player = Player(cid)
        if player:isPremium() or not shop_premium[cid] then
            if not player:removeMoneyNpc(cost) then
                npcHandler:say("You do not have enough money!", cid)
            elseif player:isPzLocked(cid) then
                npcHandler:say("Get out of there with this blood.", cid)
            else
                npcHandler:say("It was a pleasure doing business with you.", cid)
                npcHandler:releaseFocus(cid)

                local position = player:getPosition()
                player:teleportTo(destination)

                position:sendMagicEffect(CONST_ME_TELEPORT)
                destination:sendMagicEffect(CONST_ME_TELEPORT)
            end
        else
            npcHandler:say("I can only allow premium players to travel there.", cid)
        end

        npcHandler:resetNpc(cid)
        return true
    end

data/npc/lib/npcsystem/modules.lua:1077: in function <data/npc/lib/npcsystem/modules.lua:1077>
Lua:
    -- Callback for requesting a trade window with the NPC.
    function ShopModule.requestTrade(cid, message, keywords, parameters, node)
        local module = parameters.module
        if not module.npcHandler:isFocused(cid) then
            return false
        end

        if not module.npcHandler:onTradeRequest(cid) then
            return false
        end

        local itemWindow = {}
        for i = 1, #module.npcHandler.shopItems do
            itemWindow[#itemWindow + 1] = module.npcHandler.shopItems[i]
        end

        if itemWindow[1] == nil then
            local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
            local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_NOSHOP), parseInfo)
            module.npcHandler:say(msg, cid)
            return true
        end

        local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
        local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_SENDTRADE), parseInfo)
        openShopWindow(cid, itemWindow,
            function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks) end,
            function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onSell(cid, itemid, subType, amount, ignoreCap, inBackpacks) end)
        module.npcHandler:say(msg, cid)
        return true
    end

FULL FILE
 
But its not an exact npc issue because there is nothing wrong on those npcs. The issue is with npcsystem/modules
 
Which version of TFS are you using? Nekiro? TFS 1.4.2? I noticed that these NPC libs are mixed between TFS 0.4 and 1.x functions. I recommend that you use the original 'lib' specifically designed for TFS 1.x. If you simply moved TFS 0.4 to TFS 1.x, it definitely won't work. I recommend using the original 'lib' specifically made for TFS 1.x.

Compare your 'lib' with the original one for TFS 1.x to see the difference.

your "lib".
1708948970571.png
original tfs 1.x+
1708949076812.png
 
Back
Top