Darqneez
ShaC-Ohhhh
Hi, I did today a simple script for npc. It should work so: Player says "quest", NPC asks Player, if he wants to do quest. Then let's say Player says "yes", but later when Player says "quest" he didnt get the message 'Did you bring me 10 orc teeth?', but the first one ('Do you want to do a quest for me?'). I dont really know where is bug, I can only guess it, and it can be that lines which contains this
something's wrong there, I'll rep someone who tells me where did I make mistake, here's whole code:
Lua:
talkState[talkUser] = [number]
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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
local talkState = {}
function creatureSayCallback(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if(not npcHandler:isFocused(cid)) then
return false
end
if getPlayerStorageValue(cid,59990) == -1 then
if msgcontains(msg, 'quest') then
selfSay('Do you want to do a quest for me?', cid)
talkState[talkUser] = 1
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
selfSay('Very good, we, green dragons, hate orcs. They understimate our power, bring me 10 orc teeth and I will reward You.', cid)
talkState[talkUser] = 2
elseif msgcontains(msg, 'no') then
selfSay('Then go away!', cid)
talkState[talkUser] = 0
elseif msgcontains(msg, 'quest') and talkState[talkUser] == 2 then
selfSay('Did you bring me 10 orc teeth?', cid)
talkState[talkUser] = 3
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 3 then
if getPlayerItemCount(cid, 11109) >= 10 then
doPlayerRemoveItem(cid, 11109, 10)
doPlayerAddItem(cid, 2152, 50)
setPlayerStorageValue(cid, 59990, 1)
if getPlayerStorageValue(cid,59999) == -1 then
setPlayerStorageValue(cid, 59999, 1)
else
setPlayerStorageValue(cid,59999,(getPlayerStorageValue(cid,59999))+1)
end
selfSay('Great job, Here you are, 5000 gold pieces. I will inform Eulopem about your loyalty towards green dragons.', cid)
talkState[talkUser] = 0
else
selfSay('Don\'t lie to me!', cid)
talkState[talkUser] = 2
end
end
else
selfSay('I don\'t have more quests for You.', cid)
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())