• 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 nova spell

manestick

New Member
Joined
Oct 10, 2021
Messages
10
Reaction score
4
GitHub
manestick
I created a new healing spell that heals over 10 seconds, with an interval of 0.5 seconds between each heal. It works differently: when the player uses the spell, the character needs to stay still for the healing to occur, like meditating. If the player moves, the healing stops. Everything is working fine up until this point, but the problem is that when the player uses this spell and logs out or dies, the server crashes.

LUA:
-- Função para criar e configurar o combate de cura
local function createHealingCombat()
    local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
    setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
    setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
    setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, 15)  -- Efeito visual (ajustável)
    return combat
end

-- Criar um único combate de cura
local combat = createHealingCombat()

-- Função para verificar se o jogador se moveu
local function checkMovement(cid, startPos)
    local currentPos = getCreaturePosition(cid)
    if currentPos.x ~= startPos.x or currentPos.y ~= startPos.y or currentPos.z ~= startPos.z then
        return true -- Jogador se moveu
    end
    return false -- Jogador não se moveu
end

-- Função para obter o Magic Level (caso o Magic Level esteja armazenado de outra forma no seu servidor, ajuste esta parte)
local function getMagicLevel(cid)
    -- Tentando acessar o Magic Level via storage
    local magicLevel = getPlayerStorageValue(cid, 1000)  -- Substitua 1000 pelo ID correto do storage no seu servidor
    if magicLevel == -1 then
        -- Se o Magic Level não estiver no storage, podemos usar uma lógica alternativa (como o level)
        return 0  -- Retorna 0 como fallback
    end
    return magicLevel
end

-- Função para aplicar a cura
local function applyHealing(cid, var)
    local startPos = getCreaturePosition(cid) -- Salvar a posição inicial do jogador
    local healingInProgress = true  -- Flag para monitorar se a cura ainda está em progresso

    -- Função para aplicar a cura com base no level e Magic Level
    local function applyCure(interval, i)
        if not healingInProgress then
            return
        end

        if not checkMovement(cid, startPos) then
            -- Calculando a cura com base no level e Magic Level
            local level = getPlayerLevel(cid)
            local magicLevel = getMagicLevel(cid)

            -- A cura será influenciada por Level e Magic Level
            -- A fórmula ajustada:
            local healingAmount = math.floor((level * 0.8) + (magicLevel * 1.8))  -- Ajuste a fórmula conforme necessário

            -- Definindo a fórmula de cura
            setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 0, healingAmount, 0, healingAmount)
            doCombat(cid, combat, var)
        else
            healingInProgress = false  -- Interromper a cura se o jogador se mover
        end
    end

    -- Aplicar os efeitos de cura com intervalo reduzido, 20 vezes
    for i = 0, 19 do
        -- Aplique a cura a cada 0.5 segundo (intervalo reduzido)
        addEvent(function()
            applyCure(i * 500, i)  -- Intervalo de 0.5 segundo entre as curas
        end, i * 500)
    end
end

function onCastSpell(cid, var)
    -- Interromper a cura anterior se o feitiço for chamado novamente
    applyHealing(cid, var)
    return true
end
 
In all of your functions you need to confirm that cid still exists before using it.
So basically just add this check directly under each function call.

0.x server
LUA:
if not isCreature(cid) then
    return
end
1.x server
LUA:
if not cid:isCreature() then
    return
end
 
Em todas as suas funções, você precisa confirmar se o cid ainda existe antes de usá-lo.
Então, basicamente, basta adicionar esta seleção diretamente abaixo de cada chamada de função.

Servidor 0.x
[código=lua]
se não for isCreature(cid) então
retornar
fim[/código]
Servidor 1.x
[código=lua]
se não cid:isCreature() então
retornar
fim[/código]
Fiz essa alteração, mas o servidor continua trabalhando e depois cai. TFS 1.3
LUA:
-- Função para criar e configurar o combate de cura
local function createHealingCombat()
    local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
    setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
    setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
    setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, 15)  -- Efeito visual (ajustável)
    return combat
end

-- Criar um único combate de cura
local combat = createHealingCombat()

-- Função para verificar se o jogador se moveu
local function checkMovement(cid, startPos)
    local currentPos = getCreaturePosition(cid)
    if not cid:isCreature() then return false end  -- Verifica se o cid ainda é uma criatura
    if currentPos.x ~= startPos.x or currentPos.y ~= startPos.y or currentPos.z ~= startPos.z then
        return true -- Jogador se moveu
    end
    return false -- Jogador não se moveu
end

-- Função para obter o Magic Level (caso o Magic Level esteja armazenado de outra forma no seu servidor, ajuste esta parte)
local function getMagicLevel(cid)
    if not cid:isCreature() then return 0 end  -- Verifica se o cid ainda é uma criatura
    -- Tentando acessar o Magic Level via storage
    local magicLevel = getPlayerStorageValue(cid, 1000)  -- Substitua 1000 pelo ID correto do storage no seu servidor
    if magicLevel == -1 then
        -- Se o Magic Level não estiver no storage, podemos usar uma lógica alternativa (como o level)
        return 0  -- Retorna 0 como fallback
    end
    return magicLevel
end

-- Função para aplicar a cura
local function applyHealing(cid, var)
    if not cid:isCreature() then return end  -- Verifica se o cid ainda é uma criatura

    local startPos = getCreaturePosition(cid) -- Salvar a posição inicial do jogador
    local healingInProgress = true  -- Flag para monitorar se a cura ainda está em progresso

    -- Função para aplicar a cura com base no level e Magic Level
    local function applyCure(interval, i)
        if not cid:isCreature() then return end  -- Verifica se o cid ainda é uma criatura
        if not healingInProgress then
            return
        end

        if not checkMovement(cid, startPos) then
            -- Calculando a cura com base no level e Magic Level
            local level = getPlayerLevel(cid)
            local magicLevel = getMagicLevel(cid)

            -- A cura será influenciada por Level e Magic Level
            -- A fórmula ajustada:
            local healingAmount = math.floor((level * 0.8) + (magicLevel * 1.8))  -- Ajuste a fórmula conforme necessário

            -- Definindo a fórmula de cura
            setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 0, healingAmount, 0, healingAmount)
            doCombat(cid, combat, var)
        else
            healingInProgress = false  -- Interromper a cura se o jogador se mover
        end
    end

    -- Aplicar os efeitos de cura com intervalo reduzido, 20 vezes
    for i = 0, 19 do
        -- Aplique a cura a cada 0.5 segundo (intervalo reduzido)
        addEvent(function()
            if not cid:isCreature() then return end  -- Verifica se o cid ainda é uma criatura
            applyCure(i * 500, i)  -- Intervalo de 0.5 segundo entre as curas
        end, i * 500)
    end
end

function onCastSpell(cid, var)
    if not cid:isCreature() then return false end  -- Verifica se o cid ainda é uma criatura
    -- Interromper a cura anterior se o feitiço for chamado novamente
    applyHealing(cid, var)
    return true
end
 
Last edited:
Fiz essa alteração, mas o servidor continua trabalhando e depois cai. TFS 1.3
-- Função para criar e configurar o combate de cura
local function createHealingCombat()
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 15) -- Efeito visual (ajustável)
return combat
end

-- Criar um único combate de cura
local combat = createHealingCombat()

-- Função para verificar se o jogador se moveu
local function checkMovement(cid, startPos)
local currentPos = getCreaturePosition(cid)
if not cid:isCreature() then return false end -- Verifica se o cid ainda é uma criatura
if currentPos.x ~= startPos.x or currentPos.y ~= startPos.y or currentPos.z ~= startPos.z then
return true -- Jogador se moveu
end
return false -- Jogador não se moveu
end

-- Função para obter o Magic Level (caso o Magic Level esteja armazenado de outra forma no seu servidor, ajuste esta parte)
local function getMagicLevel(cid)
if not cid:isCreature() then return 0 end -- Verifica se o cid ainda é uma criatura
-- Tentando acessar o Magic Level via storage
local magicLevel = getPlayerStorageValue(cid, 1000) -- Substitua 1000 pelo ID correto do storage no seu servidor
if magicLevel == -1 then
-- Se o Magic Level não estiver no storage, podemos usar uma lógica alternativa (como o level)
return 0 -- Retorna 0 como fallback
end
return magicLevel
end

