Well, this script work like:
me: Hi
NPC: i have some items to sell. Say trade to see my offer.
me: trade
NPC: [show the list of items]
me: [I say one name of the list]
NPC: Here are. [Remove the necessery items and give me the item I said]
But I'm trying to put an confirmation, like:
me: Hi
NPC: i have some items to sell. Say trade to see my offer.
me: trade
NPC: [show the list of items]
me: [I say one name of the list]
NPC: Do you want to buy ..item name.. for ..amount of necessary coins.. ?
me: yes
NPC: Here are. [Remove the necessery items and give me the item I said]
But I failed. When I say 'yes' to the NPC, return this error in console: ...lua:40: attempt to index filed '?' <a nill value> / ...lua:40: in function 'callback'
Here are the script:
Thanks in advance. (TFS 0.4)
me: Hi
NPC: i have some items to sell. Say trade to see my offer.
me: trade
NPC: [show the list of items]
me: [I say one name of the list]
NPC: Here are. [Remove the necessery items and give me the item I said]
But I'm trying to put an confirmation, like:
me: Hi
NPC: i have some items to sell. Say trade to see my offer.
me: trade
NPC: [show the list of items]
me: [I say one name of the list]
NPC: Do you want to buy ..item name.. for ..amount of necessary coins.. ?
me: yes
NPC: Here are. [Remove the necessery items and give me the item I said]
But I failed. When I say 'yes' to the NPC, return this error in console: ...lua:40: attempt to index filed '?' <a nill value> / ...lua:40: in function 'callback'
Here are the script:
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,msg,str = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid,msg:lower(),""
local moeda = 2677
local t = {
["celestial armor"] = {amount = 30, item = {7957,1}},
["celestial legs"] = {amount = 20, item = {10552,1}},
["celestial boots"] = {amount = 20, item = {10553,1}},
["celestial helmet"] = {amount = 20, item = {10554,1}},
["3 days premium scroll"] = {amount =1, item = {9663,1}},
["15 days premium scroll"] = {amount = 5, item = {9664,1}},
["30 days premium scroll"] = {amount = 10, item = {9665,1}}
}
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
str = str .. "ou can change your tokens for: "
for name, ret in pairs(t) do
str = str.." {"..name.."}/"
end
npcHandler:say(str, cid)
talkState[talkUser] = 1
end
if t[msg] and talkState[talkUser] == 1 then
local it, am = t[msg].item[1], t[msg].amount
npcHandler:say("Do you want to buy".. getItemNameById(it) .." for "..am.." "..getItemNameById(moeda).."(s)?", cid)
talkState[talkUser] = 2
npcHandler:addFocus(cid)
end
if msgcontains(msg, "yes") and talkState[talkUser] == 2 then
local item, amount = t[msg].item[1], t[msg].item[2] --this line
if doPlayerRemoveItem(cid,moeda, t[msg].amount) then
if isItemStackable(item) or amount == 1 then
doPlayerAddItem(cid, item, amount)
else
for i = 1, amount do
doPlayerAddItem(cid, item, 1)
end
end
npcHandler:say("Here are "..amount.." ".. getItemNameById(item) .."!", cid)
else
npcHandler:say("You need "..t[msg].amount.." ".. getItemNameById(moeda).." to buy this item.", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thanks in advance. (TFS 0.4)