Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local keywordHandler = KeywordHandler:new()
- local npcHandler = NpcHandler:new(keywordHandler)
- NpcSystem.parseParameters(npcHandler)
- local choose, 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 getTaskGroupsByAddonName(taskName)
- local groups = AddonTasks.getGroups()
- for i,v in ipairs(groups) do
- if v:lower() == taskName then
- return v
- end
- end
- return false
- end
- function getTaskByName(taskName)
- local tasks = AddonTasks.getTasks()
- for k,v in pairs(tasks) do
- if k:lower() == taskName then
- return v
- end
- end
- return false
- end
- function creatureSayCallback(cid, type, msg)
- if(not npcHandler:isFocused(cid)) then
- return false
- end
- local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
- msg = msg:lower()
- if(msgcontains(msg, 'addons')) then
- local groups, string, separator = AddonTasks.getGroups(), "Here are the addons that I can help you do: ", ", "
- for i,v in ipairs(groups) do
- if(i == #groups - 1) then
- separator = " and "
- elseif(i == #groups) then
- separator = "."
- end
- string = string .. "{" .. v .. "}" .. separator
- end
- string = string .. " Which outfit would you like to have?"
- npcHandler:say(string, cid)
- elseif(getTaskGroupsByAddonName(msg)) then
- npcHandler:say("Which addon interest you? {first " .. msg .. "} addon or {second " .. msg .. "} addon?", cid)
- elseif(getTaskByName(msg)) then
- local tasks = AddonTasks.getTasks()
- for k,v in pairs(tasks) do
- if(getPlayerSpecialStorageValue(cid, v.storage) == 1) then
- npcHandler:say("I'm sorry but you're already in the middle of a different task. Type {started} to find out which one.", cid)
- return true
- end
- end
- local task = getTaskByName(msg)
- -- check if player already have this addon
- if(canPlayerWearOutfitId(cid, task.reward.outfitId, task.reward.addonId)) then
- npcHandler:say("You already have this addon. Please select another one from the list.", cid)
- return true
- end
- -- monsters
- local monsters_string = ""
- for i,v in ipairs(task.tasks.monsters) do
- monsters_string = monsters_string .. "{" .. v[2] .. "x " .. v[1] .. "}"
- if(#task.tasks.monsters > 1 and i ~= #task.tasks.monsters) then
- monsters_string = monsters_string .. ", "
- end
- end
- -- items
- local items_string = ""
- for i,v in ipairs(task.tasks.items) do
- items_string = items_string .. "{" .. v[2] .. "x " .. getItemNameById(v[1]) .. "}"
- if(#task.tasks.items > 1 and i ~= #task.tasks.items) then
- items_string = items_string .. ", "
- end
- end
- talkState[talkUser] = 1
- choose[cid] = task
- npcHandler:say("If you want to get this addon you will have to kill " .. monsters_string .. " and bring me these items: " .. items_string .. ". Do you accept the task?", cid)
- elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1 and choose[cid] ~= nil) then
- local task = choose[cid]
- setPlayerSpecialStorageValue(cid, task.storage, 1)
- choose[cid] = nil
- talkState[talkUser] = 0
- npcHandler:say("Excellent! Task has been activated. Please come back when you finish.", cid)
- elseif(msgcontains(msg, 'report')) then
- local finished_tasks, tasks = {}, AddonTasks.getTasks()
- for k,v in pairs(tasks) do
- if(getPlayerSpecialStorageValue(cid, v.storage) == 2) then
- table.insert(finished_tasks, v)
- end
- end
- if(#finished_tasks < 1) then
- npcHandler:say("You dont have any finished tasks.", cid)
- return true
- end
- local string = ""
- for k,v in pairs(finished_tasks) do
- local items = {}
- for k,v in pairs(v.tasks.items) do
- if(getPlayerItemCount(cid, v[1]) < v[2]) then
- table.insert(items, {v[1], v[2]})
- end
- end
- if(#items > 0) then
- local items_string = ""
- for i,v in ipairs(items) do
- items_string = items_string .. "{" .. v[2] .. "x " .. getItemNameById(v[1]) .. "}"
- if(#items > 1 and i ~= #items) then
- items_string = items_string .. ", "
- end
- end
- items_string = items_string .. ". Please come back when you'll have them."
- npcHandler:say("You miss these items: " .. items_string, cid)
- return true
- end
- if(v.tasks.vials) then
- if getPlayerSpecialStorageValue(cid, 6969) <= 5000 then
- npcHandler:say("You have not used yet 5000 vials.", cid)
- return false
- end
- end
- for k,v in pairs(v.tasks.items) do
- doPlayerRemoveItem(cid, v[1], v[2])
- end
- doPlayerAddOutfitId(cid, v.reward.outfitId, v.reward.addonId)
- setPlayerSpecialStorageValue(cid, v.storage, 3)
- end
- doSendMagicEffect(getPlayerPosition(cid), 12)
- doCreatureSay(cid, "TASK FINISHED!", TALKTYPE_ORANGE_1)
- npcHandler:say("Awesome! You finished " .. (#finished_tasks > 1 and 'various' or 'a') .. " task" .. (#finished_tasks > 1 and 's' or '') .. ". Talk to me again if you want to start a {addons}.", cid)
- elseif(msgcontains(msg, 'started')) then
- local tasks, groups = AddonTasks.getStartedTasks(cid), AddonTasks.getGroups()
- if(#tasks < 1) then
- npcHandler:say("You dont have any started tasks.", cid)
- return true
- end
- local string = "The current task that you started is "
- for i,v in ipairs(tasks) do
- string = string .. "{" .. groups[v.groupId] .. "}"
- if(#tasks > 1 and i ~= #tasks) then
- string = string .. ", "
- end
- end
- string = string .. "."
- npcHandler:say(string, cid)
- elseif(msgcontains(msg, 'cancel')) then
- local tasks, groups = AddonTasks.getStartedTasks(cid), AddonTasks.getGroups()
- if(#tasks < 1) then
- npcHandler:say("You dont have any started tasks.", cid)
- return true
- end
- local string = "Here are the tasks that were canceled: "
- for k,v in pairs(tasks) do
- if(getPlayerSpecialStorageValue(cid, v.storage) == 1) then
- string = string .. "{" .. groups[v.groupId] .. "}"
- if(#tasks > 1 and i ~= #tasks) then
- string = string .. ", "
- end
- setPlayerSpecialStorageValue(cid, v.storage, 0)
- end
- end
- string = string .. "."
- npcHandler:say(string, cid)
- elseif(msgcontains(msg, 'help')) then
- npcHandler:say("To buy the first addon say {first NAME} and for the second addon say {second NAME}.", cid)
- end
- return true
- end
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
- ---- lib
- local groups = {
- [1] = 'citizen', [2] = 'hunter', [3] = 'mage', [4] = 'knight', [5] = 'nobleman', [6] = 'summoner', [7] = 'warrior', [8] = 'barbarian', [9] = 'druid', [10] = 'wizard', [11] = 'oriental', [12] = 'pirate', [13] = 'assassin', [14] = 'beggar', [15] = 'shaman', [16] = 'norseman', [17] = 'nightmare', [18] = 'jester', [19] = 'brotherhood', [20] = 'demonhunter'
- }
- local tasks = {
- ["first citizen"] = {groupId = 1, storage = 28001, tasks = {monsters = {{"rotworm", 500}}, items = {{5878, 100}, {5890, 100}, {2160, 400}}}, reward = {outfitId = 1, addonId = 1}},
- ["second citizen"] = {groupId = 1, storage = 28002, tasks = {monsters = {{"dragon", 1000}}, items = {{5913, 50}, {5883, 100}, {2160, 400}}}, reward = {outfitId = 1, addonId = 2}},
- ["first hunter"] = {groupId = 2, storage = 28003, tasks = {monsters = {{"giant spider", 1500}}, items = {{6529, 1}, {5882, 50}, {5948, 400}, {2160, 350}}}, reward = {outfitId = 2, addonId = 1}},
- ["second hunter"] = {groupId = 2, storage = 28004, tasks = {monsters = {{"ghastly dragon", 2000}}, items = {{5920, 50}, {5877, 50}, {2160, 500}}}, reward = {outfitId = 2, addonId = 2}},
- ["first mage"] = {groupId = 3, storage = 28005, tasks = {monsters = {{"warlock", 4000}}, items = {{2182, 1}, {2186, 1}, {2185, 1}, {2181, 1}, {2183, 1}, {2190, 1}, {2191,1}, {2188, 1}, {2189, 1}, {2187, 1}, {5904, 30}, {2160,500}}}, reward = {outfitId = 3, addonId = 1}},
- ["second mage"] = {groupId = 3, storage = 28006, tasks = {monsters = {{"ferumbras", 20}}, items = {{5903, 10}, {5897, 100}, {2160, 900}}}, reward = {outfitId = 3, addonId = 2}},
- ["first knight"] = {groupId = 4, storage = 28007, tasks = {monsters = {{"black knight", 1000}}, items = {{2476, 10}, {5893, 50}, {2160, 450}}}, reward = {outfitId = 4, addonId = 1}},
- ["second knight"] = {groupId = 4, storage = 28008, tasks = {monsters = {{"nightmare", 1500}}, items = {{2400, 1}, {2160, 300}}}, reward = {outfitId = 4, addonId = 2}},
- ["first nobleman"] = {groupId = 5, storage = 28009, tasks = {monsters = {{"wyrm", 1000}}, items = {{2160, 500}}}, reward = {outfitId = 5, addonId = 1}},
- ["second nobleman"] = {groupId = 5, storage = 28010, tasks = {monsters = {{"serpent spawn", 1500}}, items = {{2160, 700}}}, reward = {outfitId = 5, addonId = 2}},
- ["first summoner"] = {groupId = 6, storage = 28011, tasks = {monsters = {{"lost soul", 1500}}, items = {{5881, 50}, {2392, 50}, {5883, 30}, {2160, 350}}}, reward = {outfitId = 6, addonId = 1}},
- ["second summoner"] = {groupId = 6, storage = 28012, tasks = {monsters = {{"plaguesmith", 1500}}, vials = true}, reward = {outfitId = 6, addonId = 2}}, -- UZYJ ITEM (mp, smp/gsp, gmp)
- ["first warrior"] = {groupId = 7, storage = 28013, tasks = {monsters = {{"behemoth", 2000}}, items = {{5925, 100}, {11233, 100}, {2160, 500}}}, reward = {outfitId = 7, addonId = 1}},
- ["second warrior"] = {groupId = 7, storage = 28014, tasks = {monsters = {{"undead dragon", 3500}}, items = {{5919, 4}, {5894, 25}, {2160, 500}}}, reward = {outfitId = 7, addonId = 2}},
- ["first barbarian"] = {groupId = 8, storage = 28015, tasks = {monsters = {{"demon", "test", 2500}}, items = {{5879, 100}, {6500, 100}, {2160, 600}}}, reward = {outfitId = 8, addonId = 1}},
- ["second barbarian"] = {groupId = 8, storage = 28016, tasks = {monsters = {{"draken elite", 3000}}, items = {{6500, 500}, {2432, 25}, {2160, 700}}}, reward = {outfitId = 8, addonId = 2}},
- ["first druid"] = {groupId = 9, storage = 28017, tasks = {monsters = {{"diabolic imp", 3000}}, items = {{5896, 50}, {5897, 15}, {5906, 55}, {2160, 300}}}, reward = {outfitId = 9, addonId = 1}},
- ["second druid"] = {groupId = 9, storage = 28018, tasks = {monsters = {{"hellhound", 4000}}, items = {{5902, 25}, {5894, 15}, {5913, 40}, {2160, 250}}}, reward = {outfitId = 9, addonId = 2}},
- ["first wizard"] = {groupId = 10, storage = 28019, tasks = {monsters = {{"bog raider", 1500}}, items = {{2178, 35}, {5883, 45}, {2160, 600}}}, reward = {outfitId = 10, addonId = 1}},
- ["second wizard"] = {groupId = 10, storage = 28020, tasks = {monsters = {{"infernalist", 2000}}, items = {{5879, 50}, {5911, 50}, {2160, 400}}}, reward = {outfitId = 10, addonId = 2}},
- ["first oriental"] = {groupId = 11, storage = 28021, tasks = {monsters = {{"dark torturer", 500}}, items = {{5895, 45}, {2150, 100}, {2160, 200}}}, reward = {outfitId = 11, addonId = 1}},
- ["second oriental"] = {groupId = 11, storage = 28022, tasks = {monsters = {{"hellspawn", 2000}}, items = {{5912, 35}, {2146, 100}, {2160, 200}}}, reward = {outfitId = 11, addonId = 2}},
- ["first pirate"] = {groupId = 12, storage = 28023, tasks = {monsters = {{"orshabaal", 10}}, items = {{6126, 50}, {2385, 1}, {2160, 200}}}, reward = {outfitId = 12, addonId = 1}},
- ["second pirate"] = {groupId = 12, storage = 28024, tasks = {monsters = {{"hydra", 5000}}, items = {{6098, 45}, {5917, 1}, {2160, 300}}}, reward = {outfitId = 12, addonId = 2}},
- ["first assassin"] = {groupId = 13, storage = 28025, tasks = {monsters = {{"morgaroth", 7}}, items = {{6500, 1500}, {2160, 500}}}, reward = {outfitId = 13, addonId = 1}},
- ["second assassin"] = {groupId = 13, storage = 28026, tasks = {monsters = {{"dragon lord", 3500}}, items = {{6500, 2000}, {2160, 700}}}, reward = {outfitId = 13, addonId = 2}},
- ["first beggar"] = {groupId = 14, storage = 28027, tasks = {monsters = {{"hero", 2000}}, items = {{3976, 200}, {5930, 3}, {2160, 400}}}, reward = {outfitId = 14, addonId = 1}},
- ["second beggar"] = {groupId = 14, storage = 28028, tasks = {monsters = {{"destroyer", 1500}}, items = {{5913, 100}, {5894, 20}, {2160, 400}}}, reward = {outfitId = 14, addonId = 2}},
- ["first shaman"] = {groupId = 15, storage = 28029, tasks = {monsters = {{"necromancer", 5}}, items = {{5880, 100}, {5895, 10}, {5912, 50}, {2160, 500}}}, reward = {outfitId = 15, addonId = 1}},
- ["second shaman"] = {groupId = 15, storage = 28030, tasks = {monsters = {{"defiler", 3000}}, items = {{2156, 10}, {2155, 10}, {2158, 10}, {7760, 50}, {2160, 500}}}, reward = {outfitId = 15, addonId = 2}},
- ["first norseman"] = {groupId = 16, storage = 28031, tasks = {monsters = {{"frost dragon", 3000}}, items = {{7290, 30}, {2656, 8}, {2146, 50}, {2160, 300}}}, reward = {outfitId = 16, addonId = 1}},
- ["second norseman"] = {groupId = 16, storage = 28032, tasks = {monsters = {{"sea serpent", 2000}}, items = {{7290, 40}, {5912, 50}, {2160, 400}}}, reward = {outfitId = 16, addonId = 2}},
- ["first nightmare"] = {groupId = 17, storage = 28033, tasks = {monsters = {{"ghazbaran", 5}}, items = {{6300, 10}, {5944, 200}, {2195, 10}, {2160, 400}}}, reward = {outfitId = 17, addonId = 1}},
- ["second nightmare"] = {groupId = 17, storage = 28034, tasks = {monsters = {{"blightwalker", 80}}, items = {{2469, 1}, {2506, 1}, {11118, 1}, {2492, 1}, {2160, 500}}}, reward = {outfitId = 17, addonId = 2}},
- ["first jester"] = {groupId = 18, storage = 28035, tasks = {monsters = {{"hellfire fighter", 3000}}, items = {{2160, 700}}}, reward = {outfitId = 18, addonId = 1}},
- ["second jester"] = {groupId = 18, storage = 28036, tasks = {monsters = {{"medusa", 2000}}, items = {{2160, 900}}}, reward = {outfitId = 18, addonId = 2}},
- ["first brotherhood"] = {groupId = 19, storage = 28037, tasks = {monsters = {{"juggernaut", 500}}, items = {{6500, 1000}, {2160, 500}}}, reward = {outfitId = 19, addonId = 1}},
- ["second brotherhood"] = {groupId = 19, storage = 28038, tasks = {monsters = {{"fury", 2500}}, items = {{6500, 1000}, {2160, 700}}}, reward = {outfitId = 19, addonId = 2}}
- }
- if not AddonTasks then
- AddonTasks = {
- getGroups = function()
- return groups
- end,
- getTasks = function()
- return tasks
- end,
- getStartedTasks = function(cid)
- local started_tasks = {}
- for k,v in pairs(tasks) do
- if getPlayerSpecialStorageValue(cid, v.storage) == 1 then
- table.insert(started_tasks, v)
- end
- end
- return started_tasks
- end
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement