--NPC3
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
local c = {
items = {
{id = 2324, count = 10},
{id = 2654, count = 10}
},
monster = {storage = 19801, amount = 50}
}
local storage = 6800
function creatureSayCallback(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if(not npcHandler:isFocused(cid)) then
if(msg == 'hi' or msg == 'hello') then
if(getPlayerStorageValue(cid, storage) < 4) then
selfSay('I have no business with you.', cid)
return false
elseif(getPlayerStorageValue(cid, storage) == 4) then
selfSay('Hello '..getPlayerName(cid)..', I need your {help}.', cid)
talkState[talkUser] = 1
elseif(getPlayerStorageValue(cid, storage) == 5) then
selfSay('Have you finished what I asked?', cid)
talkState[talkUser] = 2
else
selfSay('Thanks again for items and killing the monsters.', cid)
end
npcHandler:addFocus(cid)
else
return false
end
end
if(msgcontains(msg, 'help') and talkState[talkUser] == 1) then
selfSay('I need you to kill 50 Witches and collect 10 brooms and 10 capes from them. Are you up for it?', cid)
talkState[talkUser] = 2
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
if(getPlayerStorageValue(cid, storage) == 4) then
selfSay('Make haste.', cid)
setPlayerStorageValue(cid, storage, 5)
else
amount = 0
for i = 1, #c.items do
if(getPlayerItemCount(cid, c.items[i].id) >= c.items[i].count) then
amount = amount + 1
end
end
if(getPlayerStorageValue(cid, 19801) == 50 and amount == #c.items) then
for i = 1, #c.items do
doPlayerRemoveItem(cid, c.items[i].id, c.items[i].count)
end
selfSay('Good job, maybe NPC4 has some word for you now.', cid)
doPlayerAddExp(cid, 5000) -- reward?
setPlayerStorageValue(cid, storage, 6)
else
local n = 0
for i = 1, #c.items do
if getPlayerItemCount(cid, c.items[i].id) < c.items[i].count then
n = n + 1
end
end
local text = ""
local a = 0
for v = 1, #c.items do
count, info = c.items[v].count - getPlayerItemCount(cid, c.items[v].id), getItemInfo(c.items[v].id)
if(getPlayerItemCount(cid, c.items[v].id) < c.items[v].count) then
a = a + 1
local ret = ", "
if a == 1 then
ret = ""
elseif a == n then
ret = " and "
end
text = text .. ret
text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
end
end
if(text ~= "") then
text = ' '..text..''
end
local count = c.monster.amount - (getPlayerStorageValue(cid, c.monster.storage)+1)
local mtext = ''
if(c.monster.amount > (getPlayerStorageValue(cid, c.monster.storage)+1)) then
mtext = ' '..count..' '..(count > 1 and 'Witches' or 'Witch')..''..(a == 1 and ' and' or (a == 0 and '' or ','))..''
end
selfSay('You didn\'t finish what I asked. You still have'..mtext..''..text..' left.', cid)
end
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
selfSay('Ok then.', cid)
talkState[talkUser] = 0
elseif(msgcontains(msg, 'bye')) then
selfSay('Bye.', cid)
npcHandler:releaseFocus(cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)