• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Expansive Spell with lifeleech and manaleech

Sarah Wesker

ƐƖєgαηт Sуηтαx ❤
Staff member
TFS Developer
Support Team
Joined
Mar 16, 2017
Messages
1,421
Solutions
155
Reaction score
1,985
Location
London
GitHub
MillhioreBT
Twitch
millhiorebt
data/scripts/exevo_test.lua
Lua:
local lifeLeechAmount = 50
local manaLeechAmount = 50
local creaturesCount = 0 -- It is only used to calculate the number of creatures that were affected, leave it at 0

local healthEvent = CreatureEvent("leechHealth")

function healthEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    creature:unregisterEvent("leechHealth")
    if primaryType == COMBAT_HEALING then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if attacker and attacker:isPlayer() then
        local hpLeechAmount = math.floor((primaryDamage * (lifeLeechAmount / 100)) / creaturesCount)
        if hpLeechAmount > 0 then
            attacker:addHealth(hpLeechAmount)
            attacker:sendTextMessage(MESSAGE_HEALED, string.format("You leech %d health.", hpLeechAmount))
        end

        local mpLeechAmount = math.floor((primaryDamage * (manaLeechAmount / 100)) / creaturesCount)
        if mpLeechAmount > 0 then
            attacker:addMana(mpLeechAmount)
            attacker:sendTextMessage(MESSAGE_HEALED, string.format("You leech %d mana.", mpLeechAmount))
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

healthEvent:register()

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat:setArea(createCombatArea(AREA_CIRCLE5X5))

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 8) + 50
    local max = (level / 5) + (magicLevel * 12) + 75
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onTargetTile(caster, position)
    local tile = Tile(position)
    if not tile then
        return
    end

    local creatureCount = tile:getCreatureCount()
    if creatureCount == 0 then
        return
    end

    for _, creature in pairs(tile:getCreatures()) do
        if creature ~= caster then
            creature:registerEvent("leechHealth")
            creaturesCount = creaturesCount + 1
        end
    end
end

combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

local spell = Spell(SPELL_INSTANT)

function spell.onCastSpell(creature, variant, isHotkey)
    if combat:execute(creature, variant) then
        creaturesCount = 0
        return true
    end
    return false
end

spell:name("Hells")
spell:words("exevo test2")
spell:group("attack")
spell:vocation("sorcerer", "master sorcerer")
spell:id(24)
spell:cooldown(1000)
spell:groupCooldown(1000)
spell:mana(100)
spell:isPremium(true)
spell:register()
 
Thanks for scripts! I've used it as a base and added the part which will unregister an event after 20 seconds.
The question is: don't you need to pass hpLeechAmount / manaLeechAmount in if condition (or in display function) wrapped in math.abs? Isn't it negative number since it's damage? (health reduction in other words).

Best regards, Vitox.
 
Back
Top