-- Função para aplicar a cura
local function applyHealing(cid, var)
if not cid:isCreature() then return end -- Verifica se o cid ainda é uma criatura

local startPos = getCreaturePosition(cid) -- Salvar a posição inicial do jogador
local healingInProgress = true -- Flag para monitorar se a cura ainda está em progresso

-- Função para aplicar a cura com base no level e Magic Level
local function applyCure(interval, i)
if not cid:isCreature() then return end -- Verifica se o cid ainda é uma criatura
if not healingInProgress then
return
end

if not checkMovement(cid, startPos) then
-- Calculando a cura com base no level e Magic Level
local level = getPlayerLevel(cid)
local magicLevel = getMagicLevel(cid)

-- A cura será influenciada por Level e Magic Level
-- A fórmula ajustada:
local healingAmount = math.floor((level * 0.8) + (magicLevel * 1.8)) -- Ajuste a fórmula conforme necessário

-- Definindo a fórmula de cura
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 0, healingAmount, 0, healingAmount)
doCombat(cid, combat, var)
else
healingInProgress = false -- Interromper a cura se o jogador se mover
end
end

-- Aplicar os efeitos de cura com intervalo reduzido, 20 vezes
for i = 0, 19 do
-- Aplique a cura a cada 0.5 segundo (intervalo reduzido)
addEvent(function()
if not cid:isCreature() then return end -- Verifica se o cid ainda é uma criatura
applyCure(i * 500, i) -- Intervalo de 0.5 segundo entre as curas
end, i * 500)
end
end

function onCastSpell(cid, var)
if not cid:isCreature() then return false end -- Verifica se o cid ainda é uma criatura
-- Interromper a cura anterior se o feitiço for chamado novamente
applyHealing(cid, var)
return true
end
Sorry, it seems I put you on an incorrect path.

Try this instead.
LUA:
-- Função para criar e configurar o combate de cura
local function createHealingCombat()
    local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
    setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
    setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
    setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, 15)  -- Efeito visual (ajustável)
    return combat
end

-- Criar um único combate de cura
local combat = createHealingCombat()

-- Função para verificar se o jogador se moveu
local function checkMovement(creature, startPos)
    local currentPos = getCreaturePosition(creature)
    if currentPos.x ~= startPos.x or currentPos.y ~= startPos.y or currentPos.z ~= startPos.z then
        return true -- Jogador se moveu
    end
    return false -- Jogador não se moveu
end

-- Função para obter o Magic Level (caso o Magic Level esteja armazenado de outra forma no seu servidor, ajuste esta parte)
local function getMagicLevel(creature)
    -- Tentando acessar o Magic Level via storage
    local magicLevel = getPlayerStorageValue(creature, 1000)  -- Substitua 1000 pelo ID correto do storage no seu servidor
    if magicLevel == -1 then
        -- Se o Magic Level não estiver no storage, podemos usar uma lógica alternativa (como o level)
        return 0  -- Retorna 0 como fallback
    end
    return magicLevel
end

-- Função para aplicar a cura com base no level e Magic Level
local function applyCure(creature, variant, startPos)
    if not checkMovement(creature, startPos) then
        -- Calculando a cura com base no level e Magic Level
        local level = getPlayerLevel(creature)
        local magicLevel = getMagicLevel(creature)

        -- A cura será influenciada por Level e Magic Level
        -- A fórmula ajustada:
        local healingAmount = math.floor((level * 0.8) + (magicLevel * 1.8))  -- Ajuste a fórmula conforme necessário

        -- Definindo a fórmula de cura
        setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 0, healingAmount, 0, healingAmount)
        doCombat(creature, combat, variant)
    end
end

-- Função para aplicar a cura
local function applyHealing(creatureId, variant, amount, interval, startPos)
    local creature = Creature(creatureId)
    if not creature then
        return
    end
    
    amount = amount - 1
    applyCure(creature, variant, startPos)
    
    if amount > 0 then
        addEvent(applyHealing, interval, creatureId, variant, amount, interval, startPos)
    end
