Advertisement
Oskar1121

Untitled

Sep 15th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <mod name="Task System" version="0.4.0" author="Oskar" contact="oskar1121@gmail.com" enabled="yes">
  3. <config name="tasks_conf"><![CDATA[
  4. REWARD_ITEM = 0
  5. REWARD_EXP = 1
  6. REWARD_MONEY = 2
  7. REWARD_ADDON = 3
  8. REWARD_SKILL = 4
  9. REWARD_STORAGE = 5
  10. REWARD_LEVEL = 6
  11.  
  12. AUTO_TASK_LIST = {
  13. [1] = { details = {'wolf'}, totalKills = 20, storage = 2001, name = 'wolves',
  14. rewards = {REWARD_ITEM, 2152, 5, REWARD_EXP, 0, 500}, -- 250 expa/500 gp -->
  15. requiredLevel = {1, 50000}, repeatable = false},
  16. [2] = { details = {'orc', 'orc spearman', 'orc warrior'}, totalKills = 1000, storage = 2002, name = 'orcs',
  17. rewards = {REWARD_MONEY, 2152, 5, REWARD_EXP, 0, 500}, -- 250 expa/500 gp -->
  18. requiredLevel = {1, 50000}, repeatable = false},
  19. }
  20.  
  21. --[[function getDetails(cid, status, realCount)
  22. local count, detail, complete = #status.details / 2, '', true
  23.  
  24. local subStorage = getCreatureStorage(cid, countStorage)
  25.  
  26. local killsCount = subStorage ~= -1 and tostring(subStorage):explode('_')
  27. for i = 1, count do
  28. if status.var == TYPE_KILL and (not killsCount or ((tonumber(killsCount[i + 1]) or 0) < status.details[i * 2])) then
  29. complete = false
  30. elseif status.var == TYPE_ITEMBACK and getPlayerItemCount(cid, status.details[i * 2 - 1]) < status.details[i * 2] then
  31. complete = false
  32. end
  33.  
  34. if status.var == TYPE_KILL then
  35. detail = detail .. (realCount and tonumber(killsCount[i + 1]) or status.details[i * 2]) .. 'x of ' .. status.details[i * 2 - 1]
  36. elseif status.var == TYPE_ITEMBACK then
  37. detail = detail .. status.details[i * 2] .. 'x of ' .. getItemNameById(status.details[i * 2 - 1])
  38. end
  39.  
  40. if i < count - 1 and count > 2 then
  41. detail = detail .. ', '
  42. elseif i == count - 1 and count > 1 then
  43. detail = detail .. ' and '
  44. end
  45. end
  46.  
  47. return detail, complete
  48. end]]
  49.  
  50.  
  51.  
  52.  
  53. ]]></config>
  54.  
  55. <event type="kill" name="taskKill" event="script"><![CDATA[
  56. domodlib('tasks_conf')
  57.  
  58. local function doTakeReward(cid, var)
  59. for i = 1, #var / 3 do
  60. if var[i * 3 - 2] == REWARD_ITEM then
  61. doPlayerAddItem(cid, var[i * 3 - 1], var[i * 3], true)
  62. elseif var[i * 3 - 2] == REWARD_EXP then
  63. doAddExp(cid, var[i * 3])
  64. elseif var[i * 3 - 2] == REWARD_STORAGE then
  65. doCreatureSetStorage(cid, var[i * 3 - 1], var[i * 3])
  66. elseif var[i * 3 - 2] == REWARD_MONEY then
  67. doPlayerAddMoney(cid, var[i * 3])
  68. elseif var[i * 3 - 2] == REWARD_SKILL then
  69. doPlayerSetSkill(cid, var[i * 3 - 1], getPlayerSkillLevel(cid, var[i * 3 - 1]) + var[i * 3])
  70. elseif var[i * 3 - 2] == REWARD_ADDON then
  71. doPlayerAddOutfit(cid, (getPlayerSex(cid) == 0 and var[i * 3 - 1][1] or var[i * 3 - 1][2]), var[i * 3])
  72. elseif var[i * 3 - 2] == REWARD_LEVEL then
  73. doPlayerAddLevel(cid, var[i * 3])
  74. end
  75. end
  76. end
  77.  
  78. local function getTaskByName(name)
  79. for _, v in pairs(AUTO_TASK_LIST) do
  80. for i = 1, #v.details / 2 do
  81. if name == v.details[i * 2 - 1]:lower() then
  82. return v
  83. end
  84. end
  85. end
  86.  
  87. return false
  88. end
  89.  
  90. function onKill(cid, target)
  91. if not isMonster(target) or not isPlayer(cid) then
  92. return true
  93. end
  94.  
  95. local var = getTaskByName(getCreatureName(target):lower())
  96. if not var then
  97. return true
  98. end
  99.  
  100. local storage = math.max(0, getCreatureStorage(cid, var.storage))
  101. if storage >= var.totalKills then
  102. return true
  103. end
  104.  
  105. storage = storage + 1
  106. if storage >= var.totalKills then
  107. doTakeReward(cid, var.rewards)
  108. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations! You finished ' .. var.name .. ' task.')
  109. else
  110. doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have killed ' .. var.name .. '. [' .. storage .. '/' .. var.totalKills .. '].')
  111. end
  112.  
  113. doCreatureSetStorage(cid, var.storage, storage)
  114. return true
  115. end
  116. ]]></event>
  117.  
  118. <talkaction words='!mission' event='script'><![CDATA[
  119. domodlib('tasks_conf')
  120.  
  121. function onSay(cid, words, param, channel)
  122. local id = tonumber(getCreatureStorage(cid, storage))
  123. local status = task[id]
  124. local message = ''
  125. if status then
  126. local detail, complete = getDetails(cid, status, true)
  127. message = 'Mission State [ ' .. id .. '] - ' .. detail
  128. if status.var == TYPE_KILL then
  129. message = message .. ' killed.'
  130. elseif status.var == TYPE_ITEMBACK then
  131. message = message .. ' gathered.'
  132. end
  133. else
  134. message = 'You are not started any task.'
  135. end
  136.  
  137. doPlayerPopupFYI(cid, message)
  138. end
  139.  
  140. ]]></talkaction>
  141.  
  142. <event type="login" name="taskLogin" event="script"><![CDATA[
  143.  
  144. function onLogin(cid)
  145. registerCreatureEvent(cid, 'taskKill')
  146. return true
  147. end
  148. ]]></event>
  149. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement