Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.02 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4. local choose, talkState = {}, {}
  5.  
  6. function onCreatureAppear(cid)                  npcHandler:onCreatureAppear(cid)                end
  7. function onCreatureDisappear(cid)               npcHandler:onCreatureDisappear(cid)             end
  8. function onCreatureSay(cid, type, msg)          npcHandler:onCreatureSay(cid, type, msg)        end
  9. function onThink()                              npcHandler:onThink()                            end
  10.  
  11. function getTaskGroupsByAddonName(taskName)
  12.     local groups = AddonTasks.getGroups()
  13.     for i,v in ipairs(groups) do
  14.         if v:lower() == taskName then
  15.             return v
  16.         end
  17.     end
  18.     return false
  19. end
  20.  
  21. function getTaskByName(taskName)
  22.     local tasks = AddonTasks.getTasks()
  23.     for k,v in pairs(tasks) do
  24.         if k:lower() == taskName then
  25.             return v
  26.         end
  27.     end
  28.     return false
  29. end
  30.  
  31. function creatureSayCallback(cid, type, msg)
  32.     if(not npcHandler:isFocused(cid)) then
  33.         return false
  34.     end
  35.  
  36.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
  37.     msg = msg:lower()
  38.     if(msgcontains(msg, 'addons')) then
  39.         local groups, string, separator = AddonTasks.getGroups(), "Here are the addons that I can help you do: ", ", "
  40.         for i,v in ipairs(groups) do
  41.             if(i == #groups - 1) then
  42.                 separator = " and "
  43.             elseif(i == #groups) then
  44.                 separator = "."
  45.             end
  46.             string = string .. "{" .. v .. "}" .. separator
  47.         end
  48.         string = string .. " Which outfit would you like to have?"
  49.         npcHandler:say(string, cid)
  50.     elseif(getTaskGroupsByAddonName(msg)) then
  51.         npcHandler:say("Which addon interest you? {first " .. msg .. "} addon or {second " .. msg .. "} addon?", cid)
  52.     elseif(getTaskByName(msg)) then
  53.         local tasks = AddonTasks.getTasks()
  54.         for k,v in pairs(tasks) do
  55.             if(getPlayerSpecialStorageValue(cid, v.storage) == 1) then
  56.                 npcHandler:say("I'm sorry but you're already in the middle of a different task. Type {started} to find out which one.", cid)
  57.                 return true
  58.             end
  59.         end
  60.  
  61.         local task = getTaskByName(msg)
  62.  
  63.         -- check if player already have this addon
  64.         if(canPlayerWearOutfitId(cid, task.reward.outfitId, task.reward.addonId)) then
  65.             npcHandler:say("You already have this addon. Please select another one from the list.", cid)
  66.             return true
  67.         end
  68.  
  69.         -- monsters
  70.         local monsters_string = ""
  71.         for i,v in ipairs(task.tasks.monsters) do
  72.             monsters_string = monsters_string .. "{" .. v[2] .. "x " .. v[1] .. "}"
  73.             if(#task.tasks.monsters > 1 and i ~= #task.tasks.monsters) then
  74.                 monsters_string = monsters_string .. ", "
  75.             end
  76.         end
  77.  
  78.         -- items
  79.         local items_string = ""
  80.         for i,v in ipairs(task.tasks.items) do
  81.             items_string = items_string .. "{" .. v[2] .. "x " .. getItemNameById(v[1]) .. "}"
  82.             if(#task.tasks.items > 1 and i ~= #task.tasks.items) then
  83.                 items_string = items_string .. ", "
  84.             end
  85.         end
  86.  
  87.         talkState[talkUser] = 1
  88.         choose[cid] = task
  89.         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)
  90.     elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1 and choose[cid] ~= nil) then
  91.         local task = choose[cid]
  92.         setPlayerSpecialStorageValue(cid, task.storage, 1)
  93.         choose[cid] = nil
  94.         talkState[talkUser] = 0
  95.         npcHandler:say("Excellent! Task has been activated. Please come back when you finish.", cid)
  96.     elseif(msgcontains(msg, 'report')) then
  97.         local finished_tasks, tasks = {}, AddonTasks.getTasks()
  98.         for k,v in pairs(tasks) do
  99.             if(getPlayerSpecialStorageValue(cid, v.storage) == 2) then
  100.                 table.insert(finished_tasks, v)
  101.             end
  102.         end
  103.  
  104.         if(#finished_tasks < 1) then
  105.             npcHandler:say("You dont have any finished tasks.", cid)
  106.             return true
  107.         end
  108.  
  109.         local string = ""
  110.         for k,v in pairs(finished_tasks) do
  111.             local items = {}
  112.             for k,v in pairs(v.tasks.items) do
  113.                 if(getPlayerItemCount(cid, v[1]) < v[2]) then
  114.                     table.insert(items, {v[1], v[2]})
  115.                 end
  116.             end
  117.  
  118.             if(#items > 0) then
  119.                 local items_string = ""
  120.                 for i,v in ipairs(items) do
  121.                     items_string = items_string .. "{" .. v[2] .. "x " .. getItemNameById(v[1]) .. "}"
  122.                     if(#items > 1 and i ~= #items) then
  123.                         items_string = items_string .. ", "
  124.                     end
  125.                 end
  126.  
  127.                 items_string = items_string .. ". Please come back when you'll have them."
  128.                 npcHandler:say("You miss these items: " .. items_string, cid)
  129.                 return true
  130.             end
  131.  
  132.         if(v.tasks.vials) then
  133.           if getPlayerSpecialStorageValue(cid, 6969) <= 5000 then
  134.             npcHandler:say("You have not used yet 5000 vials.", cid)
  135.             return false
  136.           end
  137.         end
  138.  
  139.             for k,v in pairs(v.tasks.items) do
  140.                 doPlayerRemoveItem(cid, v[1], v[2])
  141.             end
  142.  
  143.             doPlayerAddOutfitId(cid, v.reward.outfitId, v.reward.addonId)
  144.         setPlayerSpecialStorageValue(cid, v.storage, 3)
  145.         end
  146.  
  147.       doSendMagicEffect(getPlayerPosition(cid), 12)
  148.       doCreatureSay(cid, "TASK FINISHED!", TALKTYPE_ORANGE_1)
  149.         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)
  150.     elseif(msgcontains(msg, 'started')) then
  151.         local tasks, groups = AddonTasks.getStartedTasks(cid), AddonTasks.getGroups()
  152.         if(#tasks < 1) then
  153.             npcHandler:say("You dont have any started tasks.", cid)
  154.             return true
  155.         end
  156.  
  157.         local string = "The current task that you started is "
  158.         for i,v in ipairs(tasks) do
  159.             string = string .. "{" .. groups[v.groupId] .. "}"
  160.             if(#tasks > 1 and i ~= #tasks) then
  161.                 string = string .. ", "
  162.             end
  163.         end
  164.  
  165.         string = string .. "."
  166.         npcHandler:say(string, cid)
  167.     elseif(msgcontains(msg, 'cancel')) then
  168.         local tasks, groups = AddonTasks.getStartedTasks(cid), AddonTasks.getGroups()
  169.         if(#tasks < 1) then
  170.             npcHandler:say("You dont have any started tasks.", cid)
  171.             return true
  172.         end
  173.  
  174.         local string = "Here are the tasks that were canceled: "
  175.         for k,v in pairs(tasks) do
  176.             if(getPlayerSpecialStorageValue(cid, v.storage) == 1) then
  177.                 string = string .. "{" .. groups[v.groupId] .. "}"
  178.                 if(#tasks > 1 and i ~= #tasks) then
  179.                     string = string .. ", "
  180.                 end
  181.                 setPlayerSpecialStorageValue(cid, v.storage, 0)
  182.             end
  183.         end
  184.  
  185.         string = string .. "."
  186.         npcHandler:say(string, cid)
  187.     elseif(msgcontains(msg, 'help')) then
  188.         npcHandler:say("To buy the first addon say {first NAME} and for the second addon say {second NAME}.", cid)
  189.     end
  190.     return true
  191. end
  192.  
  193. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  194. npcHandler:addModule(FocusModule:new())
  195.  
  196.  
  197. ---- lib
  198. local groups = {
  199.     [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'
  200. }
  201.  
  202. local tasks = {
  203.     ["first citizen"] = {groupId = 1, storage = 28001, tasks = {monsters = {{"rotworm", 500}}, items = {{5878, 100}, {5890, 100}, {2160, 400}}}, reward = {outfitId = 1, addonId = 1}},
  204.     ["second citizen"] = {groupId = 1, storage = 28002, tasks = {monsters = {{"dragon", 1000}}, items = {{5913, 50}, {5883, 100}, {2160, 400}}}, reward = {outfitId = 1, addonId = 2}},
  205.     ["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}},
  206.     ["second hunter"] = {groupId = 2, storage = 28004, tasks = {monsters = {{"ghastly dragon", 2000}}, items = {{5920, 50}, {5877, 50}, {2160, 500}}}, reward = {outfitId = 2, addonId = 2}},
  207.     ["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}},
  208.     ["second mage"] = {groupId = 3, storage = 28006, tasks = {monsters = {{"ferumbras", 20}}, items = {{5903, 10}, {5897, 100}, {2160, 900}}}, reward = {outfitId = 3, addonId = 2}},
  209.     ["first knight"] = {groupId = 4, storage = 28007, tasks = {monsters = {{"black knight", 1000}}, items = {{2476, 10}, {5893, 50}, {2160, 450}}}, reward = {outfitId = 4, addonId = 1}},
  210.     ["second knight"] = {groupId = 4, storage = 28008, tasks = {monsters = {{"nightmare", 1500}}, items = {{2400, 1}, {2160, 300}}}, reward = {outfitId = 4, addonId = 2}},
  211.     ["first nobleman"] = {groupId = 5, storage = 28009, tasks = {monsters = {{"wyrm", 1000}}, items = {{2160, 500}}}, reward = {outfitId = 5, addonId = 1}},
  212.     ["second nobleman"] = {groupId = 5, storage = 28010, tasks = {monsters = {{"serpent spawn", 1500}}, items = {{2160, 700}}}, reward = {outfitId = 5, addonId = 2}},
  213.     ["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}},
  214.     ["second summoner"] = {groupId = 6, storage = 28012, tasks = {monsters = {{"plaguesmith", 1500}}, vials = true}, reward = {outfitId = 6, addonId = 2}},        -- UZYJ ITEM (mp, smp/gsp, gmp)
  215.     ["first warrior"] = {groupId = 7, storage = 28013, tasks = {monsters = {{"behemoth", 2000}}, items = {{5925, 100}, {11233, 100}, {2160, 500}}}, reward = {outfitId = 7, addonId = 1}},
  216.     ["second warrior"] = {groupId = 7, storage = 28014, tasks = {monsters = {{"undead dragon", 3500}}, items = {{5919, 4}, {5894, 25}, {2160, 500}}}, reward = {outfitId = 7, addonId = 2}},
  217.     ["first barbarian"] = {groupId = 8, storage = 28015, tasks = {monsters = {{"demon", "test", 2500}}, items = {{5879, 100}, {6500, 100}, {2160, 600}}}, reward = {outfitId = 8, addonId = 1}},
  218.     ["second barbarian"] = {groupId = 8, storage = 28016, tasks = {monsters = {{"draken elite", 3000}}, items = {{6500, 500}, {2432, 25}, {2160, 700}}}, reward = {outfitId = 8, addonId = 2}},
  219.     ["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}},
  220.     ["second druid"] = {groupId = 9, storage = 28018, tasks = {monsters = {{"hellhound", 4000}}, items = {{5902, 25}, {5894, 15}, {5913, 40}, {2160, 250}}}, reward = {outfitId = 9, addonId = 2}},
  221.     ["first wizard"] = {groupId = 10, storage = 28019, tasks = {monsters = {{"bog raider", 1500}}, items = {{2178, 35}, {5883, 45}, {2160, 600}}}, reward = {outfitId = 10, addonId = 1}},
  222.     ["second wizard"] = {groupId = 10, storage = 28020, tasks = {monsters = {{"infernalist", 2000}}, items = {{5879, 50}, {5911, 50}, {2160, 400}}}, reward = {outfitId = 10, addonId = 2}},
  223.     ["first oriental"] = {groupId = 11, storage = 28021, tasks = {monsters = {{"dark torturer", 500}}, items = {{5895, 45}, {2150, 100}, {2160, 200}}}, reward = {outfitId = 11, addonId = 1}},
  224.     ["second oriental"] = {groupId = 11, storage = 28022, tasks = {monsters = {{"hellspawn", 2000}}, items = {{5912, 35}, {2146, 100}, {2160, 200}}}, reward = {outfitId = 11, addonId = 2}},
  225.     ["first pirate"] = {groupId = 12, storage = 28023, tasks = {monsters = {{"orshabaal", 10}}, items = {{6126, 50}, {2385, 1}, {2160, 200}}}, reward = {outfitId = 12, addonId = 1}},
  226.     ["second pirate"] = {groupId = 12, storage = 28024, tasks = {monsters = {{"hydra", 5000}}, items = {{6098, 45}, {5917, 1}, {2160, 300}}}, reward = {outfitId = 12, addonId = 2}},
  227.     ["first assassin"] = {groupId = 13, storage = 28025, tasks = {monsters = {{"morgaroth", 7}}, items = {{6500, 1500}, {2160, 500}}}, reward = {outfitId = 13, addonId = 1}},
  228.     ["second assassin"] = {groupId = 13, storage = 28026, tasks = {monsters = {{"dragon lord", 3500}}, items = {{6500, 2000}, {2160, 700}}}, reward = {outfitId = 13, addonId = 2}},
  229.     ["first beggar"] = {groupId = 14, storage = 28027, tasks = {monsters = {{"hero", 2000}}, items = {{3976, 200}, {5930, 3}, {2160, 400}}}, reward = {outfitId = 14, addonId = 1}},
  230.     ["second beggar"] = {groupId = 14, storage = 28028, tasks = {monsters = {{"destroyer", 1500}}, items = {{5913, 100}, {5894, 20}, {2160, 400}}}, reward = {outfitId = 14, addonId = 2}},
  231.     ["first shaman"] = {groupId = 15, storage = 28029, tasks = {monsters = {{"necromancer", 5}}, items = {{5880, 100}, {5895, 10}, {5912, 50}, {2160, 500}}}, reward = {outfitId = 15, addonId = 1}},
  232.     ["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}},
  233.     ["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}},
  234.     ["second norseman"] = {groupId = 16, storage = 28032, tasks = {monsters = {{"sea serpent", 2000}}, items = {{7290, 40}, {5912, 50}, {2160, 400}}}, reward = {outfitId = 16, addonId = 2}},
  235.     ["first nightmare"] = {groupId = 17, storage = 28033, tasks = {monsters = {{"ghazbaran", 5}}, items = {{6300, 10}, {5944, 200}, {2195, 10}, {2160, 400}}}, reward = {outfitId = 17, addonId = 1}},
  236.     ["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}},
  237.     ["first jester"] = {groupId = 18, storage = 28035, tasks = {monsters = {{"hellfire fighter", 3000}}, items = {{2160, 700}}}, reward = {outfitId = 18, addonId = 1}},
  238.     ["second jester"] = {groupId = 18, storage = 28036, tasks = {monsters = {{"medusa", 2000}}, items = {{2160, 900}}}, reward = {outfitId = 18, addonId = 2}},
  239.     ["first brotherhood"] = {groupId = 19, storage = 28037, tasks = {monsters = {{"juggernaut", 500}}, items = {{6500, 1000}, {2160, 500}}}, reward = {outfitId = 19, addonId = 1}},
  240.     ["second brotherhood"] = {groupId = 19, storage = 28038, tasks = {monsters = {{"fury", 2500}}, items = {{6500, 1000}, {2160, 700}}}, reward = {outfitId = 19, addonId = 2}}
  241. }
  242.  
  243. if not AddonTasks then
  244.     AddonTasks = {
  245.         getGroups = function()
  246.             return groups
  247.         end,
  248.         getTasks = function()
  249.             return tasks
  250.         end,
  251.         getStartedTasks = function(cid)
  252.             local started_tasks = {}
  253.             for k,v in pairs(tasks) do
  254.                 if getPlayerSpecialStorageValue(cid, v.storage) == 1 then
  255.                     table.insert(started_tasks, v)
  256.                 end
  257.             end
  258.             return started_tasks
  259.         end
  260.     }
  261. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement