Hey Guys i have problem with my npc script, he works but not corecttly
if i say item1 he works but if i say item2 or item3 he give me item1 please help me
if i say item1 he works but if i say item2 or item3 he give me item1 please help me
Code:
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
if(msgcontains(msg, 'item1') or msgcontains(msg, 'item11')) then
selfSay('Test msg', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 11400) >= 5) then
if(doPlayerRemoveItem(cid, 11400, 5)) then
doPlayerAddItem(cid, 2157, 5)
selfSay('Here you are.', cid)
else
selfSay('Test msg', cid)
end
else
selfSay('Test msg', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
if(msgcontains(msg, 'item2') or msgcontains(msg, 'item22')) then
selfSay('Test msg2', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 11400) >= 5) then
if(doPlayerRemoveItem(cid, 11400, 5)) then
doPlayerAddItem(cid, 3954, 1)
selfSay('Here you are.', cid)
else
selfSay('Test msg2', cid)
end
else
selfSay('Test msg2', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
if(msgcontains(msg, 'item3') or msgcontains(msg, 'item33')) then
selfSay('Test msg3', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 11400) >= 5) then
if(doPlayerRemoveItem(cid, 11400, 5)) then
doPlayerAddItem(cid, 3954, 1)
selfSay('Here you are.', cid)
else
selfSay('Test msg3', cid)
end
else
selfSay('Test msg3', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Last edited by a moderator: