RevScript Spell Paladin

Shuyin

Miembro
LV
23
 
Awards
17
Spell para Paladin "exevo gran san"

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

-- 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 gran san 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 gran san again.")
        return false
    end

        local playerPosition = creature:getPosition()
    local playerDirection = creature:getDirection()
    local distance = 5  -- La distancia para extender el efecto de abanico
    local angleSpread = 90  -- El ángulo de apertura del abanico en grados (90 para un cuarto de círculo)
    local numSteps = 9  -- El número de pasos para crear el efecto de abanico
    local pushDistance = 1  -- La distancia para empujar a los monstruos
    
    -- Obtén el nivel del jugador que lanza el hechizo
    local playerLevel = creature:getLevel()
    
    -- Establece los valores mínimo y máximo para el daño holy
    local minHolyDamage = playerLevel * 0.20  -- Daño mínimo basado en el nivel (ajusta según tus necesidades)
    local maxHolyDamage = playerLevel * 0.40  -- Daño máximo basado en el nivel (ajusta según tus necesidades)

    local angleIncrement = angleSpread / (numSteps - 1)  -- Calcula el incremento del ángulo

    -- Calcula los desplazamientos basados en la dirección del jugador
    local xOffset, yOffset

    if playerDirection == DIRECTION_NORTH then
        xOffset, yOffset = 0, -1
    elseif playerDirection == DIRECTION_SOUTH then
        xOffset, yOffset = 0, 1
    elseif playerDirection == DIRECTION_EAST then
        xOffset, yOffset = 1, 0
    elseif playerDirection == DIRECTION_WEST then
        xOffset, yOffset = -1, 0
    else
        xOffset, yOffset = 0, -1  -- Por defecto, utiliza el norte si la dirección no se reconoce
    end

    for i = 1, numSteps do
        local currentX, currentY = playerPosition.x, playerPosition.y

        for j = 1, distance do
            -- Calcula la nueva posición basada en los desplazamientos
            currentX = currentX + xOffset
            currentY = currentY + yOffset

            -- Crea un nuevo objeto de posición a nivel del suelo
            local newPosition = Position(currentX, currentY, playerPosition.z)

            -- Comprueba si hay una criatura (monstruo) en la nueva posición
            local tile = Tile(newPosition)
            local targetCreature = tile:getTopCreature()
            
            if targetCreature and targetCreature:isMonster() then
                -- Calcula un daño holy aleatorio entre el mínimo y el máximo
                local holyDamage = math.random(minHolyDamage, maxHolyDamage)
                
                -- Aplica el daño holy al monstruo
                targetCreature:addHealth(-holyDamage, COMBAT_HOLYDAMAGE, creature)
                
                -- Calculate the new position after pushing the monster diagonally
local pushX = targetCreature:getPosition().x + xOffset * pushDistance
local pushY = targetCreature:getPosition().y + yOffset * pushDistance
local pushPosition = Position(pushX, pushY, targetCreature:getPosition().z)

-- Check if the new position is accessible before moving the monster
local newTile = Tile(pushPosition)
local isInProtectionZone = newTile and newTile:hasFlag(TILESTATE_PROTECTIONZONE)

if newTile and newTile:isWalkable() and not newTile:hasProperty(CONST_PROP_BLOCKINGANDNOTMOVEABLE) and not isInProtectionZone then
    -- The new position is valid, so push the monster diagonally
    targetCreature:teleportTo(pushPosition, true)
end
            end

            -- Envía el efecto mágico en la nueva posición
            newPosition:sendMagicEffect(40)
        end

        -- Rota los desplazamientos para el siguiente paso
        local newOffsetX = xOffset * math.cos(math.rad(angleIncrement)) - yOffset * math.sin(math.rad(angleIncrement))
        local newOffsetY = xOffset * math.sin(math.rad(angleIncrement)) + yOffset * math.cos(math.rad(angleIncrement))
        xOffset, yOffset = newOffsetX, newOffsetY
    end
    playerCooldowns[playerId] = 5 -- 5 segundos de cooldown para este jugador

    return true
end

spell:group("attack")
spell:id(233)
spell:name("divine purge")
spell:words("exevo gran san")
spell:level(300)
spell:mana(400)
spell:isPremium(true)
spell:groupCooldown(1 * 1000)
spell:needLearn(false)
spell:vocation("paladin;true", "royal paladin;true")
spell:register()
 
Arriba