local reflectTable = {
["rat"] = {
{combatType = COMBAT_FIREDAMAGE, reflectPercentage = 10}, -- add all types of elements you want to reflect
{combatType = COMBAT_ICEDAMAGE, reflectPercentage = 20}, -- if you only want to reflect 1 type of damage, only have 1 entry in this table.
{combatType = COMBAT_DEATHDAMAGE, reflectPercentage = 400} -- minimum reflectPercentage is 1.
},
["demon"] = { -- keep monster names lowercase
{combatType = COMBAT_FIREDAMAGE, reflectPercentage = 10}
}
}
local effects = {
[COMBAT_PHYSICALDAMAGE] = CONST_ME_DRAWBLOOD,
[COMBAT_ENERGYDAMAGE] = CONST_ME_ENERGYAREA,
[COMBAT_EARTHDAMAGE] = CONST_ME_POISONAREA,
[COMBAT_FIREDAMAGE] = CONST_ME_FIREAREA,
[COMBAT_ICEDAMAGE] = CONST_ME_ICEAREA,
[COMBAT_HOLYDAMAGE] = CONST_ME_HOLYAREA,
[COMBAT_DEATHDAMAGE] = CONST_ME_MORTAREA,
--[COMBAT_HEALING] = CONST_ME_MAGIC_GREEN
}
local healthChange = CreatureEvent("onHealthChange_MonsterReflect")
function healthChange.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if not creature then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
local reflectIndex = reflectTable[creature:getName():lower()]
if not reflectIndex then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
if attacker:isPlayer() then -- remove this check, if you want the monsters to reflect to all creatures, instead of only players
for i = 1, #reflectIndex do
if reflectIndex[i].combatType == primaryType then
local damage = math.floor((primaryDamage * (reflectIndex[i].reflectPercentage / 100)) + 0.5)
if damage < 1 then
damage = 1
end
doTargetCombat(creature, attacker, primaryType, -damage, -damage, effects[primaryType])
end
if reflectIndex[i].combatType == secondaryType then
local damage = math.floor((secondaryDamage * (reflectIndex[i].reflectPercentage / 100)) + 0.5)
if damage < 1 then
damage = 1
end
doTargetCombat(creature, attacker, secondaryType, -damage, -damage, effects[secondaryType])
end
end
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
healthChange:register()