RevScript Spell Knight

Shuyin

Miembro
LV
23
 
Awards
17
Spell para Knight "exori attraction"

Ver archivo adjunto Tibia - Deixis 2023-12-12 21-47-03.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 exori attraction 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()

    -- Verificar si el jugador está en una zona de protección
  if creature:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
    creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot use this item inside a protection zone.")
    creature:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
end

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

    local radius = 5 -- Radio de atracción en casillas
    local position = creature:getPosition()
    local targetCreatures = {}
    local paralyzeCondition = Condition(CONDITION_PARALYZE)
    paralyzeCondition:setParameter(CONDITION_PARAM_TICKS, 10000)
    paralyzeCondition:setFormula(-0.90, 0, -0.95, 0)

    for x = -radius, radius do
        for y = -radius, radius do
            local tile = Tile({x = position.x + x, y = position.y + y, z = position.z})
            if tile then
                local tileCreatures = tile:getCreatures()
                if tileCreatures then
                    for _, tileCreature in ipairs(tileCreatures) do
                        if tileCreature:isMonster() then
                            -- Verificar si el monstruo no es un summon de un jugador
                            local owner = tileCreature:getMaster()
                            if not owner or not owner:isPlayer() then
                                tileCreature:addCondition(paralyzeCondition)
                                table.insert(targetCreatures, tileCreature)
                                -- Mostrar el efecto mágico "poff" en cada monstruo
                                tileCreature:getPosition():sendMagicEffect(CONST_ME_POFF)
                            end
                        end
                    end
                end
            end
        end
    end

    for _, targetCreature in ipairs(targetCreatures) do
        targetCreature:teleportTo(creature:getPosition())
        targetCreature:say("Poff!", TALKTYPE_MONSTER_SAY)
    end
    playerCooldowns[playerId] = 5 -- 5 segundos de cooldown para este jugador

    return true
end

spell:group("attack")
spell:id(234)
spell:name("Arcane Attraction")
spell:words("exori attraction")
spell:level(300)
spell:mana(300)
spell:isAggressive(true)
spell:blockWalls(true)
spell:groupCooldown(1 * 1000)
spell:needLearn(false)
spell:vocation("knight;true", "elite knight;true")
spell:register()
 
Arriba