end

function onCastSpell(creature, variant)
    -- Interromper a cura anterior se o feitiço for chamado novamente
    local startPos = getCreaturePosition(creature) -- Salvar a posição inicial do jogador
    applyHealing(creature:getId(), variant, 20, 500, startPos)
    return true
end
 
Sorry, it seems I put you on an incorrect path.

Try this instead.
LUA:
-- Função para criar e configurar o combate de cura
local function createHealingCombat()
    local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
    setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
    setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
    setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, 15)  -- Efeito visual (ajustável)
    return combat
end

-- Criar um único combate de cura
local combat = createHealingCombat()

-- Função para verificar se o jogador se moveu
local function checkMovement(creature, startPos)
    local currentPos = getCreaturePosition(creature)
    if currentPos.x ~= startPos.x or currentPos.y ~= startPos.y or currentPos.z ~= startPos.z then
        return true -- Jogador se moveu
    end
    return false -- Jogador não se moveu
end

-- Função para obter o Magic Level (caso o Magic Level esteja armazenado de outra forma no seu servidor, ajuste esta parte)
local function getMagicLevel(creature)
    -- Tentando acessar o Magic Level via storage
    local magicLevel = getPlayerStorageValue(creature, 1000)  -- Substitua 1000 pelo ID correto do storage no seu servidor
    if magicLevel == -1 then
        -- Se o Magic Level não estiver no storage, podemos usar uma lógica alternativa (como o level)
        return 0  -- Retorna 0 como fallback
    end
    return magicLevel
end

-- Função para aplicar a cura com base no level e Magic Level
local function applyCure(creature, startPos)
    if not checkMovement(creature, startPos) then
        -- Calculando a cura com base no level e Magic Level
        local level = getPlayerLevel(creature)
        local magicLevel = getMagicLevel(creature)

        -- A cura será influenciada por Level e Magic Level
        -- A fórmula ajustada:
        local healingAmount = math.floor((level * 0.8) + (magicLevel * 1.8))  -- Ajuste a fórmula conforme necessário

        -- Definindo a fórmula de cura
        setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 0, healingAmount, 0, healingAmount)
        doCombat(creature, combat, var)
    end
end

-- Função para aplicar a cura
local function applyHealing(creatureId, variant, amount, interval, startPos)
    local creature = Creature(creatureId)
    if not creature then
        return
    end
   
    amount = amount - 1
    applyCure(creature, startPos)
   
    if amount > 0 then
        addEvent(applyHealing, interval, creatureId, variant, amount, interval, startPos)
    end
end

function onCastSpell(creature, variant)
    -- Interromper a cura anterior se o feitiço for chamado novamente
    local startPos = getCreaturePosition(creature) -- Salvar a posição inicial do jogador
    applyHealing(creature:getId(), variant, 20, 500, startPos)
    return true
end
Lua Script Error: [Spell Interface]
data/spells/scripts/healing/meditate gran vita.lua:onCastSpell
attempt to index a nil value
stack traceback:
[C]: at 0x7ff653aa63b0
[C]: in function 'doCombat'
data/spells/scripts/healing/meditate gran vita.lua:48: in function 'applyCure'
data/spells/scripts/healing/meditate gran vita.lua:60: in function 'applyHealing'
data/spells/scripts/healing/meditate gran vita.lua:70: in function <data/spells/scripts/healing/meditate gran vita.lua:67>
 
Lua Script Error: [Spell Interface]
data/spells/scripts/healing/meditate gran vita.lua:onCastSpell
attempt to index a nil value
stack traceback:
[C]: at 0x7ff653aa63b0
[C]: in function 'doCombat'
data/spells/scripts/healing/meditate gran vita.lua:48: in function 'applyCure'
data/spells/scripts/healing/meditate gran vita.lua:60: in function 'applyHealing'
data/spells/scripts/healing/meditate gran vita.lua:70: in function <data/spells/scripts/healing/meditate gran vita.lua:67>
you were too quick. xP

copy again.
 
you were too quick. xP

