hi guys
I'm trying to configure my npc djin to open the trade shop, but I can't. it pops me an error message on tfs
i used tfs 0.4

I'm trying to configure my npc djin to open the trade shop, but I can't. it pops me an error message on tfs
i used tfs 0.4

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
local storage = 100057
local storage2 = 100032
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 greetCallback(cid)
Topic[cid] = 0
return true
end
function creatureSayCallback(cid, type, msg)
local p = getCreatureName(cid)
local v = getPlayerStorageValue(cid, storage)
if npcHandler:isFocused(cid) then
if msgcontains(msg, 'no') and Topic[cid] == 2 then
npcHandler:say("Dont disturb me then.",cid)
Topic[cid] = 1
elseif msgcontains(msg, 'no') and Topic[cid] >= 4 then
npcHandler:say("Dont disturb me then.",cid)
Topic[cid] = 3
end
end
if (msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) and getPlayerStorageValue(cid, storage) == -1 then
if getPlayerStorageValue(cid, 100054) == 2 and getPlayerStorageValue(cid, 9030) == 1 then
npcHandler:say("What do you want from me, "..p.."?", cid)
npcHandler:addFocus(cid)
Topic[cid] = 1
end
elseif Topic[cid] == 1 then
if msgcontains(msg, 'mission') and getPlayerStorageValue(cid, storage) == -1 then
npcHandler:say("So Baa'leal thinks you are up to do a mission for us? ...",cid)
npcHandler:say("I think he is getting old, entrusting human scum such as you are with an important mission like that. ...",cid, 1000)
npcHandler:say("I don't understand why you haven't been slaughtered right at the gates. ...",cid, 2500)
npcHandler:say("Are you prepared to embark on a dangerous mission for us?",cid, 3500)
Topic[cid] = 2
end
elseif Topic[cid] == 2 then
if msgcontains(msg, 'yes') and getPlayerStorageValue(cid, storage) == -1 then
npcHandler:say("All right then, human. Have you ever heard of the {Tears of Daraman}? ...",cid)
npcHandler:say("They are precious gemstones made of some unknown blue mineral and possess enormous magical power. ...",cid, 1000)
npcHandler:say("If you want to learn more about these gemstones don't forget to visit our library. ...",cid, 2000)
npcHandler:say("Anyway, one of them is enough to create thousands of our mighty djinn blades. ...",cid, 3000)
npcHandler:say("Unfortunately my last gemstone broke and therefore I'm not able to create new blades anymore. ...",cid, 4000)
npcHandler:say("To my knowledge there is only one place where you can find these gemstones - I know for a fact that the Marid have at least one of them. ...",cid, 5000)
npcHandler:say("Well... to cut a long story short, your mission is to sneak into Ashta'daramai and to steal it. ...",cid, 6000)
npcHandler:say("Needless to say, the Marid won't be too eager to part with it. Try not to get killed until you have delivered the stone to me.",cid, 7000)
setPlayerStorageValue(cid, 100062, 6)
setPlayerStorageValue(cid,10160, 1)
end
Topic[cid] = 0
end
if (msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) and getPlayerStorageValue(cid, storage) == 1 then
if getPlayerStorageValue(cid, storage) == 1 and getPlayerStorageValue(cid, 9030) == 1 then
npcHandler:say("What do you want from me, "..p.."?", cid)
npcHandler:addFocus(cid)
Topic[cid] = 3
end
elseif Topic[cid] == 3 then
if msgcontains(msg, 'mission') then
npcHandler:say("Did you find the tear of Daraman?",cid)
Topic[cid] = 4
end
elseif Topic[cid] == 4 then
if msgcontains(msg, 'yes') and doPlayerTakeItem(cid, 2346, 1) then
npcHandler:say("So you have made it? You have really managed to steal a Tear of Daraman? ...",cid)
npcHandler:say("Amazing how you humans are just impossible to get rid of. Incidentally, you have this character trait in common with many insects and with other vermin. ...",cid, 1000)
npcHandler:say("Nevermind. I hate to say it, but it you have done us a favour, human. That gemstone will serve us well. ...",cid, 3000)
npcHandler:say("Baa'leal, wants you to talk to {Malor} concerning some {new mission.} ...",cid, 4500)
npcHandler:say("Looks like you have managed to extended your life expectancy - for just a bit longer.",cid, 5500)
setPlayerStorageValue(cid,storage, 1)
setPlayerStorageValue(cid, 100062, 8)
setPlayerStorageValue(cid,100159, 3)
else
npcHandler:say("You better don't return here until you've got the Tear.", cid)
end
Topic[cid] = 0
end
if msgcontains(msg, 'trade') and getPlayerStorageValue(cid, storage2) == -1 then
selfSay("Only players with {acess}!", cid)
else
openShopWindow(cid, trade, onBuy, onSell)
selfSay("vc tem acesso!", cid)
return true
end
if msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
npcHandler:say("Finally.",cid)
npcHandler:releaseFocus(cid)
npcHandler:resetNpc(cid)
Topic[cid] = 0
end
return true
end
local trade = {
{name="abyss hammer", id=7414, buy=0, sell=20000},
{name="wolf trophy", id=7394, buy=0, sell=3000}
}
local items = {}
for _, item in ipairs(trade) do
items[item.id] = {item_id = item.id, buyPrice = item.buy, sellPrice = item.sell, subType = 0, realName = item.name}
end
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if items[item].buyPrice ~= 0 then
doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
if isItemStackable(items[item].item_id) then
doPlayerAddItem(cid, items[item].item_id, amount)
else
for i = 1, amount do
doPlayerAddItem(cid, items[item].item_id, 1)
end
end
end
end
local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if items[item].sellPrice ~= 0 then
doPlayerAddMoney(cid, items[item].sellPrice * amount)
doPlayerRemoveItem(cid, items[item].item_id, amount)
end
end
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
npcHandler:setCallback(CALLBACK_ONTRADEREQUEST, onTradeRequest)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
local storage = 100057
local storage2 = 100032
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 greetCallback(cid)
Topic[cid] = 0
return true
end
function creatureSayCallback(cid, type, msg)
local p = getCreatureName(cid)
local v = getPlayerStorageValue(cid, storage)
if npcHandler:isFocused(cid) then
if msgcontains(msg, 'no') and Topic[cid] == 2 then
npcHandler:say("Dont disturb me then.",cid)
Topic[cid] = 1
elseif msgcontains(msg, 'no') and Topic[cid] >= 4 then
npcHandler:say("Dont disturb me then.",cid)
Topic[cid] = 3
end
end
if (msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) and getPlayerStorageValue(cid, storage) == -1 then
if getPlayerStorageValue(cid, 100054) == 2 and getPlayerStorageValue(cid, 9030) == 1 then
npcHandler:say("What do you want from me, "..p.."?", cid)
npcHandler:addFocus(cid)
Topic[cid] = 1
end
elseif Topic[cid] == 1 then
if msgcontains(msg, 'mission') and getPlayerStorageValue(cid, storage) == -1 then
npcHandler:say("So Baa'leal thinks you are up to do a mission for us? ...",cid)
npcHandler:say("I think he is getting old, entrusting human scum such as you are with an important mission like that. ...",cid, 1000)
npcHandler:say("I don't understand why you haven't been slaughtered right at the gates. ...",cid, 2500)
npcHandler:say("Are you prepared to embark on a dangerous mission for us?",cid, 3500)
Topic[cid] = 2
end
elseif Topic[cid] == 2 then
if msgcontains(msg, 'yes') and getPlayerStorageValue(cid, storage) == -1 then
npcHandler:say("All right then, human. Have you ever heard of the {Tears of Daraman}? ...",cid)
npcHandler:say("They are precious gemstones made of some unknown blue mineral and possess enormous magical power. ...",cid, 1000)
npcHandler:say("If you want to learn more about these gemstones don't forget to visit our library. ...",cid, 2000)
npcHandler:say("Anyway, one of them is enough to create thousands of our mighty djinn blades. ...",cid, 3000)
npcHandler:say("Unfortunately my last gemstone broke and therefore I'm not able to create new blades anymore. ...",cid, 4000)
npcHandler:say("To my knowledge there is only one place where you can find these gemstones - I know for a fact that the Marid have at least one of them. ...",cid, 5000)
npcHandler:say("Well... to cut a long story short, your mission is to sneak into Ashta'daramai and to steal it. ...",cid, 6000)
npcHandler:say("Needless to say, the Marid won't be too eager to part with it. Try not to get killed until you have delivered the stone to me.",cid, 7000)
setPlayerStorageValue(cid, 100062, 6)
setPlayerStorageValue(cid,10160, 1)
end
Topic[cid] = 0
end
if (msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) and getPlayerStorageValue(cid, storage) == 1 then
if getPlayerStorageValue(cid, storage) == 1 and getPlayerStorageValue(cid, 9030) == 1 then
npcHandler:say("What do you want from me, "..p.."?", cid)
npcHandler:addFocus(cid)
Topic[cid] = 3
end
elseif Topic[cid] == 3 then
if msgcontains(msg, 'mission') then
npcHandler:say("Did you find the tear of Daraman?",cid)
Topic[cid] = 4
end
elseif Topic[cid] == 4 then
if msgcontains(msg, 'yes') and doPlayerTakeItem(cid, 2346, 1) then
npcHandler:say("So you have made it? You have really managed to steal a Tear of Daraman? ...",cid)
npcHandler:say("Amazing how you humans are just impossible to get rid of. Incidentally, you have this character trait in common with many insects and with other vermin. ...",cid, 1000)
npcHandler:say("Nevermind. I hate to say it, but it you have done us a favour, human. That gemstone will serve us well. ...",cid, 3000)
npcHandler:say("Baa'leal, wants you to talk to {Malor} concerning some {new mission.} ...",cid, 4500)
npcHandler:say("Looks like you have managed to extended your life expectancy - for just a bit longer.",cid, 5500)
setPlayerStorageValue(cid,storage, 1)
setPlayerStorageValue(cid, 100062, 8)
setPlayerStorageValue(cid,100159, 3)
else
npcHandler:say("You better don't return here until you've got the Tear.", cid)
end
Topic[cid] = 0
end
if msgcontains(msg, 'trade') and getPlayerStorageValue(cid, storage2) == -1 then
selfSay("Only players with {acess}!", cid)
else
openShopWindow(cid, trade, onBuy, onSell)
selfSay("vc tem acesso!", cid)
return true
end
if msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
npcHandler:say("Finally.",cid)
npcHandler:releaseFocus(cid)
npcHandler:resetNpc(cid)
Topic[cid] = 0
end
return true
end
local trade = {
{name="abyss hammer", id=7414, buy=0, sell=20000},
{name="ancient amulet", id=2142, buy=0, sell=800},
{name="assassin dagger", id=7404, buy=0, sell=20000},
{name="beastslayer axe", id=3962, buy=0, sell=1500},
{name="bone shield", id=2541, buy=0, sell=80},
{name="beholder helmet", id=3972, buy=0, sell=7500},
{name="behemoth trophy", id=7396, buy=0, sell=20000},
{name="castle shield", id=2535, buy=0, sell=5000},
{name="chaos mace", id=7427, buy=0, sell=7000},
{name="crocodile boots", id=3982, buy=0, sell=1000},
{name="crystal mace", id=2445, buy=0, sell=12000},
{name="crystal necklace", id=2125, buy=0, sell=400},
{name="crystal ring", id=2124, buy=0, sell=250},
{name="crystal sword", id=7449, buy=0, sell=600},
{name="crystalline armor", id=8878, buy=0, sell=16000},
{name="cyclops trophy", id=7398, buy=0, sell=4000},
{name="daramanian mace", id=2439, buy=0, sell=110},
{name="daramanian waraxe", id=2440, buy=0, sell=1000},
{name="dark shield", id=2521, buy=0, sell=400},
{name="death ring", id=6301, buy=0, sell=1000},
{name="demon shield", id=2520, buy=0, sell=30000},
{name="demonbone amulet", id=2136, buy=0, sell=32000},
{name="demonrage sword", id=7382, buy=0, sell=36000},
{name="demon trophy", id=7393, buy=0, sell=50000},
{name="devil helmet", id=2462, buy=0, sell=1000},
{name="deer trophy", id=7397, buy=0, sell=3000},
{name="diamond sceptre", id=7387, buy=0, sell=3000},
{name="divine plate", id=8885, buy=0, sell=55000},
{name="doll", id=2110, buy=0, sell=200},
{name="dragon lord trophy", id=7399, buy=0, sell=15000},
{name="dragon scale mail", id=2492, buy=0, sell=40000},
{name="dragon slayer", id=7402, buy=0, sell=15000},
{name="dreaded cleaver", id=7419, buy=0, sell=10000},
{name="dwarven armor", id=2503, buy=0, sell=30000},
{name="emerald bangle", id=2127, buy=0, sell=800},
{name="glacier kilt", id=7896, buy=0, sell=11000},
{name="glacier mask", id=7902, buy=0, sell=2500},
{name="glacier robe", id=7897, buy=0, sell=11000},
{name="glacier shoes", id=7892, buy=0, sell=2500},
{name="gold ring", id=2179, buy=0, sell=8000},
{name="golden armor", id=2466, buy=0, sell=20000},
{name="golden legs", id=2470, buy=0, sell=70000},
{name="griffin shield", id=2533, buy=0, sell=3000},
{name="guardian halberd", id=2427, buy=0, sell=11000},
{name="hammer of wrath", id=2444, buy=0, sell=30000},
{name="heavy mace", id=2452, buy=0, sell=50000},
{name="heavy machete", id=2442, buy=0, sell=90},
{name="leopard armor", id=3968, buy=0, sell=1000},
{name="lightning boots", id=7893, buy=0, sell=2500},
{name="lightning headband", id=7901, buy=0, sell=2500},
{name="lightning legs", id=7895, buy=0, sell=11000},
{name="lightning robe", id=7898, buy=0, sell=11000},
{name="lion trophy", id=7400, buy=0, sell=4000},
{name="magic plate armor", id=2472, buy=0, sell=12000},
{name="magma boots", id=7891, buy=0, sell=2500},
{name="magma coat", id=7899, buy=0, sell=11000},
{name="magma legs", id=7894, buy=0, sell=11000},
{name="magma monocle", id=7900, buy=0, sell=2500},
{name="mastermind shield", id=2514, buy=0, sell=90000},
{name="medusa shield", id=2536, buy=0, sell=9000},
{name="mercenary sword", id=7386, buy=0, sell=12000},
{name="minotaur trophy", id=7401, buy=0, sell=4000},
{name="naginata", id=2426, buy=0, sell=2000},
{name="nightmare blade", id=7418, buy=0, sell=35000},
{name="noble axe", id=7456, buy=0, sell=10000},
{name="orc trophy", id=7395, buy=0, sell=4000},
{name="paladin armor", id=8891, buy=0, sell=15000},
{name="pharaoh sword", id=2446, buy=0, sell=23000},
{name="platinum amulet", id=2171, buy=0, sell=2500},
{name="relic sword", id=7383, buy=0, sell=25000},
{name="ring of the sky", id=2123, buy=0, sell=30000},
{name="ruby necklace", id=2133, buy=0, sell=2000},
{name="scarab amulet", id=2142, buy=0, sell=200},
{name="scarab shield", id=2540, buy=0, sell=2000},
{name="silver dagger", id=2402, buy=0, sell=500},
{name="skull helmet", id=5741, buy=0, sell=40000},
{name="skullcracker armor", id=8889, buy=0, sell=18000},
{name="spiked squelcher", id=7452, buy=0, sell=5000},
{name="steel boots", id=2645, buy=0, sell=30000},
{name="swamplair armor", id=8880, buy=0, sell=16000},
{name="taurus mace", id=7425, buy=0, sell=500},
{name="tempest shield", id=2542, buy=0, sell=35000},
{name="terra boots", id=7886, buy=0, sell=2500},
{name="terra hood", id=7903, buy=0, sell=2500},
{name="terra legs", id=7885, buy=0, sell=11000},
{name="terra mantle", id=7884, buy=0, sell=11000},
{name="vile axe", id=7388, buy=0, sell=30000},
{name="war axe", id=2454, buy=0, sell=12000},
{name="war horn", id=3957, buy=0, sell=8000},
{name="wolf trophy", id=7394, buy=0, sell=3000}
}
local items = {}
for _, item in ipairs(trade) do
items[item.id] = {item_id = item.id, buyPrice = item.buy, sellPrice = item.sell, subType = 0, realName = item.name}
end
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if items[item].buyPrice ~= 0 then
doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
if isItemStackable(items[item].item_id) then
doPlayerAddItem(cid, items[item].item_id, amount)
else
for i = 1, amount do
doPlayerAddItem(cid, items[item].item_id, 1)
end
end
end
end
local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if items[item].sellPrice ~= 0 then
doPlayerAddMoney(cid, items[item].sellPrice * amount)
doPlayerRemoveItem(cid, items[item].item_id, amount)
end
end
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
npcHandler:setCallback(CALLBACK_ONTRADEREQUEST, onTradeRequest)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)