Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function stat_onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
- if origin == 2 then return primaryDamage, primaryType, secondaryDamage, secondaryType end
- if not creature then return primaryDamage, primaryType, secondaryDamage, secondaryType end
- if not attacker then return primaryDamage, primaryType, secondaryDamage, secondaryType end
- local cid = creature:getId()
- local aid = attacker:getId()
- -- weapon extra damage
- if attacker:isPlayer() then
- for i = CONST_SLOT_RIGHT, CONST_SLOT_LEFT do
- local item = attacker:getSlotItem(slots[i])
- if item then
- if STATS_SYSTEM_CONFIG.reqLvlBasedOnUpgrade then
- if item then
- if isWeapon(item:getUniqueId()) then
- local lv = attacker:getLevel()
- local rlv = item:getStatReqLevel()
- if rlv > lv then
- local ndmg = lv/rlv
- primaryDamage = math.floor(primaryDamage * ndmg)
- secondaryDamage = math.floor(secondaryDamage * ndmg)
- end
- end
- end
- end
- local cur_slots = item:getStatSlots()
- local it_id = ItemType(item:getId())
- if it_id:getWeaponType() > 0 and it_id:getWeaponType() ~= WEAPON_SHIELD then
- local slotc = item:getStatSlotCount()
- if slotc > 0 then
- for i = 1, slotc do
- if element_stats[cur_slots[i][1]] then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- local dmg = math.floor((primaryDamage * (tonumber(a..b)/100)))
- if dmg > 0 then
- doTargetCombatHealth(aid, cid, element_stats[cur_slots[i][1]].combat, 1, dmg, element_stats[cur_slots[i][1]].effect)
- end
- else
- local dmg = math.floor(math.random(0, tonumber(cur_slots[i][2])))
- if dmg > 0 then
- doTargetCombatHealth(aid, cid, element_stats[cur_slots[i][1]].combat, 1, dmg, element_stats[cur_slots[i][1]].effect)
- end
- end
- else
- if creature and attacker then
- if creature:getId() ~= attacker:getId() then
- if cur_slots[i][1] == 'drainHP' then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- local hp_d = math.floor((primaryDamage * (tonumber(a..b)/100)))
- if hp_d > 0 then
- doTargetCombatHealth(aid, cid, COMBAT_LIFEDRAIN, -hp_d, -hp_d, CONST_ME_MAGIC_RED)
- attacker:addHealth(hp_d)
- end
- else
- local hp_d = math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
- if hp_d > 0 then
- doTargetCombatHealth(aid, cid, COMBAT_LIFEDRAIN, -hp_d, -hp_d, CONST_ME_MAGIC_RED)
- attacker:addHealth(hp_d)
- end
- end
- end
- if cur_slots[i][1] == 'drainMP' then
- if creature:getMana() > 0 then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- local mp_d = math.floor((primaryDamage * (tonumber(a..b)/100)))
- doTargetCombatMana(aid, cid, -mp_d, -mp_d)
- attacker:addMana(mp_d)
- else
- local mp_d = math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
- doTargetCombatMana(aid, cid, -mp_d, -mp_d)
- attacker:addMana(mp_d)
- end
- end
- end
- end
- end
- if (creature:isPlayer() or isInArray(human_looktypes, creature:getOutfit().lookType)) and cur_slots[i][1] == 'humans' then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
- else
- primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
- end
- end
- if creature:isMonster() then
- local race = MonsterType(creature:getName()):getRace()
- local name = creature:getName():lower()
- if cur_slots[i][1] == 'insects' then
- if race == 1 then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
- else
- primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
- end
- end
- elseif cur_slots[i][1] == 'animals' then
- if race == 2 and not isInArray(human_looktypes, creature:getOutfit().lookType) then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
- else
- primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
- end
- end
- elseif cur_slots[i][1] == 'undeads' then
- if race == 3 then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
- else
- primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
- end
- end
- elseif cur_slots[i][1] == 'elementals' then
- if race == 4 or race == 5 or name:match("elemental") then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
- else
- primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
- end
- end
- elseif cur_slots[i][1] == 'dragons' then
- if name:match("dragon") then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
- else
- primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
- end
- end
- elseif cur_slots[i][1] == 'lizards' then
- if name:match("lizard") or name:match("draken") then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- primaryDamage = primaryDamage + math.floor((primaryDamage * (tonumber(a..b)/100)))
- else
- primaryDamage = primaryDamage + math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- -- armor elemental protection
- if creature:isPlayer() then
- for i = 1, #slots do
- local item = creature:getSlotItem(slots[i])
- if item then
- local it_id = ItemType(item:getId())
- if it_id:getWeaponType() == WEAPON_SHIELD or it_id:getWeaponType() == 0 then
- local slotc = item:getStatSlotCount()
- if slotc > 0 then
- local cur_slots = item:getStatSlots()
- for i = 1, slotc do
- if element_stats[cur_slots[i][1]] then
- if cur_slots[i][2]:match("%%") then
- local a, b = cur_slots[i][2]:match('([+-])(%d+)%%')
- if primaryType == element_stats[cur_slots[i][1]] then
- primaryDamage = math.floor(primaryDamage - (primaryDamage * (tonumber(a..b)/100)))
- end
- if secondaryType == element_stats[cur_slots[i][1]] then
- secondaryDamage = math.floor(secondaryDamage - (secondaryDamage * (tonumber(a..b)/100)))
- end
- else
- if primaryType == element_stats[cur_slots[i][1]] then
- primaryDamage = math.floor(primaryDamage - math.random(0, tonumber(cur_slots[i][2])))
- end
- if secondaryType == element_stats[cur_slots[i][1]] then
- secondaryDamage = math.floor(secondaryDamage - math.random(0, tonumber(cur_slots[i][2])))
- end
- end
- end
- end
- end
- end
- end
- end
- end
- return primaryDamage, primaryType, secondaryDamage, secondaryType
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement