RevScript Spell Sorcerer

Shuyin

Miembro
LV
23
 
Awards
17
Spell para Sorcerer "exevo necroshock"

Ver archivo adjunto Tibia - Deixis 2023-12-12 21-51-09.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 Necroshock 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 Necroshock 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 energyEffect = 48
local deathEffect = 18

local function castEffects(positions, currentEffectIndex)
    if currentEffectIndex <= #positions then
        local currentPos = positions[currentEffectIndex]
        
        -- Alterna entre los efectos "energy" y "muerte" en cada posición intermedia.
        if currentEffect == energyEffect then
            currentEffect = deathEffect
        else
            currentEffect = energyEffect
        end
        
        Position(currentPos):sendMagicEffect(currentEffect)
        
        local damage
        if currentEffect == energyEffect then
            damage = iceDamage
        elseif currentEffect == deathEffect 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 == energyEffect and COMBAT_ENERGYDAMAGE or COMBAT_DEATHDAMAGE)
                    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 == energyEffect then
            target:addHealth(-iceDamage, COMBAT_ENERGYDAMAGE)
        elseif currentEffect == deathEffect then
            target:addHealth(-earthDamage, COMBAT_DEATHDAMAGE)
        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(231)
spell:name("Elemental Avalanche Sorcerer")
spell:words("exevo Necroshock")
spell:level(300)
spell:mana(700)
spell:isPremium(true)
spell:range(5)
spell:isSelfTarget(false)
spell:groupCooldown(1 * 1000)
spell:needLearn(false)
spell:vocation("sorcerer;true", "master sorcerer;true")
spell:register()
 
Arriba