copy again.
Thank you, thank you! , Can you help me with another spell that has a similar bug? It's an attack spell that only works on the server when I use the /reload spells command. Additionally, it causes the same issue: the server crashes when the player dies or logs out.
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, true)

arr = {
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
}

local area = createCombatArea(arr)
setCombatArea(combat, area)

function calculateDamage(cid)
    local level = getPlayerLevel(cid)
    local magLevel = getPlayerMagLevel(cid)

    -- Reduzindo os fatores para diminuir o dano em 800
    local damage = (level * 9) + (magLevel * 2)  -- Ajuste para reduzir ainda mais o dano

    return damage
end

function spellCallback(param)
    if param.count > 0 or math.random(0, 1) == 1 then
        doSendMagicEffect(param.pos, CONST_ME_MORTAREA)
        local damage = calculateDamage(param.cid)
        doAreaCombatHealth(param.cid, COMBAT_DEATHDAMAGE, param.pos, 0, damage, damage, CONST_ME_EXPLOSIONHIT)
    end

    if param.count < 5 then
        param.count = param.count + 1
        addEvent(spellCallback, math.random(1000, 3000), param)
    end
end

function onTargetTile(cid, pos)
    local param = {}
    param.cid = cid
    param.pos = pos
    param.count = 0
    spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    if doCombat(cid, combat, var) then
        -- Sucesso ao lançar a magia
    else
        -- Falha ao lançar a magia
    end
    return true
end
 
Thank you, thank you! , Can you help me with another spell that has a similar bug? It's an attack spell that only works on the server when I use the /reload spells command. Additionally, it causes the same issue: the server crashes when the player dies or logs out.
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, true)

arr = {
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
}

local area = createCombatArea(arr)
setCombatArea(combat, area)

function calculateDamage(cid)
    local level = getPlayerLevel(cid)
    local magLevel = getPlayerMagLevel(cid)

    -- Reduzindo os fatores para diminuir o dano em 800
    local damage = (level * 9) + (magLevel * 2)  -- Ajuste para reduzir ainda mais o dano

    return damage
end

function spellCallback(param)
    if param.count > 0 or math.random(0, 1) == 1 then
        doSendMagicEffect(param.pos, CONST_ME_MORTAREA)
        local damage = calculateDamage(param.cid)
        doAreaCombatHealth(param.cid, COMBAT_DEATHDAMAGE, param.pos, 0, damage, damage, CONST_ME_EXPLOSIONHIT)
    end

    if param.count < 5 then
        param.count = param.count + 1
        addEvent(spellCallback, math.random(1000, 3000), param)
    end
end

function onTargetTile(cid, pos)
    local param = {}
    param.cid = cid
    param.pos = pos
    param.count = 0
    spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    if doCombat(cid, combat, var) then
        -- Sucesso ao lançar a magia
    else
        -- Falha ao lançar a magia
    end
    return true
end

Try
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, true)

local arr = {
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
}

local area = createCombatArea(arr)
setCombatArea(combat, area)

function calculateDamage(cid)
    local level = getPlayerLevel(cid)
    local magLevel = getPlayerMagLevel(cid)

    -- Reduzindo os fatores para diminuir o dano em 800
    local damage = (level * 9) + (magLevel * 2)  -- Ajuste para reduzir ainda mais o dano

    return damage
end

function spellCallback(param)
    local cid = Creature(param.cid)
    if not cid then
        return
    end
    if param.count > 0 or math.random(0, 1) == 1 then
        doSendMagicEffect(param.pos, CONST_ME_MORTAREA)
        local damage = calculateDamage(cid)
        doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, param.pos, 0, damage, damage, CONST_ME_EXPLOSIONHIT)
    end

    if param.count < 5 then
        param.count = param.count + 1
        addEvent(spellCallback, math.random(1000, 3000), param)
    end
end

function onTargetTile(cid, pos)
    local param = {}
    param.cid = cid:getId()
    param.pos = pos
    param.count = 0
    spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    if doCombat(cid, combat, var) then
        -- Sucesso ao lançar a magia
    else
        -- Falha ao lançar a magia
    end
    return true
end
 
Try
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, true)

local arr = {
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
}

local area = createCombatArea(arr)
setCombatArea(combat, area)

