RevScript Spell Druid

Shuyin

Miembro
LV
23
 
Awards
17
Spell para Druid "exevo frostquake"

Ver archivo adjunto Tibia - Deixis 2023-12-12 21-39-28.mp4
Código Lua:
local spell = Spell("instant")

-- Función para normalizar un vector.
local function normalizeVector(vector)
    local length = math.sqrt(vector.x^2 + vector.y^2 + vector.z^2)
    return {
        x = vector.x / length,
        y = vector.y / length,
        z = vector.z / length
    }
end

-- Tabla para almacenar los tiempos de reutilización de los jugadores
local playerCooldowns = {}

-- Función para actualizar los cooldowns de los jugadores
local function updateCooldowns()
    for playerId, cooldown in pairs(playerCooldowns) do
        if cooldown > 0 then
            cooldown = cooldown - 1
            playerCooldowns[playerId] = cooldown

            -- Obtener al jugador por su ID
            local player = Player(playerId)
            if player then
                player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Wait " .. cooldown .. " seconds before using exevo Frostquake again.")
            end
        end
    end
    addEvent(updateCooldowns, 1000) -- Espera 1 segundo antes de actualizar nuevamente
end

-- Iniciar la función para descuento de cooldowns
updateCooldowns()

-- Modifica la función spell.onCastSpell para aplicar el cooldown
function spell.onCastSpell(creature, variant)
    local playerId = creature:getId()

    if playerCooldowns[playerId] and playerCooldowns[playerId] > 0 then
        local player = Player(creature)
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Wait " .. playerCooldowns[playerId] .. " seconds before using exevo Frostquake again.")
        return false
    end

    local target = creature:getTarget()
   
    if not target or not target:isCreature() then
        creature:sendCancelMessage("You need to target a creature to use this spell.")
        return false
    end
   
    local mlvl = creature:getMagicLevel() -- Nivel mágico del jugador
    local level = creature:getLevel() -- Nivel del jugador
   
    local iceDamage = math.random(mlvl * 1, mlvl * 3) + math.random(level * 1, level * 1) --
    local earthDamage = math.random(mlvl * 1, mlvl * 3) + math.random(level * 1, level * 1) --
   
    local startPos = creature:getPosition()
    local targetPos = target:getPosition()
   
    local distance = startPos:getDistance(targetPos)
   
    local direction = {
        x = targetPos.x - startPos.x,
        y = targetPos.y - startPos.y,
        z = targetPos.z - startPos.z
    }
   
    direction = normalizeVector(direction)
   
    local iceEffect = CONST_ME_ICEATTACK
local earthEffect = 46

local function castEffects(positions, currentEffectIndex)
    if currentEffectIndex <= #positions then
        local currentPos = positions[currentEffectIndex]
       
        -- Alterna entre los efectos "hielo" y "tierra" en cada posición intermedia.
        if currentEffect == iceEffect then
            currentEffect = earthEffect
        else
            currentEffect = iceEffect
        end
       
        Position(currentPos):sendMagicEffect(currentEffect)
       
        local damage
        if currentEffect == iceEffect then
            damage = iceDamage
        elseif currentEffect == earthEffect then
            damage = earthDamage
        end
       
        if damage then
            local tile = Tile(currentPos)
            if tile then
                local creatures = tile:getCreatures()
                for _, creatureInTile in ipairs(creatures) do
                    if creatureInTile:isCreature() and creatureInTile ~= creature then
                        creatureInTile:addHealth(-damage, currentEffect == iceEffect and COMBAT_ICEDAMAGE or COMBAT_EARTHDAMAGE)
                    end
                end
            end
        end
       
        -- Agrega un temporizador para el próximo efecto visual.
        local nextEffectIndex = currentEffectIndex + 1
        local delay = 100 -- Tiempo en milisegundos entre efectos (ajusta según lo deseado)
        addEvent(castEffects, delay, positions, nextEffectIndex)
    else
        -- Una vez que se muestran todos los efectos, aplica el daño al objetivo original.
        if currentEffect == iceEffect then
            target:addHealth(-iceDamage, COMBAT_ICEDAMAGE)
        elseif currentEffect == earthEffect then
            target:addHealth(-earthDamage, COMBAT_EARTHDAMAGE)
        end
    end
end

-- Crea una tabla de posiciones intermedias entre el jugador y el objetivo.
local positions = {}
for i = 1, distance do
    local currentPos = {
        x = startPos.x + direction.x * i,
        y = startPos.y + direction.y * i,
        z = startPos.z + direction.z * i
    }
    table.insert(positions, currentPos)
end

-- Comienza la secuencia de efectos.
castEffects(positions, 1)
playerCooldowns[playerId] = 5 -- 5 segundos de cooldown para este jugador

    return true
end

spell:group("attack", "focus")
spell:id(230)
spell:name("Elemental Avalanche Druid")
spell:words("exevo Frostquake")
spell:level(300)
spell:mana(700)
spell:isPremium(true)
spell:range(5)
spell:isSelfTarget(false)
spell:groupCooldown(1 * 1000)
spell:needLearn(false)
spell:vocation("druid;true", "elder druid;true")
spell:register()
 
Arriba