• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Time to kill boss

mattehj

Member
Joined
Oct 8, 2009
Messages
83
Reaction score
16
How can i add timer? Like you only have 15 min to kill the boss, If it goes 15 min, you get kicked to X position?

Lua:
-- lever to Duke Krule room

local config = {
    requiredLevel = 100,
    daily = true,
    roomCenterPosition = Position(33456, 31472, 13),
    playerPositions = {
        Position(33455, 31493, 13),
        Position(33456, 31493, 13),
        Position(33457, 31493, 13),
        Position(33458, 31493, 13),
        Position(33459, 31493, 13)
    },
    teleportPosition = Position(33456, 31480, 13),
    bossPosition = Position(33456, 31472, 13)
}

local leverboss = Action()

function leverboss.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 9825 then
        -- Check if the player that pulled the lever is on the correct position
        if player:getPosition() ~= config.playerPositions[1] then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can\'t start the battle.")
            return true
        end
        
        local team, participant = {}

        for i = 1, #config.playerPositions do
            participant = Tile(config.playerPositions[i]):getTopCreature()
            
            -- Check there is a participant player
            if participant and participant:isPlayer() then
                -- Check participant level
                if participant:getLevel() < config.requiredLevel then
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE,
                        "All the players need to be level ".. config.requiredLevel .." or higher.")
                    return true
                end

                -- -- Check participant boss timer
                if config.daily and participant:getStorageValue(Storage.GraveDanger.KruleTimer) > os.time() then
                    player:getPosition():sendMagicEffect(CONST_ME_POFF)
                    player:sendCancelMessage("Not all players are ready yet from last battle.")
                    return true
                end

                team[#team + 1] = participant
            end
        end

        -- Check if a team currently inside the boss room
        local specs, spec = Game.getSpectators(config.roomCenterPosition, false, false, 14, 14, 13, 13)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A team is already inside the boss room.")
                return true
            end

            spec:remove()
        end

        -- Spawn boss
        Game.createMonster("Duke Krule", config.bossPosition)

        -- Teleport team participants
        for i = 1, #team do
            team[i]:getPosition():sendMagicEffect(CONST_ME_POFF)
            team[i]:teleportTo(config.teleportPosition)
            -- Assign boss timer
            team[i]:setStorageValue(Storage.GraveDanger.KruleTimer, os.time() + 20*60*60) -- 20 hours
        end
        
        config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
    end

    item:transform(9825)
    return true
end

leverboss:uid(49006)
leverboss:register()
 
Solution
Try this:
Lua:
local config = {
    leverUniqueID = 49006,
    requiredLevel = 100,
    daily = true,
    bossName = "Duke Krule",
    storage = Storage.GraveDanger.KruleTimer,
    roomCenterPosition = Position(33456, 31472, 13),
    playerPositions = {
        Position(33455, 31493, 13),
        Position(33456, 31493, 13),
        Position(33457, 31493, 13),
        Position(33458, 31493, 13),
        Position(33459, 31493, 13)
    },
    teleportPosition = Position(33456, 31480, 13),
    bossPosition = Position(33456, 31472, 13),

    kickMinutes = 15, -- minutes
    kickPosition = Position(0, 0, 0)
}

local leverBoss = Action()

function leverBoss.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() ==...
Try this:
Lua:
local config = {
    leverUniqueID = 49006,
    requiredLevel = 100,
    daily = true,
    bossName = "Duke Krule",
    storage = Storage.GraveDanger.KruleTimer,
    roomCenterPosition = Position(33456, 31472, 13),
    playerPositions = {
        Position(33455, 31493, 13),
        Position(33456, 31493, 13),
        Position(33457, 31493, 13),
        Position(33458, 31493, 13),
        Position(33459, 31493, 13)
    },
    teleportPosition = Position(33456, 31480, 13),
    bossPosition = Position(33456, 31472, 13),

    kickMinutes = 15, -- minutes
    kickPosition = Position(0, 0, 0)
}

local leverBoss = Action()

function leverBoss.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() == 9825 then
        if player:getPosition() ~= config.playerPositions[1] then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can\'t start the battle.")
            return true
        end

        local participants = {}
        for _, playerPos in pairs(config.playerPositions) do
            local tile = Tile(playerPos)
            if tile then
                local participant = tile:getTopCreature()
                if participant and participant:isPlayer() then
                    if participant:getLevel() < config.requiredLevel then
                        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("All the players need to be level %d or higher.", config.requiredLevel))
                        return true
                    end

                    if config.daily and participant:getStorageValue(config.storage) > os.time() then
                        player:getPosition():sendMagicEffect(CONST_ME_POFF)
                        player:sendCancelMessage("Not all players are ready yet from last battle.")
                        return true
                    end

                    participants[#participants +1] = participant
                end
            end
        end

        for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, 14, 14, 13, 13)) do
            if spectator:isPlayer() then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A team is already inside the boss room.")
                return true
            end
            spectator:remove()
        end

        local boss = Game.createMonster(config.bossName, config.bossPosition)
        if boss then boss:registerEvent("CancelKickEvent") end

        for _, participant in pairs(participants) do
            participant:getPosition():sendMagicEffect(CONST_ME_POFF)
            participant:teleportTo(config.teleportPosition)
            participant:setStorageValue(config.storage, os.time() + 20*60*60)
        end
        
        config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)

        config.kickEventId = addEvent(function ()
            for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, 14, 14, 13, 13)) do
                if spectator:isPlayer() then
                    spectator:teleportTo(config.kickPosition, false)
                    spectator:sendCancelMessage("Time is up!")
                else
                    spectator:remove()
                end
            end
            config.kickPosition:sendMagicEffect(CONST_ME_TELEPORT)
        end, config.kickMinutes * 60 * 1000)
    end

    item:transform(9825)
    return true
end

leverBoss:uid(config.leverUniqueID)
leverBoss:register()

local cancelKickEvent = CreatureEvent("CancelKickEvent")
function cancelKickEvent.onDeath(...) stopEvent(config.kickEventId) return true end
cancelKickEvent:register()
 
Last edited:
Solution
Back
Top