function calculateDamage(cid)
    local level = getPlayerLevel(cid)
    local magLevel = getPlayerMagLevel(cid)

    -- Reduzindo os fatores para diminuir o dano em 800
    local damage = (level * 9) + (magLevel * 2)  -- Ajuste para reduzir ainda mais o dano

    return damage
end

function spellCallback(param)
    local cid = Creature(param.cid)
    if not cid then
        return
    end
    if param.count > 0 or math.random(0, 1) == 1 then
        doSendMagicEffect(param.pos, CONST_ME_MORTAREA)
        local damage = calculateDamage(cid)
        doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, param.pos, 0, damage, damage, CONST_ME_EXPLOSIONHIT)
    end

    if param.count < 5 then
        param.count = param.count + 1
        addEvent(spellCallback, math.random(1000, 3000), param)
    end
end

function onTargetTile(cid, pos)
    local param = {}
    param.cid = cid:getId()
    param.pos = pos
    param.count = 0
    spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    if doCombat(cid, combat, var) then
        -- Sucesso ao lançar a magia
    else
        -- Falha ao lançar a magia
    end
    return true
end
It worked, but this spell is only working when I use the /reload spells command. Do you know how to solve this problem?
 
It worked, but this spell is only working when I use the /reload spells command. Do you know how to solve this problem?
Only thing I can think of, is the global function names.. possibly being overwritten?

I've put locals in front of them.
Idk what else to try if this doesn't work tho.
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, true)

local arr = {
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
}

local area = createCombatArea(arr)
setCombatArea(combat, area)

local function calculateDamage(cid)
    local level = getPlayerLevel(cid)
    local magLevel = getPlayerMagLevel(cid)

    -- Reduzindo os fatores para diminuir o dano em 800
    local damage = (level * 9) + (magLevel * 2)  -- Ajuste para reduzir ainda mais o dano

    return damage
end

local function spellCallback(param)
    local cid = Creature(param.cid)
    if not cid then
        return
    end
    if param.count > 0 or math.random(0, 1) == 1 then
        doSendMagicEffect(param.pos, CONST_ME_MORTAREA)
        local damage = calculateDamage(cid)
        doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, param.pos, 0, damage, damage, CONST_ME_EXPLOSIONHIT)
    end

    if param.count < 5 then
        param.count = param.count + 1
        addEvent(spellCallback, math.random(1000, 3000), param)
    end
end

function onTargetTile(cid, pos)
    local param = {}
    param.cid = cid:getId()
    param.pos = pos
    param.count = 0
    spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    if doCombat(cid, combat, var) then
        -- Sucesso ao lançar a magia
    else
        -- Falha ao lançar a magia
    end
    return true
end
 
Only thing I can think of, is the global function names.. possibly being overwritten?

I've put locals in front of them.
Idk what else to try if this doesn't work tho.
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, true)

local arr = {
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
}

local area = createCombatArea(arr)
setCombatArea(combat, area)

local function calculateDamage(cid)
    local level = getPlayerLevel(cid)
    local magLevel = getPlayerMagLevel(cid)

    -- Reduzindo os fatores para diminuir o dano em 800
    local damage = (level * 9) + (magLevel * 2)  -- Ajuste para reduzir ainda mais o dano

    return damage
end

local function spellCallback(param)
    local cid = Creature(param.cid)
    if not cid then
        return
    end
    if param.count > 0 or math.random(0, 1) == 1 then
        doSendMagicEffect(param.pos, CONST_ME_MORTAREA)
        local damage = calculateDamage(cid)
        doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, param.pos, 0, damage, damage, CONST_ME_EXPLOSIONHIT)
    end

    if param.count < 5 then
        param.count = param.count + 1
        addEvent(spellCallback, math.random(1000, 3000), param)
    end
end

function onTargetTile(cid, pos)
    local param = {}
    param.cid = cid:getId()
    param.pos = pos
    param.count = 0
    spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
    if doCombat(cid, combat, var) then
        -- Sucesso ao lançar a magia
    else
        -- Falha ao lançar a magia
    end
    return true
end
Now it's working normally, thank you
 
Back
Top