-- Elemental Damage Bonus
-- Since we need to cancel the damage and use doTargetCombatHealth
-- that calls onStatsChange again, lets hold which player is actually
-- taking damage and ignore the next onStatsChange
local ignoreNext = {}
-- Storages
-- As local for simplicity. But can be global
local STRG_BONUS_DEF_EARTH = 294242
local STRG_BONUS_DEF_EARTH_TIME = 294243
function onStatsChange(cid, attacker, type, combat, value)
if ignoreNext[cid] then -- onStatsChange already processed for this player, ignore
ignoreNext[cid] = nil
return true
end
-- No other creature is in the action. Ignore
if not attacker then
return true
end
-- Not a damage? Just ignore
if not type == STATSCHANGE_HEALTHLOSS and not type == STATSCHANGE_MANALOSS then
return true
end
-- Earth damage, lets check for bonus
if combat == COMBAT_EARTHDAMAGE then
-- Lets check defense bonus first
local hasDefBonus = getCreatureStorage(cid, STRG_BONUS_DEF_EARTH_TIME) > os.time()
if hasDefBonus then
-- Ok, bonus is enabled for now, lets get how much of it
local defBonus = getCreatureStorage(cid, STRG_BONUS_DEF_EARTH)
defBonus = (defBonus * value / 100) -- Lets get as percent
value = value - defBonus -- Reduce the damage by the bonus percent
if value > 0 then -- If value is less than 0 just cancel the damage
-- if more than 0, lets do another damage event
-- but first, don't forget to make it be ignored
ignoreNext[cid] = true
doTargetCombatHealth(attacker, cid, type, -value, -value, effect) -- Do another damage event
end
return false -- Lets cancel this damage
end
end
return true
end