local STORAGE = 18008
local TALKSTATE_PICK = 1
local TALKSTATE_RESET = 2
local TALKSTATE_COMPLETE = 3
local TASKSTATE_COMPLETED = 1
local TASKSTATE_BOSS = 2
local TASKSTATE_FINALIZED = 3
local tasks = {
['minotaurs'] = {storage = 18009, kills = 5000, experience = 0, once = false, items = {}},
['pirates'] = {storage = 18010, kills = 3000, experience = 10000, once = false, items = {{2152, 50}}},
['sea serpents'] = {storage = 18011, kills = 2000, experience = 0, once = false, items = {}},
['serpent spawns'] = {storage = 18012, kills = 1500, experience = 0, once = false, items = {}},
['demons'] = {storage = 18013, kills = 6666, experience = 2000000, once = true, items = {}},
['behemoths'] = {storage = 18014, kills = 2000, experience = 0, once = false, items = {}},
['hydras'] = {storage = 18015, kills = 2000, experience = 0, once = false, items = {}},
['dragons'] = {storage = 18016, kills = 10000, experience = 1000000, once = false, items = {}},
['necromancers'] = {storage = 18017, kills = 4000, experience = 400000, once = false, items = {}},
['giant spiders'] = {storage = 18018, kills = 5000, experience = 50000, once = false, items = {}},
['juggernaut'] = {storage = 18019, kills = 500, experience = 5000000, once = true, items = {}},
['hands'] = {storage = 18020, kills = 500, experience = 500000, once = true, items = {}},
['dark torturers'] = {storage = 18021, kills = 2000, experience = 500000, once = ftrue, items = {}},
['phantasms'] = {storage = 18022, kills = 2000, experience = 500000, once = true, items = {}},
['warlocks'] = {storage = 18023, kills = 2000, experience = 500000, once = false, items = {}},
['grim reapers'] = {storage = 18024, kills = 2000, experience = 500000, once = false, items = {}}
}
function listTasks()
local output, list = '', {}
for k, v in ipairs(tasks) do
table.insert(list, k)
end
for k, v in ipairs(list) do
if k == 1 then
output = '{'.. v .. '}'
elseif k == #list then
output = output .. ' and {'.. v ..'}'
else
output = output ..', {'.. v ..'}'
end
end
return output
end
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState, turned = {}
function onCreatureAppear(cid)
npcHandler:onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
npcHandler:onCreatureDisappear(cid)
if talkState[cid] then
talkState[cid] = nil
end
end
function onCreatureSay(cid, type, msg)
npcHandler:onCreatureSay(cid, type, msg)
end
function onThink()
if not turned then
selfTurn(SOUTH)
turned = true
end
npcHandler:onThink()
end
local shop = ShopModule:new()
npcHandler:addModule(shop)
shop:addBuyableItem({'demon backpack'}, 10518, 1000, 1, 'Demon Backpack')
shop:addSellableItem({'hydra head'}, 11199, 600, 'Hydra Head')
shop:addSellableItem({'cyclops trophy'}, 7398, 500, 'Cyclops Trophy')
shop:addSellableItem({'minotaur trophy'}, 7401, 500, 'Minotaur Trophy')
shop:addSellableItem({'deer trophy'}, 7397, 1000, 'Deer Trophy')
shop:addSellableItem({'lion trophy'}, 7400, 1000, 'Lion Trophy')
shop:addSellableItem({'wolf trophy'}, 7394, 1000, 'Wolf Trophy')
shop:addSellableItem({'behemoth trophy'}, 7396, 20000, 'Behemoth Trophy')
shop:addSellableItem({'demon trophy'}, 7393, 40000, 'Demon Trophy')
shop:addSellableItem({'dragon lord trophy'}, 7399, 10000, 'Dragon Lord Trophy')
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
if msgcontains(msg, 'task') then
if getCreatureStorage(cid, STORAGE) == EMPTY_STORAGE then
local list = listTasks()
selfSay('You can start one of the following tasks: {Minotaurs}, {Pirates}, {Sea Serpents}, {Serpent Spawns}, {Demons}, {Behemoths}, {Hydras}, {Dragons}, {Necromancers}, {Giant Spiders}, {Warlocks} and {Grim Reapers}.', cid)
selfSay('You can also make these: {Juggernauts}, {Hands}, {Dark Torturers} and {Phantasms}. But you can make them only once.', cid)
selfSay('To start a task, simply type one of highlighted keywords, and remember - you can\'t start more than one task at same time.', cid)
talkState[cid] = TALKSTATE_PICK
else
selfSay('You are currently assigned a task. Would you like to dismiss your current task and begin another one?', cid)
talkState[cid] = TALKSTATE_RESET
end
elseif talkState[cid] == TALKSTATE_RESET then
if msgcontains(msg, 'yes') then
doCreatureSetStorage(cid, STORAGE, EMPTY_STORAGE)
for _, v in ipairs(tasks) do
doCreatureSetStorage(cid, v.storage, EMPTY_STORAGE)
end
selfSay('Your current task has been restarted, now you can choose another one, please say {task} to see list of available tasks.', cid)
else
selfSay('No then...', cid)
end
talkState[cid] = nil
elseif talkState[cid] == TALKSTATE_PICK then
local task = tasks[msg:lower()]
if task then
if getCreatureStorage(cid, task.storage) == task.kills + TASKSTATE_FINALIZED then
selfSay('This task has been already finalized and you can\'t pick it anymore.', cid)
else
doCreatureSetStorage(cid, STORAGE, 1)
doCreatureSetStorage(cid, task.storage, 0)
selfSay('You just started the {'.. msg:lower():gsub('%a', string.upper, 1) ..'} task. You have to kill '.. task.kills ..' of '.. msg:lower() ..'. Come back and ask about {complete} when you are done.', cid)
end
else
selfSay('It does seem like you don\'t understand me, I told you to pick task from list.', cid)
end
talkState[cid] = nil
elseif msgcontains(msg, 'complete') then
if getCreatureStorage(cid, STORAGE) == EMPTY_STORAGE then
selfSay('You aren\'t doing any task at the moment, if you would like to start one - type {task}.', cid)
else
selfSay(' I forgot, which task did you just complete?', cid)
talkState[cid] = TALKSTATE_COMPLETE
end
elseif talkState[cid] == TALKSTATE_COMPLETE then
local task = tasks[msg:lower()]
if task then
local kills = getCreatureStorage(cid, task.storage)
if kills <= task.kills then
selfSay('You have to kill '.. task.kills ..' '.. msg:lower() ..' in order to complete the {'.. msg:lower() ..'} task, you have killed '.. kills ..' '.. msg:lower():gsub('%a', string.upper, 1) ..'.', cid)
elseif kills == task.kills + TASKSTATE_COMPLETED then
local msg = 'Congratulations! You have completed the {'.. msg:lower():gsub('%a', string.upper, 1) ..'} task. You receive {access to magic forcefield}'
if task.experience > 0 then
doPlayerAddExperience(cid, task.experience)
msg = msg .. ' and {'.. task.experience ..' experience points}'
end
if #task.items > 0 then
msg = msg ..' and following items'
for k, v in ipairs(task.items) do
doPlayerAddItem(cid, v[1], v[2])
if k == 1 then
msg = msg ..' {'.. getItemInfo(v[1]).name ..'}'
else
msg = msg ..', {'.. getItemInfo(v[1]).name ..'}'
end
end
end
msg = msg ..' as a reward!'
doCreatureSetStorage(cid, task.storage, task.kills + TASKSTATE_BOSS)
doSendMagicEffect(getThingPosition(cid), CONST_ME_GIFT_WRAPS)
selfSay(msg, cid)
talkState[cid] = nil
if not __achv.check(cid, 8) then
__achv.set(cid, 8, 1)
end
elseif kills == task.kills + TASKSTATE_BOSS then
selfSay('You have already reported in about that task and received access to magic forcefield, go and kill boss.', cid)
elseif kills == task.kills + TASKSTATE_FINALIZED then
selfSay('This task has been already finalized and you can\'t pick it anymore.', cid)
end
else
selfSay('There\'s no task named {'.. msg:lower() ..'}, please remind yourself what task you have started before or type {task} to see list of available tasks.', cid)
end
talkState[cid] = nil
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, 'Hello, |PLAYERNAME|! I need someone to fufill a special {task} for me. If you have completed a task, please say {complete}, then the name of the task.')
npcHandler:addModule(FocusModule:new())