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

npc not open trade window

iib0w

New Member
Joined
Jan 22, 2015
Messages
18
Reaction score
0
Hi guys, i run 0.4, 3337, 8.6, and i really need this npc to work,
I want npc to sell items for another item in trade window.

I use this script and get this error
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
 
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
          [2195] = {price = 15, price2 = 10}, -- [ITEMID TO SELL] = {Buy cost (0 = not buyable), sell cost (0 = not sellable)}
          [2493] = {price = 25, price2 = 0},
          [2361] = {price = 30, price2 = 0},
          [8851] = {price = 20, price2 = 0},
          [8925] = {price = 30, price2 = 0},
          [2640] = {price = 50, price2 = 0},
          [2494] = {price = 100, price2 = 0},
          [9932] = {price = 50, price2 = 0},
          [2472] = {price = 70, price2 = 0},
          [8931] = {price = 100, price2 = 0}
          }
local TradeItem = 6527
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    if getPlayerItemCount(cid, TradeItem) < t[item].price*amount then
        selfSay("You don't have enough christmas token.", cid)
    else
        doPlayerAddItem(cid, item, amount)
        doPlayerRemoveItem(cid, TradeItem, t[item].price*amount)
        doPlayerSendTextMessage(cid, 20, "You have bought " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " christmas token.")
    end
    return true
end
local onSell = function(cid, item, subType, amount)
    doPlayerRemoveItem(cid, item, amount)
    doPlayerAddItem(cid, TradeItem, t[item].price2*amount)
    doPlayerSendTextMessage(cid, 20, "You have sold " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " christmas token.")
    --selfSay("Here your are!", cid)
    return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
    for var, ret in pairs(t) do
        table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = ret.price2, name = getItemName(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell) end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

This is the error when i say trade to npc.
Lua:
[12:10:39.451] [Error - NpcScript Interface]
[12:10:39.454] data/npc/scripts/seller.lua:onCreatureSay
[12:10:39.457] Description:
[12:10:39.458] (LuaInterface::luaGetThing) Thing not found

[12:10:39.460] [Error - NpcScript Interface]
[12:10:39.463] data/npc/scripts/seller.lua:onCreatureSay
[12:10:39.466] Description:
[12:10:39.468] data/lib/050-function.lua:300: attempt to index a boolean value
[12:10:39.472] stack traceback:
[12:10:39.473] data/lib/050-function.lua:300: in function 'getItemName'
[12:10:39.477] data/npc/scripts/seller.lua:48: in function 'callback'
[12:10:39.480] data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
[12:10:39.483] data/npc/scripts/seller.lua:7: in function

I really need this to work, What seems to be the problem? anyone able to help
 
Solution
All you have to do is changing getItemName to getItemNameById
Use this one I have edited it and should work.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
 
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow =...
All you have to do is changing getItemName to getItemNameById
Use this one I have edited it and should work.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
 
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
          [2195] = {price = 15, price2 = 10}, -- [ITEMID TO SELL] = {Buy cost (0 = not buyable), sell cost (0 = not sellable)}
          [2493] = {price = 25, price2 = 0},
          [2361] = {price = 30, price2 = 0},
          [8851] = {price = 20, price2 = 0},
          [8925] = {price = 30, price2 = 0},
          [2640] = {price = 50, price2 = 0},
          [2494] = {price = 100, price2 = 0},
          [9932] = {price = 50, price2 = 0},
          [2472] = {price = 70, price2 = 0},
          [8931] = {price = 100, price2 = 0}
          }
local TradeItem = 6527
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    if getPlayerItemCount(cid, TradeItem) < t[item].price*amount then
        selfSay("You don't have enough christmas token.", cid)
    else
        doPlayerAddItem(cid, item, amount)
        doPlayerRemoveItem(cid, TradeItem, t[item].price*amount)
        doPlayerSendTextMessage(cid, 20, "You have bought " .. amount .. "x " .. getItemNameById(item) .. " for " .. t[item].price*amount .. " christmas token.")
    end
    return true
end
local onSell = function(cid, item, subType, amount)
    doPlayerRemoveItem(cid, item, amount)
    doPlayerAddItem(cid, TradeItem, t[item].price2*amount)
    doPlayerSendTextMessage(cid, 20, "You have sold " .. amount .. "x " .. getItemNameById(item) .. " for " .. t[item].price*amount .. " christmas token.")
    --selfSay("Here your are!", cid)
    return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
    for var, ret in pairs(t) do
        table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = ret.price2, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell) end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Back
Top