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

Lua Spells chain

alcapone

Member
Joined
Jan 13, 2021
Messages
247
Reaction score
19
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_WHITE_ENERGY_SPARK)

function onCastSpell(creature, var)
    local target = Creature(var.number)
    if not target then return false end
    local creaturePos = creature:getPosition()
    local path = creaturePos:getPathTo(target:getPosition(), 0, 0, true, true, 8)
    if not path or #path == 0 then return false end
    for i=1, #path do
        creaturePos:getNextPosition(path[i], 1)
        creaturePos:sendMagicEffect(CONST_ME_WHITE_ENERGY_SPARK)
    end
    return combat:execute(creature, var)
end


this magic creates a chain to the target but only the target takes the damage I would like the entire path that the chain passes to suffer damage
 
function chain(creature, effect, minDamage, maxDamage, combatType)
local spectators = Game.getSpectators(creature:getPosition(), false, false, 9, 9, 6, 6)
local totalTarget = 0
local targets = {}
for _, spectador in pairs(spectators) do
if spectador:isPlayer() then
targets[#targets + 1] = spectador
end
end
local lastChain = creature
local lastChainPosition = creature:getPosition()
local closestTarget, closestTargetIndex, closestTargetPosition
local path, tempPosition, updateLastChain
while (totalTarget < 5 and #targets > 0) do
closestTarget = nil
for index, target in pairs(targets) do
tempPosition = target:getPosition()
if not closestTarget or getDiagonalDistance(lastChain:getPosition(), tempPosition) < getDiagonalDistance(lastChain:getPosition(), closestTargetPosition) then
closestTarget = target
closestTargetIndex = index
closestTargetPosition = tempPosition
end
end
table.remove(targets, closestTargetIndex)
updateLastChain = false
if lastChainPosition:getDistance(closestTargetPosition) == 1 then
updateLastChain = true
else
path = lastChainPosition:getPathTo(closestTargetPosition, 0, 1, true, true, 9)
if path and #path > 0 then
for i=1, #path do
lastChainPosition:getNextPosition(path, 1)
lastChainPosition:sendMagicEffect(effect)
end
updateLastChain = true
end
end
if updateLastChain then
doTargetCombatHealth(creature, closestTarget, combatType, -minDamage, -maxDamage, effect)
closestTargetPosition:sendMagicEffect(effect)
lastChain = closestTarget
lastChainPosition = closestTargetPosition
totalTarget = totalTarget + 1
end
end
return totalTarget
end

function onCastSpell(creature, variant)
local min = 500
local max = 1000
local total = chain(creature, CONST_ME_WHITE_ENERGY_SPARK, min, max, COMBAT_DEATHDAMAGE)
if total > 0 then
return true
end
end
 
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_EARTHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_GREEN_ENERGY_SPARK)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLEARTH)

function onTargetCreatureML(creature, target)
    local master = target:getMaster()
    if target:isPlayer() and not master
            or master and master:isPlayer() then
            local list = getSpectators(Position(target:getPosition()), 4, 4, false)
            if list then
                for index, closeplayerlist in ipairs(list) do
                if Player(closeplayerlist) then
                    if isSightClear(Position(target:getPosition()), Position(Player(closeplayerlist):getPosition())) and not(Player(closeplayerlist):getName() == target:getName()) then
                        chainPositionML(target:getPosition(), Player(closeplayerlist), creature)
                    end
                end
                end           
            end
            
    end
    return true
end

function chainPositionML(pos1, bouncer, boss)
    addEvent(function()
if bouncer:getPosition().x > pos1.x then
mlnewx = pos1.x + 1
elseif bouncer:getPosition().x < pos1.x then
mlnewx = pos1.x - 1
else
mlnewx = pos1.x
end
if bouncer:getPosition().y > pos1.y then
mlnewy = pos1.y + 1
elseif bouncer:getPosition().y < pos1.y then
mlnewy = pos1.y - 1
else
mlnewy = pos1.y
end
if mlnewx == pos1.x and mlnewy == pos1.y then
doTargetCombatHealth(boss, bouncer, COMBAT_DEATHDAMAGE, -1, -2, CONST_ME_WHITE_ENERGY_SPARK)
return
end
Position(mlnewx, mlnewy, pos1.z):sendMagicEffect(CONST_ME_WHITE_ENERGY_SPARK)
chainPositionML(Position(mlnewx, mlnewy, pos1.z), bouncer, boss)
    end, 100)
end
    
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreatureML")

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end

I was using this script and found out that if the player (second target) dies or gets kicked before the chain reaches him, the server goes down.
 
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_EARTHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_GREEN_ENERGY_SPARK)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLEARTH)

function onTargetCreatureML(creature, target)
    local master = target:getMaster()
    if target:isPlayer() and not master
            or master and master:isPlayer() then
            local list = getSpectators(Position(target:getPosition()), 4, 4, false)
            if list then
                for index, closeplayerlist in ipairs(list) do
                if Player(closeplayerlist) then
                    if isSightClear(Position(target:getPosition()), Position(Player(closeplayerlist):getPosition())) and not(Player(closeplayerlist):getName() == target:getName()) then
                        chainPositionML(target:getPosition(), Player(closeplayerlist), creature)
                    end
                end
                end          
            end
           
    end
    return true
end

function chainPositionML(pos1, bouncer, boss)
    addEvent(function()
if bouncer:getPosition().x > pos1.x then
mlnewx = pos1.x + 1
elseif bouncer:getPosition().x < pos1.x then
mlnewx = pos1.x - 1
else
mlnewx = pos1.x
end
if bouncer:getPosition().y > pos1.y then
mlnewy = pos1.y + 1
elseif bouncer:getPosition().y < pos1.y then
mlnewy = pos1.y - 1
else
mlnewy = pos1.y
end
if mlnewx == pos1.x and mlnewy == pos1.y then
doTargetCombatHealth(boss, bouncer, COMBAT_DEATHDAMAGE, -1, -2, CONST_ME_WHITE_ENERGY_SPARK)
return
end
Position(mlnewx, mlnewy, pos1.z):sendMagicEffect(CONST_ME_WHITE_ENERGY_SPARK)
chainPositionML(Position(mlnewx, mlnewy, pos1.z), bouncer, boss)
    end, 100)
end
   
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreatureML")

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end

I was using this script and found out that if the player (second target) dies or gets kicked before the chain reaches him, the server goes down.
 
Back
Top