• 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!

Lua Cant sell new item ID to NPC

haiguri

New Member
Joined
Jun 25, 2012
Messages
18
Reaction score
0
Hi, I added some new items to my OT (itens.otb and items.xml) and they're just fine. However, when I try to sell those new itens to a NPC, it just doesnt sell and gives me an error:

https://imgur.com/a/qg7it
 
remove those items and add them again, step by step with someones tutorial

or

look how to add properly sellable items in npc xml file
 
here's your error:
Code:
        local shopItem = self:getShopItem(itemid, subType)
        if shopItem == nil then
            error("[ShopModule.onSell] items[itemid] == nil")
            return false
        end
remove those items and add them again, step by step with someones tutorial

or

look how to add properly sellable items in npc xml file
 
here's your error:
Code:
        local shopItem = self:getShopItem(itemid, subType)
        if shopItem == nil then
            error("[ShopModule.onSell] items[itemid] == nil")
            return false
        end

Yea, I've seen that if condition... it seems that the itemid in the getShopItem function is null
 
sellable/buyable items in npc xml file must have atleast 3 things.

Code:
<parameter key="shop_sellable" value="item_name,item_id,item_price;bow,2456,130"/>
<parameter key="shop_sellable" value="bow,2456,130"/>
becouse:
Code:
            local name = nil
            local itemid = nil
            local cost = nil
            local realName = nil
            local subType = nil

            for temp in string.gmatch(item, "[^,]+") do
                if i == 1 then
                    name = temp
                elseif i == 2 then
                    itemid = tonumber(temp)
                elseif i == 3 then
                    cost = tonumber(temp)

You will have such error if you put only 2 things in shop_sellable's value, like itemid and price only. Your script is trying to find itemid based on price.
So, im 100% sure you made a mistake here.


edit:
Also on older tfs I noticed a bug when itemname doesn't matches itemid.
 
Last edited:
sellable/buyable items in npc xml file must have atleast 3 things.

Code:
<parameter key="shop_sellable" value="item_name,item_id,item_price;bow,2456,130"/>
<parameter key="shop_sellable" value="bow,2456,130"/>
becouse:
Code:
            local name = nil
            local itemid = nil
            local cost = nil
            local realName = nil
            local subType = nil

            for temp in string.gmatch(item, "[^,]+") do
                if i == 1 then
                    name = temp
                elseif i == 2 then
                    itemid = tonumber(temp)
                elseif i == 3 then
                    cost = tonumber(temp)

You will have such error if you put only 2 things in shop_sellable's value, like itemid and price only. Your script is trying to find itemid based on price.
So, im 100% sure you made a mistake here.


edit:
Also on older tfs I noticed a bug when itemname doesn't matches itemid.

Since I'm using TFS 1.2, it shouldn't be a problem. I'm still getting error. That's how my npc.xml is:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Thorin" script="loot.lua" walkinterval="2000" floorchange="0">
<health now="150" max="150"/>
<look type="66"/>
<parameters>
<parameter key="module_shop" value="1"/>
<parameter key="message_greet" value="Hello |PLAYERNAME|. Eu vendo alguns itens Caso não consiga comprar algum iten, diga {buy staff of baiak}, etc."/>
<parameter key="shop_buyable" value="pick,2553,5000;"/>
<parameter key="shop_sellable" value="mined red gem,26354,600;bow,2456,130"/>
</parameters>
</npc>

I'm using 3 parameters for sellable items.. item name, item id and price.
 
Then problem is with this function in npc/lib/npcsystem/modules.lua
Code:
    function ShopModule:getShopItem(itemId, itemSubType)
        if ItemType(itemId):isFluidContainer() then
            for i = 1, #self.npcHandler.shopItems do
                local shopItem = self.npcHandler.shopItems[i]
                if shopItem.id == itemId and shopItem.subType == itemSubType then
                    return shopItem
                end
            end
        else
            for i = 1, #self.npcHandler.shopItems do
                local shopItem = self.npcHandler.shopItems[i]
                if shopItem.id == itemId then
                    return shopItem
                end
            end
        end
        return nil
    end
Becouse it returns nil when it shouldn't.

Maybe your mined red gem is a fluid container? Check your tibia.dat and items.otb again. If not then, try to replace that function with with this one:
Code:
    function ShopModule:getShopItem(itemId, itemSubType)
        if ItemType(itemId):isFluidContainer() then
            for i = 1, #self.npcHandler.shopItems do
                local shopItem = self.npcHandler.shopItems[i]
                if shopItem.id == itemId and shopItem.subType == itemSubType then
                    return shopItem
                end
            end
        else
            for i = 1, #self.npcHandler.shopItems do
                local shopItem = self.npcHandler.shopItems[i]
                if shopItem.id == itemId then
                    return shopItem
                end
            end
        end
        print(">>>>>> ERROR with local shopItem = self.npcHandler.shopItems[i], it returns nil")
        return nil
    end
Then show me screen of your console with error.
 
Then problem is with this function in npc/lib/npcsystem/modules.lua
Code:
    function ShopModule:getShopItem(itemId, itemSubType)
        if ItemType(itemId):isFluidContainer() then
            for i = 1, #self.npcHandler.shopItems do
                local shopItem = self.npcHandler.shopItems[i]
                if shopItem.id == itemId and shopItem.subType == itemSubType then
                    return shopItem
                end
            end
        else
            for i = 1, #self.npcHandler.shopItems do
                local shopItem = self.npcHandler.shopItems[i]
                if shopItem.id == itemId then
                    return shopItem
                end
            end
        end
        return nil
    end
Becouse it returns nil when it shouldn't.

Maybe your mined red gem is a fluid container? Check your tibia.dat and items.otb again. If not then, try to replace that function with with this one:
Code:
    function ShopModule:getShopItem(itemId, itemSubType)
        if ItemType(itemId):isFluidContainer() then
            for i = 1, #self.npcHandler.shopItems do
                local shopItem = self.npcHandler.shopItems[i]
                if shopItem.id == itemId and shopItem.subType == itemSubType then
                    return shopItem
                end
            end
        else
            for i = 1, #self.npcHandler.shopItems do
                local shopItem = self.npcHandler.shopItems[i]
                if shopItem.id == itemId then
                    return shopItem
                end
            end
        end
        print(">>>>>> ERROR with local shopItem = self.npcHandler.shopItems[i], it returns nil")
        return nil
    end
Then show me screen of your console with error.

It's not a fluid container. I've checked it in Item Editor

Image: https://imgur.com/a/xenGO
 
Back
Top