Advertisement
Guest User

Untitled

a guest
Mar 20th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.51 KB | None | 0 0
  1. function stat_onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
  2. if origin == 2 then return primaryDamage, primaryType, secondaryDamage, secondaryType end
  3. if not creature then return primaryDamage, primaryType, secondaryDamage, secondaryType end
  4. if not attacker then return primaryDamage, primaryType, secondaryDamage, secondaryType end
  5. local cid = creature:getId()
  6. local aid = attacker:getId()
  7.  
  8. -- weapon extra damage
  9. if attacker:isPlayer() then
  10. for i = CONST_SLOT_RIGHT, CONST_SLOT_LEFT do
  11. local item = attacker:getSlotItem(slots[i])
  12. if item then
  13. if STATS_SYSTEM_CONFIG.reqLvlBasedOnUpgrade then
  14. if item then
  15. if isWeapon(item:getUniqueId()) then
  16. local lv = attacker:getLevel()
  17. local rlv = item:getStatReqLevel()
  18. if rlv > lv then
  19. local ndmg = lv/rlv
  20. primaryDamage = math.floor(primaryDamage * ndmg)
  21. secondaryDamage = math.floor(secondaryDamage * ndmg)
  22. end
  23. end
  24. end
  25. end
  26.  
  27.  
  28. local cur_slots = item:getStatSlots()
  29. local it_id = ItemType(item:getId())
  30. if it_id:getWeaponType() > 0 and it_id:getWeaponType() ~= WEAPON_SHIELD then
  31. local slotc = item:getStatSlotCount()
  32. if slotc > 0 then
  33. for i = 1, slotc do
  34. if element_stats[cur_slots[i][1]] then
  35. if cur_slots[i][2]:match("%%") then
  36. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  37. local dmg = math.floor((primaryDamage * (tonumber(a..b)/100)))
  38. if dmg > 0 then
  39. doTargetCombatHealth(aid, cid, element_stats[cur_slots[i][1]].combat, 1, dmg, element_stats[cur_slots[i][1]].effect)
  40. end
  41. else
  42. local dmg = math.floor(math.random(0, tonumber(cur_slots[i][2])))
  43. if dmg > 0 then
  44. doTargetCombatHealth(aid, cid, element_stats[cur_slots[i][1]].combat, 1, dmg, element_stats[cur_slots[i][1]].effect)
  45. end
  46. end
  47. else
  48. if creature and attacker then
  49. if creature:getId() ~= attacker:getId() then
  50. if cur_slots[i][1] == 'drainHP' then
  51. if cur_slots[i][2]:match("%%") then
  52. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  53. local hp_d = math.floor((primaryDamage * (tonumber(a..b)/100)))
  54. if hp_d > 0 then
  55. doTargetCombatHealth(aid, cid, COMBAT_LIFEDRAIN, -hp_d, -hp_d, CONST_ME_MAGIC_RED)
  56. attacker:addHealth(hp_d)
  57. end
  58. else
  59. local hp_d = math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
  60. if hp_d > 0 then
  61. doTargetCombatHealth(aid, cid, COMBAT_LIFEDRAIN, -hp_d, -hp_d, CONST_ME_MAGIC_RED)
  62. attacker:addHealth(hp_d)
  63. end
  64. end
  65. end
  66.  
  67. if cur_slots[i][1] == 'drainMP' then
  68. if creature:getMana() > 0 then
  69. if cur_slots[i][2]:match("%%") then
  70. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  71. local mp_d = math.floor((primaryDamage * (tonumber(a..b)/100)))
  72. doTargetCombatMana(aid, cid, -mp_d, -mp_d)
  73. attacker:addMana(mp_d)
  74. else
  75. local mp_d = math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
  76. doTargetCombatMana(aid, cid, -mp_d, -mp_d)
  77. attacker:addMana(mp_d)
  78. end
  79. end
  80. end
  81. end
  82. end
  83.  
  84. if (creature:isPlayer() or isInArray(human_looktypes, creature:getOutfit().lookType)) and cur_slots[i][1] == 'humans' then
  85. if cur_slots[i][2]:match("%%") then
  86. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  87. primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
  88. else
  89. primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
  90. end
  91. end
  92.  
  93. if creature:isMonster() then
  94. local race = MonsterType(creature:getName()):getRace()
  95. local name = creature:getName():lower()
  96. if cur_slots[i][1] == 'insects' then
  97. if race == 1 then
  98. if cur_slots[i][2]:match("%%") then
  99. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  100. primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
  101. else
  102. primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
  103. end
  104. end
  105. elseif cur_slots[i][1] == 'animals' then
  106. if race == 2 and not isInArray(human_looktypes, creature:getOutfit().lookType) then
  107. if cur_slots[i][2]:match("%%") then
  108. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  109. primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
  110. else
  111. primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
  112. end
  113. end
  114. elseif cur_slots[i][1] == 'undeads' then
  115. if race == 3 then
  116. if cur_slots[i][2]:match("%%") then
  117. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  118. primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
  119. else
  120. primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
  121. end
  122. end
  123. elseif cur_slots[i][1] == 'elementals' then
  124. if race == 4 or race == 5 or name:match("elemental") then
  125. if cur_slots[i][2]:match("%%") then
  126. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  127. primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
  128. else
  129. primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
  130. end
  131. end
  132. elseif cur_slots[i][1] == 'dragons' then
  133. if name:match("dragon") then
  134. if cur_slots[i][2]:match("%%") then
  135. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  136. primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
  137. else
  138. primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
  139. end
  140. end
  141. elseif cur_slots[i][1] == 'lizards' then
  142. if name:match("lizard") or name:match("draken") then
  143. if cur_slots[i][2]:match("%%") then
  144. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  145. primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
  146. else
  147. primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
  148. end
  149. end
  150. end
  151. end
  152. end
  153. end
  154. end
  155. end
  156. end
  157. end
  158. end
  159.  
  160. -- armor elemental protection
  161. if creature:isPlayer() then
  162. for i = 1, #slots do
  163. local item = creature:getSlotItem(slots[i])
  164. if item then
  165. local it_id = ItemType(item:getId())
  166.  
  167. if it_id:getWeaponType() == WEAPON_SHIELD or it_id:getWeaponType() == 0 then
  168. local slotc = item:getStatSlotCount()
  169. if slotc > 0 then
  170. local cur_slots = item:getStatSlots()
  171. for i = 1, slotc do
  172. if element_stats[cur_slots[i][1]] then
  173. if cur_slots[i][2]:match("%%") then
  174. local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
  175. if primaryType == element_stats[cur_slots[i][1]] then
  176. primaryDamage = math.floor(primaryDamage - (primaryDamage * (tonumber(a..b)/100)))
  177. end
  178.  
  179. if secondaryType == element_stats[cur_slots[i][1]] then
  180. secondaryDamage = math.floor(secondaryDamage - (secondaryDamage * (tonumber(a..b)/100)))
  181. end
  182. else
  183. if primaryType == element_stats[cur_slots[i][1]] then
  184. primaryDamage = math.floor(primaryDamage - math.random(0, tonumber(cur_slots[i][2])))
  185. end
  186.  
  187. if secondaryType == element_stats[cur_slots[i][1]] then
  188. secondaryDamage = math.floor(secondaryDamage - math.random(0, tonumber(cur_slots[i][2])))
  189. end
  190. end
  191. end
  192. end
  193. end
  194. end
  195. end
  196. end
  197. end
  198. return primaryDamage, primaryType, secondaryDamage, secondaryType
  199. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement