Guest User

Task_window.lua -- Creaturescript

a guest
Nov 18th, 2018
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.57 KB | None | 0 0
  1. function onModalWindow(cid, modalWindowId, buttonId, choiceId)
  2.     local rank = getCreatureStorage(cid, rankStorage)
  3.     if rank < 0 then
  4.         doCreatureSetStorage(cid, rankStorage, 0)
  5.     end
  6.                    
  7.     local r_string = function() if tasks[choiceId].repeatable then return "repeatable" end return "not repeatable" end
  8.     local r_article_string = function (id, amount)
  9.         task_item_word = ""
  10.         if amount > 1 then
  11.             task_item_word = task_item_word .. amount .. "x " .. getItemName(id)
  12.         else
  13.             if ItemType(itemId):getArticle() == "" then
  14.                 task_item_word = task_item_word .. getItemName(id)
  15.             else
  16.                 task_item_word = task_item_word .. ItemType(itemId):getArticle() .. " " .. getItemName(id)
  17.             end
  18.         end
  19.     return task_item_word
  20.     end
  21.     local storage_string = {[80000] = "The Snapper",
  22. [80001] = "Demodras",
  23. [80002] = "The Hide",
  24. [80003] = "The Bloodtusk",
  25. [80004] = "The Shardhead",
  26. [80005] = "Thul",
  27. [80006] = "Esmeralda",
  28. [80007] = "The Old Widow",
  29. [80008] = "The Many",
  30. [80009] = "The Leviathan",
  31. [80010] = "The Stonecracker",
  32. [80011] = "The Noxious Spawn",
  33. [80012] = "Merikh The Slaughterer",
  34. [80013] = "Fahim The Wise",
  35. [80014] = "pirate leader",
  36. [80015] = "The Horned Fox",
  37. [80016] = "Necropharus"
  38.     }
  39.     if (not modalWindowId == 1900) then return false end
  40.  
  41.     if buttonId == 1 then -- confirm task
  42.         if getCreatureStorage(cid, tasks[choiceId].questStarted) < 1 then
  43.             doCreatureSetStorage(cid, tasks[choiceId].questStarted, 1)
  44.             doCreatureSetStorage(cid, tasks[choiceId].questStorage, 0)
  45.             doCreatureSay(taskNPCuid, "In this mission you have to hunt " .. tasks[choiceId].killsRequired .. " " .. tasks[choiceId].raceName .. " down. Good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
  46.         else
  47.             if getCreatureStorage(cid, tasks[choiceId].questStarted) == 1 then
  48.                 if tasks[choiceId].killsRequired > getCreatureStorage(cid, tasks[choiceId].questStorage) then
  49.                     doPlayerPopupFYI(cid,"Status: Active\nKills: " .. getCreatureStorage(cid, tasks[choiceId].questStorage) .. "/" .. tasks[choiceId].killsRequired .. " (" .. tasks[choiceId].killsRequired - getCreatureStorage(cid, tasks[choiceId].questStorage) .. " left)\n\nThis mission is " .. r_string() .. ".")
  50.                     sendTaskWindow(cid)
  51.                 else
  52.                     doCreatureSetStorage(cid, tasks[choiceId].questStarted, 2)
  53.                     task_reward_str = "Reward(s):\n"
  54.                     for i = 1, table.maxn(tasks[choiceId].rewards) do
  55.                         if(tasks[choiceId].rewards[i].enable) then
  56.                             if isInArray({"boss", "teleport", 1}, tasks[choiceId].rewards[i].type) then
  57.                                 doTeleportThing(cid, tasks[choiceId].rewards[i].values)
  58.                                 task_reward_str = task_reward_str .. "You have been teleported.\n"
  59.                             elseif isInArray({"exp", "experience", 2}, tasks[choiceId].rewards[i].type) then
  60.                                 doPlayerAddExperience(cid, tasks[choiceId].rewards[i].values)
  61.                                 task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " exp\n"
  62.                             elseif isInArray({"item", 3}, tasks[choiceId].rewards[i].type) then
  63.                                 doPlayerAddItem(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
  64.                                 task_reward_str = task_reward_str .. r_article_string(tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2]) .. "\n"
  65.                             elseif isInArray({"money", 4}, tasks[choiceId].rewards[i].type) then
  66.                                 doPlayerAddMoney(cid, tasks[choiceId].rewards[i].values)
  67.                                 task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " gp\n"
  68.                             elseif isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
  69.                                 doCreatureSetStorage(cid, tasks[choiceId].rewards[i].values[1], tasks[choiceId].rewards[i].values[2])
  70.                                 task_reward_str = task_reward_str .. "Chance to duel " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. ".\n"
  71.                             elseif isInArray({"points", "rank", 2}, tasks[choiceId].rewards[i].type) then
  72.                                 doCreatureSetStorage(cid, rankStorage, getCreatureStorage(cid, rankStorage) + tasks[choiceId].rewards[i].values)
  73.                                 task_reward_str = task_reward_str .. "+ " .. tasks[choiceId].rewards[i].values .. " rank points.\n"
  74.                             else
  75.                                 print("[Warning - Npc::KillingInTheNameOf] Wrong reward type: " .. (tasks[choiceId].rewards[i].type or "nil") .. ", reward could not be loaded.")
  76.                             end
  77.                         end
  78.                     end
  79.                     if task_reward_str == "Reward(s):\n" then
  80.                         doPlayerPopupFYI(cid,task_reward_str .. "none")
  81.                     else
  82.                         doPlayerPopupFYI(cid,task_reward_str)
  83.                     end
  84.                     doCreatureSay(taskNPCuid, "Great job" .. (((rank > 4 and rank < 10) and (", Huntsman") or (rank > 9 and rank < 20) and (", Ranger") or (rank > 19 and rank < 30) and (", Big Game Hunter") or (rank > 29 and rank < 50) and (", Trophy Hunter") or (rank > 49) and (", Elite Hunter")) or ", my Beginner") .. "! Here is your reward. Keep hunting and good luck!", TALKTYPE_PRIVATE_NP, false, cid, getThingPos(taskNPCuid))
  85.                 end
  86.             else
  87.                 if tasks[choiceId].repeatable then
  88.                     for i = 1, table.maxn(tasks[choiceId].rewards) do
  89.                         if isInArray({"storage", "stor", 5}, tasks[choiceId].rewards[i].type) then
  90.                             doPlayerPopupFYI(cid,"To repeat this mission again, fight with " .. storage_string[tasks[choiceId].rewards[i].values[1]] .. " first.")
  91.                             break
  92.                         end
  93.                         if i == table.maxn(tasks[choiceId].rewards) then
  94.                             doPlayerPopupFYI(cid,"You can't repeat this mission.")
  95.                         end
  96.                     end
  97.                 else
  98.                     doPlayerPopupFYI(cid,"You can't repeat this mission.")
  99.                 end
  100.                 sendTaskWindow(cid)
  101.             end
  102.         end
  103.     elseif buttonId == 255 then
  104.         doPlayerPopupFYI(cid,"Please use a button.")
  105.         sendTaskWindow(cid)
  106.     end
  107.    
  108. return true
  109. end
Advertisement
Add Comment
Please, Sign In to add comment