Guest User

Untitled

a guest
Jun 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.90 KB | None | 0 0
  1. --npc/scripts/task.lua
  2. local tasks =
  3. {
  4.        
  5.         [1] = {questStarted = 1510, questStorage = 65000, killsRequired = 600,mount = "Widow Queen", raceName = "Giant Spiders", rewards = {{enable = true, type = "item", values = 9007}}},
  6.         [2] = {questStarted = 1511, questStorage = 65001, killsRequired = 400,mount = "Racing Bird", raceName = "medusas", rewards = {{enable = true, type = "item", values = 10127}}},
  7.         [3] = {questStarted = 1512, questStorage = 65002, killsRequired = 800,mount = "War Bear", raceName = "Cyclops", rewards = {{enable = true, type = "item", values = 9019}}},
  8.         [4] = {questStarted = 1513, questStorage = 65003, killsRequired = 500,mount = "black sheep", raceName = "Necromancers", rewards = {{enable = true, type = "item", values = 10129}}},
  9.         [5] = {questStarted = 1514, questStorage = 65004, killsRequired = 700,mount = "Midnight Panther", raceName = "Dark Torturers", rewards = {{enable = true, type = "item", values = 9653}}},
  10.         [6] = {questStarted = 1515, questStorage = 65005, killsRequired = 500,mount = "draptor", raceName = "Lizards chosens", rewards = {{enable = true, type = "item", values = 9662}}},
  11.         [7] = {questStarted = 1516, questStorage = 65006, killsRequired = 300,mount = "titanica", raceName = "Water Elementals",rewards = {{enable = true, type = "item", values = 9981}}},
  12.         [8] = {questStarted = 1517, questStorage = 65007, killsRequired = 400,mount = "Tin Lizzard", raceName = "Dragon lords", rewards = {{enable = true, type = "item", values = 9980}}},
  13.         [9] = {questStarted = 1518, questStorage = 65008, killsRequired = 900,mount = "Blazebringer", raceName = "Demons", rewards = {{enable = true, type = "item", values = 10108}}},
  14.         [10] = {questStarted = 1519, questStorage = 65009, killsRequired = 700,mount = "Rapid Boar", raceName = "Behemoths", rewards = {{enable = true, type = "item", values = 10124}}},
  15.         [11] = {questStarted = 1520, questStorage = 65010, killsRequired = 800,mount = "Stampor Mount", raceName = "Hydras", rewards = {{enable = true, type = "item", values = 10125}}},
  16.         [12] = {questStarted = 1521, questStorage = 65011, killsRequired = 100,mount = "Undead Cadaver", raceName = "Armagedons", rewards = {{enable = true, type = "item", values = 11773}}},
  17.         [13] = {questStarted = 1522, questStorage = 65012, killsRequired = 400,mount = "Dragon ", raceName = "Dragons", rewards = {{enable = true, type = "item", values = 10530}}},
  18.         [14] = {questStarted = 1523, questStorage = 65013, killsRequired = 700,mount = "Nightmare", raceName = "Nightmares", rewards = {{enable = true, type = "item", values = 8974}}},
  19.         [15] = {questStarted = 1524, questStorage = 65014, killsRequired = 400,mount = "Quara Predator", raceName = "Quara Predators", rewards = {{enable = true, type = "item", values = 10142}}},
  20.         [16] = {questStarted = 1525, questStorage = 65015, killsRequired = 800,mount = "Undead Dragon", raceName = "Undead Dragons", rewards = {{enable = true, type = "item", values = 10150}}},
  21.         [17] = {questStarted = 1526, questStorage = 65016, killsRequired = 700,mount = "Panda", raceName = "Warlocks", rewards = {{enable = true, type = "item", values = 10173}}},
  22.         [18] = {questStarted = 1527, questStorage = 65017, killsRequired = 700,mount = "Tarantula ", raceName = "Tarantulas", rewards = {{enable = true, type = "item", values = 6102}}},
  23.         [19] = {questStarted = 1528, questStorage = 65018, killsRequired = 500,mount = "Donkey ", raceName = "furys", rewards = {{enable = true, type = "item", values = 12641}}},
  24.         [20] = {questStarted = 1529, questStorage = 65019, killsRequired = 300,mount = "Tiger Slug ", raceName = "deepling warriors", rewards = {{enable = true, type = "item", values = 8298}}},
  25.         [21] = {questStarted = 1530, questStorage = 65020, killsRequired = 600,mount = "Uniwheel ", raceName = "war golems", rewards = {{enable = true, type = "item", values = 13292}}},
  26.         [22] = {questStarted = 1531, questStorage = 65021, killsRequired = 700,mount = "Crystal Wolf ", raceName = "mad mages", rewards = {{enable = true, type = "item", values = 13293}}},
  27.         [23] = {questStarted = 1532, questStorage = 65022, killsRequired = 700,mount = "War Horse ", raceName = "deepling giant pros", rewards = {{enable = true, type = "item", values = 13294}}},
  28.         [24] = {questStarted = 1533, questStorage = 65023, killsRequired = 800,mount = "Kingly Deer ", raceName = "floor blobs", rewards = {{enable = true, type = "item", values = 13298}}},
  29.         [25] = {questStarted = 1534, questStorage = 65024, killsRequired = 800,mount = "Tamed Panda ", raceName = "crawlers", rewards = {{enable = true, type = "item", values = 13295}}},
  30.         [26] = {questStarted = 1535, questStorage = 65025, killsRequired = 800,mount = "Dromedary ", raceName = "spidiris", rewards = {{enable = true, type = "item", values = 13307}}},
  31.         [27] = {questStarted = 1536, questStorage = 65026, killsRequired = 600,mount = "King Scorpion ", raceName = "deepling guards", rewards = {{enable = true, type = "item", values = 13305}}},
  32.         [28] = {questStarted = 1537, questStorage = 65027, killsRequired = 50,mount = "Horse ", raceName = "esmeraldas", rewards = {{enable = true, type = "item", values = 10063}}},
  33.         [29] = {questStarted = 1538, questStorage = 65028, killsRequired = 700,mount = "Fire War Horse ", raceName = "askarak demons", rewards = {{enable = true, type = "item", values = 13247}}},
  34.         [30] = {questStarted = 1539, questStorage = 65029, killsRequired = 900,mount = "Shadow Draptor ", raceName = "kollos", rewards = {{enable = true, type = "item", values = 13538}}},
  35.        
  36.  
  37.  
  38.  
  39.        
  40. }
  41.  
  42. local rankStorage = 32150
  43. local choose = {}
  44.  
  45. local keywordHandler = KeywordHandler:new()
  46. local npcHandler = NpcHandler:new(keywordHandler)
  47. NpcSystem.parseParameters(npcHandler)
  48. local talkState = {}
  49.  
  50. function onCreatureAppear(cid)                          npcHandler:onCreatureAppear(cid) end
  51. function onCreatureDisappear(cid)                       npcHandler:onCreatureDisappear(cid) end
  52. function onCreatureSay(cid, type, msg)                  npcHandler:onCreatureSay(cid, type, msg) end
  53. function onThink()                                      npcHandler:onThink() end
  54.  
  55. function getTasksStarted(cid)
  56.         local tmp = {}
  57.         for k, v in pairs(tasks) do
  58.                 if getCreatureStorage(cid, v.questStarted) == 1 then
  59.                         table.insert(tmp, k)
  60.                 end
  61.         end
  62.         return tmp
  63. end
  64.  
  65. function getTaskByName(name)
  66.         for k, v in pairs(tasks) do
  67.                 if v.raceName:lower() == name:lower() then
  68.                         return k
  69.                 end
  70.         end
  71.         return false
  72. end
  73.  
  74. function creatureSayCallback(cid, type, msg)
  75.  
  76.         if(not npcHandler:isFocused(cid)) then
  77.                 return false
  78.         end
  79.         local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
  80.         if isInArray({"task", "tasks"}, msg:lower()) then
  81.                 selfSay("There you can see the following tasks, please tell me the number of the task that you want to do.", cid)
  82.                 local text = ""
  83.                 for i = 1, table.maxn(tasks) do
  84.                         text = text .. (text == "" and "" or "\n") .. i .. "  -  " .. tasks[i].raceName .. " ["..tasks[i].mount.. " mount] ".. (getCreatureStorage(cid, tasks[i].questStarted) == 1 and " [...]" or getCreatureStorage(cid, tasks[i].questStarted) == 2 and " [x]" or "")
  85.                 end
  86.                 return doShowTextDialog(cid, 5956, text)
  87.  
  88.         elseif getTaskByName(msg) or tasks[tonumber(msg)] then
  89.                 msg = (getTaskByName(msg) or tonumber(msg))
  90.                 if getCreatureStorage(cid, tasks[msg].questStarted) == 1 then
  91.                         selfSay("You already started this task.", cid)
  92.                         talkState[talkUser] = 0
  93.                         return true
  94.                 end
  95.                 if getCreatureStorage(cid, tasks[msg].questStarted) == 2 then
  96.                         selfSay("You already finished this task.", cid)
  97.                         talkState[talkUser] = 0
  98.                         return true
  99.                 end
  100.                 if tasks[msg].level and getPlayerLevel(cid) < tasks[msg].level then
  101.                         selfSay("You need level " .. tasks[msg].level .. " or higher to make this task.", cid)
  102.                         talkState[talkUser] = 0
  103.                         return true
  104.                 end
  105.                 selfSay("Are you sure that do you want to start the task number " .. msg .. "? In this task you will need to defeat " .. tasks[msg].killsRequired .. " " .. tasks[msg].raceName .. ".", cid)
  106.                 choose[cid] = msg
  107.                 talkState[talkUser] = 1
  108.         elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
  109.                 doCreatureSetStorage(cid, tasks[choose[cid]].questStarted, 1)
  110.                 selfSay("You have started the task number " .. choose[cid] .. ", remember... in this task you will need to defeat " .. tasks[choose[cid]].killsRequired .. " " .. tasks[choose[cid]].raceName .. ". Good luck!", cid)
  111.                 talkState[talkUser] = 0
  112.                 return true
  113.  
  114.         elseif msg:lower() == "report" then
  115.                 local t = getTasksStarted(cid)
  116.                 local response = "You are currently making " .. (#t > 1 and "these" or "this") .. " task" .. (#t > 1 and "s" or "") .. ":\n"
  117.                 if table.maxn(t) > 0 then
  118.                         for _, tsk in ipairs(t) do
  119.                                 if tonumber(getCreatureStorage(cid, tasks[tsk].questStorage)) < 0 then doCreatureSetStorage(cid, tasks[tsk].questStorage, 0) end
  120.                                 response = response .. "     Name: " .. tasks[tsk].raceName .. "     Kills: " .. getCreatureStorage(cid, tasks[tsk].questStorage) .. " - " .. tasks[tsk].killsRequired .. ".\n"
  121.                         end
  122.                         response = response .. "Please say report and the name of the task that do you want to report, example: 'Report Trolls'."
  123.                         return selfSay(response, cid)
  124.                 else
  125.                         return selfSay("You need to start at least one task first.", cid)
  126.                 end
  127.         elseif string.sub(msg:lower(), 0, 6) == "report" then
  128.                 local t = getTaskByName(string.sub(msg, 8, string.len(msg)))
  129.                 if not t then
  130.                         return selfSay("That task does not exists.", cid)
  131.                 end
  132.  
  133.                 if getCreatureStorage(cid, tasks[t].questStarted) == 2 then
  134.                         return selfSay("You already finished this task.", cid)
  135.                 end
  136.  
  137.                 if getCreatureStorage(cid, tasks[t].questStarted) < 1 then
  138.                         return selfSay("You don't have started this task.", cid)
  139.                 end
  140.  
  141.                 if tasks[t].killsRequired > getCreatureStorage(cid, tasks[t].questStorage) then
  142.                         return selfSay("Current " .. getCreatureStorage(cid, tasks[t].questStorage) .. " " .. tasks[t].raceName .. " killed, you need to kill " .. tasks[t].killsRequired .. ".", cid)
  143.                 end
  144.  
  145.                 for i = 1, table.maxn(tasks[t].rewards) do
  146.                         if(tasks[t].rewards[i].enable) then
  147.                                 if isInArray({"item", 1}, tasks[t].rewards[i].type) then
  148.                                         doPlayerAddItem(cid, tasks[t].rewards[i].values, 1)
  149.                                 end
  150.                         end
  151.                 end
  152.                 local rank = getCreatureStorage(cid, rankStorage)
  153.                 selfSay("Great!... you have finished the task number " .. t .. ",  Good job.", cid)
  154.                 return doCreatureSetStorage(cid, tasks[t].questStarted, 2)
  155.         end
  156.         return true
  157. end
  158.  
  159. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  160. npcHandler:addModule(FocusModule:new())
Add Comment
Please, Sign In to add comment