Advertisement
Alscara

potionResist.lua

Jun 24th, 2015
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.75 KB | None | 0 0
  1. local res = {
  2.     {101, COMBAT_FIREDAMAGE}, {102, COMBAT_EARTHDAMAGE}, {103, COMBAT_ENERGYDAMAGE}, {104, COMBAT_ICEDAMAGE}, {105, COMBAT_HOLYDAMAGE}, {106, COMBAT_DEATHDAMAGE}, {107, COMBAT_PHYSICALDAMAGE}, {108, COMBAT_PHYSICALDAMAGE},
  3.     {109, COMBAT_FIREDAMAGE},{110, COMBAT_EARTHDAMAGE}, {111, COMBAT_ENERGYDAMAGE}, {112, COMBAT_ICEDAMAGE}, {113, COMBAT_HOLYDAMAGE}, {114, COMBAT_DEATHDAMAGE}, {115, COMBAT_PHYSICALDAMAGE}, {116, COMBAT_PHYSICALDAMAGE},
  4.     {117, COMBAT_FIREDAMAGE}, {118, COMBAT_EARTHDAMAGE}, {119, COMBAT_ENERGYDAMAGE}, {120, COMBAT_ICEDAMAGE}, {121, COMBAT_HOLYDAMAGE}, {122, COMBAT_DEATHDAMAGE}, {123, COMBAT_PHYSICALDAMAGE}, {124, COMBAT_PHYSICALDAMAGE},
  5.     {125, COMBAT_FIREDAMAGE}, {126, COMBAT_EARTHDAMAGE}, {127, COMBAT_ENERGYDAMAGE}, {128, COMBAT_ICEDAMAGE}, {129, COMBAT_HOLYDAMAGE}, {130, COMBAT_DEATHDAMAGE}, {131, COMBAT_PHYSICALDAMAGE}, {132, COMBAT_PHYSICALDAMAGE},
  6. }
  7.  
  8. local refs = {
  9.     [COMBAT_PHYSICALDAMAGE] = CONST_ME_DRAWBLOOD,
  10.     [COMBAT_ENERGYDAMAGE] = CONST_ME_ENERGYAREA,
  11.     [COMBAT_EARTHDAMAGE] = CONST_ME_POISONAREA,
  12.     [COMBAT_FIREDAMAGE] = CONST_ME_FIREAREA,
  13.     [COMBAT_ICEDAMAGE] = CONST_ME_ICEAREA,
  14.     [COMBAT_HOLYDAMAGE] = CONST_ME_HOLYAREA,
  15.     [COMBAT_DEATHDAMAGE] = CONST_ME_MORTAREA
  16. }
  17. function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
  18.     if creature:isPlayer() then
  19.         if primaryType == COMBAT_HEALING then
  20.             return primaryDamage, primaryType, secondaryDamage, secondaryType
  21.         end
  22.         if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 11) then
  23.             if primaryType == COMBAT_DROWNDAMAGE then
  24.                 primaryDamage = 0
  25.             end
  26.             if secondaryType == COMBAT_DROWNDAMAGE then
  27.                 secondaryDamage = 0
  28.             end
  29.         end
  30.         for i = 1, 8 do -- resist
  31.             if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, res[i][1]) then
  32.                 if primaryType == res[i][2] or i == 8 then
  33.                     primaryDamage = (primaryDamage - (primaryDamage * (creature:getStorageValue(5) / 100)))
  34.                 end
  35.                 if secondaryType == res[i][2] or i == 8 then
  36.                     secondaryDamage = (secondaryDamage - (secondaryDamage * (creature:getStorageValue(5) / 100)))
  37.                 end
  38.             end
  39.         end
  40.         for i = 9, 16 do -- reflect
  41.             if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, res[i][1]) then
  42.                 if not attacker then
  43.                     return primaryDamage, primaryType, secondaryDamage, secondaryType
  44.                 end
  45.                 if primaryType == res[i][2] or i == 16 then
  46.                     local a = math.floor(primaryDamage * (creature:getStorageValue(5) / 100))
  47.                     if attacker:isMonster() then
  48.                         local m = MonsterType(attacker:getName())
  49.                         local e = m:getElementList()
  50.                         local f = m:getCombatImmunities()
  51.                         if type(f) == "number" then
  52.                             if f == primaryType then
  53.                                 a = 0
  54.                             end
  55.                         else
  56.                             for i, j in pairs(f) do
  57.                                 if i == primaryType then
  58.                                     a = 0
  59.                                 end
  60.                             end
  61.                         end
  62.                         if type(e) == "number" then
  63.                             if e == primaryType then
  64.                                 if e > 0 then
  65.                                     a = (a - (a * (e / 100)))
  66.                                 else
  67.                                     a = (a + (a * ((e * -1) / 100)))
  68.                                 end
  69.                             end
  70.                         else
  71.                             for i, j in pairs(e) do
  72.                                 if i == primaryType then
  73.                                     if j > 0 then
  74.                                         a = (a - (a * (j / 100)))
  75.                                     else
  76.                                         a = (a + (a * ((j * -1) / 100)))
  77.                                     end
  78.                                 end
  79.                             end
  80.                         end
  81.                     end
  82.                     doTargetCombatHealth(creature, attacker, primaryType, a, a, refs[primaryType])
  83.                 end
  84.             end
  85.         end
  86.         for i = 17, 24 do -- deflect
  87.             if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, res[i][1]) then
  88.                 if not attacker then
  89.                     return primaryDamage, primaryType, secondaryDamage, secondaryType
  90.                 end
  91.                 if primaryType == res[i][2] or i == 24 then
  92.                     local a = math.floor(primaryDamage * (creature:getStorageValue(5) / 100))
  93.                     if attacker:isMonster() then
  94.                    
  95.                         local m = MonsterType(attacker:getName())
  96.                         local e = m:getElementList()
  97.                         local f = m:getCombatImmunities()
  98.                         if type(f) == "number" then
  99.                             if f == primaryType then
  100.                                 a = 0
  101.                             end
  102.                         else
  103.                             for i, j in pairs(f) do
  104.                                 if i == primaryType then
  105.                                     a = 0
  106.                                 end
  107.                             end
  108.                         end
  109.                         if type(e) == "number" then
  110.                             if e == primaryType then
  111.                                 if e > 0 then
  112.                                     a = (a - (a * (e / 100)))
  113.                                 else
  114.                                     a = (a + (a * ((e * -1) / 100)))
  115.                                 end
  116.                             end
  117.                         else
  118.                             for i, j in pairs(e) do
  119.                                 if i == primaryType then
  120.                                     if j > 0 then
  121.                                         a = (a - (a * (j / 100)))
  122.                                     else
  123.                                         a = (a + (a * ((j * -1) / 100)))
  124.                                     end
  125.                                 end
  126.                             end
  127.                         end
  128.                     end
  129.                     doTargetCombatHealth(creature, attacker, primaryType, a, a, refs[primaryType])
  130.                     primaryDamage = (primaryDamage - (primaryDamage * (creature:getStorageValue(5) / 100)))
  131.                     secondaryDamage = (secondaryDamage - (secondaryDamage * (creature:getStorageValue(5) / 100)))
  132.                 end
  133.             end
  134.         end
  135.         for i = 25, 32 do
  136.             if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, res[i][1]) then
  137.                 if primaryType == res[i][2] or i == 32 then
  138.                     local a = math.floor(primaryDamage * (creature:getStorageValue(5) / 100))
  139.                     creature:addHealth(a)
  140.                     primaryDamage = (primaryDamage - (primaryDamage * (creature:getStorageValue(5) / 100)))
  141.                     secondaryDamage = (secondaryDamage - (secondaryDamage * (creature:getStorageValue(5) / 100)))
  142.                 end
  143.             end
  144.         end
  145.     end
  146.     if primaryDamage == 0 and secondaryDamage == 0 and creature:isPlayer() and not creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 20) then
  147.         creature:getPosition():sendMagicEffect(CONST_ME_POFF)
  148.     end
  149.     return primaryDamage, primaryType, secondaryDamage, secondaryType
  150. end
  151.  
  152. function onManaChange(creature, attacker, manaChange, origin)
  153.     return manaChange
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement