• 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!

TFS 1.2 Spell isnt executing when monster cast it

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
873
Solutions
2
Reaction score
49
Lua:
local combats = {}
local spellConfig = {
    combat = COMBAT_ENERGYDAMAGE,
    distanceEffect = 5,
    effect = 1,
    bounces = {
        max = 4,
        chance = 100,
        baseMult = 0.1,
        levelMult = 0.1,
        magicMult = 0.1
    }
}
for i = 1, spellConfig.bounces.max do
    combats[i] = Combat()
    combats[i]:setParameter(COMBAT_PARAM_TYPE, spellConfig.combat)
    combats[i]:setParameter(COMBAT_PARAM_EFFECT, spellConfig.effect)
    function onGetFormulaValues(player, level, magicLevel)
        local min = ((level * (1.0 + (spellConfig.bounces.levelMult * i))) + (magicLevel * (1.0 + (spellConfig.bounces.magicMult * i)))) * (1.0 + (spellConfig.bounces.baseMult * i))
        local max = ((level * (1.2 + (spellConfig.bounces.levelMult * i))) + (magicLevel * (1.2 + (spellConfig.bounces.magicMult * i)))) * (1.2 + (spellConfig.bounces.baseMult * i))
        return -min, -max
    end
    combats[i]:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
end
local function getClosedTarget(player, cid, targets)
    local targets = targets or {}
    if #targets >= spellConfig.bounces.max then
        return targets
    end
    local c = Creature(cid)
    if c then
        targets[#targets +1] = cid
        local spectators = Game.getSpectators(c:getPosition(), false, false, 4, 4, 4, 4)
        table.sort(spectators, function(a, b) return a:getPosition():getDistance(c:getPosition()) < b:getPosition():getDistance(c:getPosition()) end)
        for _, spectator in pairs(spectators) do
            local sid = spectator:getId()
            if (targets[#targets] ~= sid or not table.contains(targets, sid) and spectator:isMonster() or spectator:isPlayer()) then
                return getClosedTarget(player, sid, targets)
            end
        end
    end
    return targets
end

function onCastSpell(creature, variant)
    local targets = getClosedTarget(creature, variant:getNumber())
    for i, tid in pairs(targets) do
        if i ~= 1 and math.random(100) > spellConfig.bounces.chance then
            break
        end
        addEvent(function(cid, tid, atid)
            atid = targets[i+1]
            if creature:isPlayer() then
                local target = Creature(tid)
                if target then
                    if not atid then
                        creature:getPosition():sendDistanceEffect(target:getPosition(), spellConfig.distanceEffect)
                    else
                        local atarget = Creature(atid)
                        if atarget then
                            atarget:getPosition():sendDistanceEffect(target:getPosition(), spellConfig.distanceEffect)
                        end
                    end
                    combats[i]:execute(creature, Variant(tid))
                end
            end
        end, 200 * i-1, creature:getId(), tid, targets[i-1])
    end
    return #targets > 0
end
 
Back
Top