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 say(param)
npcHandler:say(param.text,param.cid)
end
function delayedSay(text, delay, cid)
if(not npcHandler:isFocused(cid)) then
return FALSE
else
local param = {cid = cid, text = text}
local delay = delay or 0
addEvent(say, delay, param)
end
end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local main_storage = 10005
local bosses_storage = 10006
local getStorage = getPlayerStorageValue(cid, main_storage)
local getStorages = getPlayerStorageValue(cid, bosses_storage)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local good_hunting = {"Happy hunting, old chap! Come back to me when you are through with your {task}.", "Good show, old chap! Speak to me again when you are done hunting."}
local good_job = {"That took some time, huh? Good hunting though. If you're up for another hunting mission just ask me for a {task}.", "If you're up for another hunting mission just ask me for a {task}."}
local tasks = {
[1] = {name = "aniol", storage = 9899, min_level = 8, max_level = 200,
first = "yes", first_rewards = {type = "money", reward = 0, count = 250000},
second = "yes", second_rewards = {type = "exp", reward = 0, count = 25000000},
third = "no", third_rewards = {type = 0, reward = , count = 0},
begin_storage_value = 1, finish_storage_value = 2, boss = "yes", before_kill_boss = 0, after_kill_boss = 0, talkstate = 1},
[2] = {name = "archaniol", storage = 9898, min_level = 10, max_level = 2000,
first = "yes", first_rewards = {type = "money", reward = 0, count = 450000},
second = "yes", second_rewards = {type = "exp", reward = 0, count = 5000000},
third = "no", third_rewards = {type = 0, reward = 0, count = 0},
begin_storage_value = 3, finish_storage_value = 4, boss = "no", before_kill_boss = 0, after_kill_boss = 0, talkstate = 2}
}
s = "All right, what would you like to hunt - "
for k, v in pairs(tasks) do
if (getPlayerLevel(cid) >= v.min_level and getPlayerLevel(cid) <= v.max_level) then
s = s.."{"..v.name..",} "
end
end
s = string.sub(s, 1, string.len(s) - 3).."."
if msgcontains(msg, "task") then
if getStorage <= 0 then
selfSay(s, cid)
talkState[talkUser] = 100
end
elseif msgcontains(msg, "cancel") then
if getStorage > 0 then
selfSay("Do you want cancel actual mission?", cid)
talkState[talkUser] = 101
else
selfSay("You don't have started any task!", cid)
return true
end
end
for i = 1, #tasks do
if msgcontains(msg, tasks[i].name) and talkState[talkUser] == 100 then
if (getPlayerLevel(cid) >= tasks[i].min_level and getPlayerLevel(cid) <= tasks[i].max_level) then
selfSay("Do you want hunt "..tasks[i].name.."?", cid)
talkState[talkUser] = tasks[i].talkstate
else
selfSay("You do not have enough level.", cid)
return true
end
elseif msgcontains(msg, "yes") and talkState[talkUser] == tasks[i].talkstate then
doPlayerSetStorageValue(cid, main_storage, tasks[i].begin_storage_value)
selfSay(good_hunting[math.random(1, #good_hunting)], cid)
doPlayerSetStorageValue(cid, tasks[i].storage, 0)
elseif msgcontains(msg, "task") then
if getStorage == tasks[i].finish_storage_value and getStorages < tasks[i].before_kill_boss then
if tasks[i].boss == "yes" then
selfSay("Good job, go kill boss.", cid)
doPlayerSetStorageValue(cid, bosses_storage, tasks[i].before_kill_boss)
else
doPlayerSetStorageValue(cid, bosses_storage, -1)
doPlayerSetStorageValue(cid, main_storage, -1)
doPlayerSetStorageValue(cid, tasks[i].storage, -1)
selfSay(good_job[math.random(1, #good_job)], cid)
if tasks[i].first == "yes" then
if tasks[i].first_rewards.type == "item" then
doPlayerAddItem(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count, true)
elseif tasks[i].first_rewards.type == "exp" then
doPlayerAddExperience(cid, tasks[i].first_rewards.count)
doSendAnimatedText(getPlayerPosition(cid), tasks[i].first_rewards.count, TEXTCOLOR_WHITE)
elseif tasks[i].first_rewards.type == "storage" then
doPlayerSetStorageValue(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count)
elseif tasks[i].first_rewards.type == "money" then
doPlayerAddMoney(cid, tasks[i].first_rewards.count)
elseif tasks[i].first_rewards.type == "skill" then
doPlayerAddSkill(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count)
elseif tasks[i].first_rewards.type == "addon" then
doPlayerAddOutfit(cid, tasks[i].first_rewards.reward[1], tasks[i].first_rewards.count)
doPlayerAddOutfit(cid, tasks[i].first_rewards.reward[2], tasks[i].first_rewards.count)
end
end
if tasks[i].second == "yes" then
if tasks[i].second_rewards.type == "item" then
doPlayerAddItem(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count, true)
elseif tasks[i].second_rewards.type == "exp" then
doPlayerAddExperience(cid, tasks[i].second_rewards.count)
doSendAnimatedText(getPlayerPosition(cid), tasks[i].second_rewards.count, TEXTCOLOR_WHITE)
elseif tasks[i].second_rewards.type == "storage" then
doPlayerSetStorageValue(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count)
elseif tasks[i].second_rewards.type == "money" then
doPlayerAddMoney(cid, tasks[i].second_rewards.count)
elseif tasks[i].second_rewards.type == "skill" then
doPlayerAddSkill(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count)
elseif tasks[i].second_rewards.type == "addon" then
doPlayerAddOutfit(cid, tasks[i].second_rewards.reward[1], tasks[i].second_rewards.count)
doPlayerAddOutfit(cid, tasks[i].second_rewards.reward[2], tasks[i].second_rewards.count)
end
end
if tasks[i].third == "yes" then
if tasks[i].third_rewards.type == "item" then
doPlayerAddItem(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count, true)
elseif tasks[i].third_rewards.type == "exp" then
doPlayerAddExperience(cid, tasks[i].third_rewards.count)
doSendAnimatedText(getPlayerPosition(cid), tasks[i].third_rewards.count, TEXTCOLOR_WHITE)
elseif tasks[i].third_rewards.type == "storage" then
doPlayerSetStorageValue(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count)
elseif tasks[i].third_rewards.type == "money" then
doPlayerAddMoney(cid, tasks[i].third_rewards.count)
elseif tasks[i].third_rewards.type == "skill" then
doPlayerAddSkill(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count)
elseif tasks[i].third_rewards.type == "addon" then
doPlayerAddOutfit(cid, tasks[i].third_rewards.reward[1], tasks[i].third_rewards.count)
doPlayerAddOutfit(cid, tasks[i].third_rewards.reward[2], tasks[i].third_rewards.count)
end
end
end
elseif getStorages == tasks[i].after_kill_boss then
doPlayerSetStorageValue(cid, bosses_storage, -1)
doPlayerSetStorageValue(cid, main_storage, -1)
doPlayerSetStorageValue(cid, tasks[i].storage, -1)
selfSay(good_job[math.random(1, #good_job)], cid)
if tasks[i].first == "yes" then
if tasks[i].first_rewards.type == "item" then
doPlayerAddItem(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count, true)
elseif tasks[i].first_rewards.type == "exp" then
doPlayerAddExperience(cid, tasks[i].first_rewards.count)
doSendAnimatedText(getPlayerPosition(cid), tasks[i].first_rewards.count, TEXTCOLOR_WHITE)
elseif tasks[i].first_rewards.type == "storage" then
doPlayerSetStorageValue(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count)
elseif tasks[i].first_rewards.type == "money" then
doPlayerAddMoney(cid, tasks[i].first_rewards.count)
elseif tasks[i].first_rewards.type == "skill" then
doPlayerAddSkill(cid, tasks[i].first_rewards.reward, tasks[i].first_rewards.count)
elseif tasks[i].first_rewards.type == "addon" then
doPlayerAddOutfit(cid, tasks[i].first_rewards.reward[1], tasks[i].first_rewards.count)
doPlayerAddOutfit(cid, tasks[i].first_rewards.reward[2], tasks[i].first_rewards.count)
end
end
if tasks[i].second == "yes" then
if tasks[i].second_rewards.type == "item" then
doPlayerAddItem(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count, true)
elseif tasks[i].second_rewards.type == "exp" then
doPlayerAddExperience(cid, tasks[i].second_rewards.count)
doSendAnimatedText(getPlayerPosition(cid), tasks[i].second_rewards.count, TEXTCOLOR_WHITE)
elseif tasks[i].second_rewards.type == "storage" then
doPlayerSetStorageValue(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count)
elseif tasks[i].second_rewards.type == "money" then
doPlayerAddMoney(cid, tasks[i].second_rewards.count)
elseif tasks[i].second_rewards.type == "skill" then
doPlayerAddSkill(cid, tasks[i].second_rewards.reward, tasks[i].second_rewards.count)
elseif tasks[i].second_rewards.type == "addon" then
doPlayerAddOutfit(cid, tasks[i].second_rewards.reward[1], tasks[i].second_rewards.count)
doPlayerAddOutfit(cid, tasks[i].second_rewards.reward[2], tasks[i].second_rewards.count)
end
end
if tasks[i].third == "yes" then
if tasks[i].third_rewards.type == "item" then
doPlayerAddItem(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count, true)
elseif tasks[i].third_rewards.type == "exp" then
doPlayerAddExperience(cid, tasks[i].third_rewards.count)
doSendAnimatedText(getPlayerPosition(cid), tasks[i].third_rewards.count, TEXTCOLOR_WHITE)
elseif tasks[i].third_rewards.type == "storage" then
doPlayerSetStorageValue(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count)
elseif tasks[i].third_rewards.type == "money" then
doPlayerAddMoney(cid, tasks[i].third_rewards.count)
elseif tasks[i].third_rewards.type == "skill" then
doPlayerAddSkill(cid, tasks[i].third_rewards.reward, tasks[i].third_rewards.count)
elseif tasks[i].third_rewards.type == "addon" then
doPlayerAddOutfit(cid, tasks[i].third_rewards.reward[1], tasks[i].third_rewards.count)
doPlayerAddOutfit(cid, tasks[i].third_rewards.reward[2], tasks[i].third_rewards.count)
end
end
elseif getStorage == tasks[i].begin_storage_value then
selfSay("You have kill "..getPlayerStorageValue(cid, tasks[i].storage).." "..tasks[i].name..".", cid)
elseif getStorages == tasks[i].before_kill_boss then
selfSay("You do not kill boss yet.", cid)
return true
end
elseif msgcontains(msg, "yes") and talkState[talkUser] == 101 then
if getStorage > 0 then
selfSay("Speak to me again when you are done hunting.", cid)
doPlayerSetStorageValue(cid, main_storage, -1)
doPlayerSetStorageValue(cid, tasks[i].storage, -1)
return true
end
elseif msgcontains(msg, "no") and isInArray({i, 100, 101}, talkState[talkUser]) then
selfSay("Ok then.", cid)
return true
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())