Well, I'm making this Shop NPC, but I'm having some problems.
When I say "Item1"
The NPC says "So do you want to buy item1's... how many?"
Then I say 50, and here is the bug the NPC answers:
"Do you really wan't to buy 50 item1
Do you really wan't to buy 50 item2"
Twice cause he gets "i" twice so I wan't he to just answer with the "i" I said first.
I hope I explained it well.
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 onPlayerEndTrade(cid) npcHandler:onPlayerEndTrade(cid) end
function onPlayerCloseChannel(cid) npcHandler:onPlayerCloseChannel(cid) end
local function getCount(s)
local b, e = s:find('%d+')
return b and e and math.min(4294967295, tonumber(s:sub(b, e))) or -1
end
local items = {
["item1"] = {price = 5, cash = 500},
["item2"] = {price = 10, cash = 1000}
}
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if(msgcontains(msg, 'hi') or msgcontains(msg, 'hello')) then
selfSay('Hi, May I help you?', cid)
elseif(msgcontains(msg, 'offer')) or msgcontains(msg, 'trade') then
selfSay('I sell a lot of items.', cid)
end
for i, v in pairs(items) do
if(msgcontains(msg, i)) then
selfSay('So do you want to buy '..i..'\'s... how many? ', cid)
talkState = 2
elseif(msgcontains(msg,getCount(msg))) and talkState == 2 then
talkState = 2
selfSay('Do you really wan\'t to buy '..getCount(msg)..' '..i..'', cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
When I say "Item1"
The NPC says "So do you want to buy item1's... how many?"
Then I say 50, and here is the bug the NPC answers:
"Do you really wan't to buy 50 item1
Do you really wan't to buy 50 item2"
Twice cause he gets "i" twice so I wan't he to just answer with the "i" I said first.
I hope I explained it well.