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

[8.6] Bug with NPC

pansuchar

Member
Joined
Dec 29, 2008
Messages
68
Reaction score
5
Hi all. I have mission npc :

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() 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, 'quest')) then
selfSay('You can start from the {first mission}.', cid)
end
---------------------------------------------------------
if(msgcontains(msg, 'first mission')) then
if (getPlayerStorageValue(cid,210) > 0) then
selfSay('You have already done this mission.', cid)
elseif (getPlayerStorageValue(cid,210) < 0) then
selfSay('First mission is {xxx}.', cid)
talkState[talkUser] = 1
setPlayerStorageValue(cid,190,1)
elseif(msgcontains(msg, 'xxx') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,200) > 0) then
setPlayerStorageValue(cid,210,1)
selfSay('Okay, you can start {second mission}', cid)
else
selfSay('You must perform the task.', cid)
end
end
return true
end
---------------------------------------------------------
if(msgcontains(msg, 'second mission')) then
if (getPlayerStorageValue(cid,211) > 0) then
selfSay('You have already done this mission.', cid)
elseif (getPlayerStorageValue(cid,210) < 0) then
selfSay('Complete previous mission.', cid)
elseif (getPlayerStorageValue(cid,211) < 0) then
selfSay('Second mission is {yyy}.', cid)
setPlayerStorageValue(cid,191,1)
talkState[talkUser] = 1
if(msgcontains(msg, 'yyy') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,201) > 0) then
setPlayerStorageValue(cid,211,1)
selfSay('Very good!.', cid)
else
selfSay('You must perform the task.', cid)
end
end
end
return true
end
---------------------------------------------------------
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

The conversation ends when I tell him about the executed task, when I say xxx NPC does not respond, no errors appear in the console.
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, 'quest')) then
         selfSay('You can start from the {first mission}.', cid)
     end
   ---------------------------------------------------------
     if msgcontains(msg, 'first mission') then
         if getPlayerStorageValue(cid,210) > 0 then
             selfSay('You have already done this mission.', cid)
         elseif getPlayerStorageValue(cid,210) < 0 then
             selfSay('First mission is {xxx}.', cid)
             talkState[talkUser] = 1
             setPlayerStorageValue(cid,190,1)
         end
     elseif(msgcontains(msg, 'xxx') and talkState[talkUser] == 1) then
         if getPlayerStorageValue(cid,200) > 0 then
             setPlayerStorageValue(cid,210,1)
             selfSay('Okay, you can start {second mission}', cid)
         else
             selfSay('You must perform the task.', cid)
         end
         talkState[talkUser] = 0
     end
     ---------------------------------------------------------
     if msgcontains(msg, 'second mission') then
         if getPlayerStorageValue(cid,211) > 0 then
             selfSay('You have already done this mission.', cid)
         elseif getPlayerStorageValue(cid,210) < 0 then
             selfSay('Complete previous mission.', cid)
         elseif getPlayerStorageValue(cid,211) < 0 then
             selfSay('Second mission is {yyy}.', cid)
             setPlayerStorageValue(cid,191,1)
             talkState[talkUser] = 2
         end
     elseif msgcontains(msg, 'yyy') and talkState[talkUser] == 2 then
         if getPlayerStorageValue(cid,201) > 0 then
             setPlayerStorageValue(cid,211,1)
             selfSay('Very good!.', cid)
         else
             selfSay('You must perform the task.', cid)
         end
         talkState[talkUser] = 0
     end
     ---------------------------------------------------------
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Instead of letting it respond on different words, you can also let it respond different on the same word by using storage and/or talkstate and let the npc give the second mission automaticly after finishing the first one, without saying second mission first.
 
Back
Top