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
https://imgur.com/a/qg7it
remove those items and add them again, step by step with someones tutorial
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
<parameter key="shop_sellable" value="item_name,item_id,item_price;bow,2456,130"/>
<parameter key="shop_sellable" value="bow,2456,130"/>
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)
sellable/buyable items in npc xml file must have atleast 3 things.
becouse:Code:<parameter key="shop_sellable" value="item_name,item_id,item_price;bow,2456,130"/> <parameter key="shop_sellable" value="bow,2456,130"/>
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.
<?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>
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
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 problem is with this function in npc/lib/npcsystem/modules.lua
Becouse it returns nil when it shouldn't.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
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:
Then show me screen of your console with error.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