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