• 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 How do i add exausted to a boss lever?

Methemia

Member
Joined
Feb 1, 2015
Messages
59
Reaction score
7
I want the player to only be able to pull the lever every 20h, can anyone teach me?

Lua:
local config = {
    duration = 10, -- time till reset, in minutes
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
     if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if item.itemid ~= config.lever_id then
        return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
    end

    local participants, pull_player = {}, false
    for i = 1, #player_positions do
        local fromPos = player_positions[i].fromPos
        local tile = Tile(fromPos)
        if not tile then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end

        local creature = tile:getBottomCreature()
        if creature then
            local participant = creature:getPlayer()
            if not participant then
                return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
            end

            if participant:getLevel() < config.level_req then
                return player:sendCancelMessage(participant:getName() .. " is not the required level.")
            end

            if participant.uid == player.uid then
                pull_player = true
            end

            participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
        end
    end

    if #participants < config.min_players then
        return player:sendCancelMessage("You do not have the required amount of participants.")
    end

    if not pull_player then
        return player:sendCancelMessage("You are in the wrong position.")
    end

    for i = 1, #monsters do
        local toPos = monsters[i].pos
        if not Tile(toPos) then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end

    local cid_array = {}
    for i = 1, #participants do
        participants[i].participant:teleportTo(participants[i].toPos)
        participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
        cid_array[#cid_array + 1] = participants[i].participant.uid
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
    end

    item:transform(config.pulled_id)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
    return true
end
 
I want only the player who pulls it to have to wait 20 hours to try again, if I change the time to 1200, everyone should wait that time to use it u.u
I already tried many things and I still can't add a cooldown of 20h for those who already pulled the lever
 
Try this, I didn't test it.


Code:
local config = {
    duration = 10, -- time till reset, in minutes
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
    cooldown_storage = 72000, -- cooldown in seconds
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
     if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if player:getStorageValue(cooldown_storage) <= os.time() then
        if item.itemid ~= config.lever_id then
            return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
        end

        local participants, pull_player = {}, false
        for i = 1, #player_positions do
            local fromPos = player_positions[i].fromPos
            local tile = Tile(fromPos)
            if not tile then
                print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
                return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
            end

            local creature = tile:getBottomCreature()
            if creature then
                local participant = creature:getPlayer()
                if not participant then
                    return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
                end

                if participant:getLevel() < config.level_req then
                    return player:sendCancelMessage(participant:getName() .. " is not the required level.")
                end

                if participant.uid == player.uid then
                    pull_player = true
                end

                participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
            end
        end

        if #participants < config.min_players then
            return player:sendCancelMessage("You do not have the required amount of participants.")
        end

        if not pull_player then
            return player:sendCancelMessage("You are in the wrong position.")
        end

        for i = 1, #monsters do
            local toPos = monsters[i].pos
            if not Tile(toPos) then
                print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
                return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
            end
            Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
        end

        local cid_array = {}
        for i = 1, #participants do
            participants[i].participant:teleportTo(participants[i].toPos)
            participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
            cid_array[#cid_array + 1] = participants[i].participant.uid
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
        end

        item:transform(config.pulled_id)
        addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
        player:setStorageValue(cooldown_storage, os.time() + cooldown) -- Successfully started quest, set the players cooldown here.
        return true

    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every " .. cooldown .. " seconds. Remaining cooldown: " .. player:getStorageValue(cooldown_storage) - os.time())
    end
    
    return false

end
 
Try this, I didn't test it.


Code:
local config = {
    duration = 10, -- time till reset, in minutes
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
    cooldown_storage = 72000, -- cooldown in seconds
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
     if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if player:getStorageValue(cooldown_storage) <= os.time() then
        if item.itemid ~= config.lever_id then
            return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
        end

        local participants, pull_player = {}, false
        for i = 1, #player_positions do
            local fromPos = player_positions[i].fromPos
            local tile = Tile(fromPos)
            if not tile then
                print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
                return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
            end

            local creature = tile:getBottomCreature()
            if creature then
                local participant = creature:getPlayer()
                if not participant then
                    return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
                end

                if participant:getLevel() < config.level_req then
                    return player:sendCancelMessage(participant:getName() .. " is not the required level.")
                end

                if participant.uid == player.uid then
                    pull_player = true
                end

                participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
            end
        end

        if #participants < config.min_players then
            return player:sendCancelMessage("You do not have the required amount of participants.")
        end

        if not pull_player then
            return player:sendCancelMessage("You are in the wrong position.")
        end

        for i = 1, #monsters do
            local toPos = monsters[i].pos
            if not Tile(toPos) then
                print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
                return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
            end
            Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
        end

        local cid_array = {}
        for i = 1, #participants do
            participants[i].participant:teleportTo(participants[i].toPos)
            participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
            cid_array[#cid_array + 1] = participants[i].participant.uid
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
        end

        item:transform(config.pulled_id)
        addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
        player:setStorageValue(cooldown_storage, os.time() + cooldown) -- Successfully started quest, set the players cooldown here.
        return true

    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Can only be executed once every " .. cooldown .. " seconds. Remaining cooldown: " .. player:getStorageValue(cooldown_storage) - os.time())
    end
   
    return false

end
it didn't work:(
 
Does he need to add anything in SQL because of this?
player:setStorageValue(cooldown_storage, os.time() + cooldown) or is it like a tmp value ?
 
I want the player to only be able to pull the lever every 20h, can anyone teach me?


Lua:
local config = {
    duration = 10, -- time till reset, in minutes
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
     if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if item.itemid ~= config.lever_id then
        return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
    end

    local participants, pull_player = {}, false
    for i = 1, #player_positions do
        local fromPos = player_positions[i].fromPos
        local tile = Tile(fromPos)
        if not tile then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end

        local creature = tile:getBottomCreature()
        if creature then
            local participant = creature:getPlayer()
            if not participant then
                return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
            end

            if participant:getLevel() < config.level_req then
                return player:sendCancelMessage(participant:getName() .. " is not the required level.")
            end

            if participant.uid == player.uid then
                pull_player = true
            end

            participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
        end
    end

    if #participants < config.min_players then
        return player:sendCancelMessage("You do not have the required amount of participants.")
    end

    if not pull_player then
        return player:sendCancelMessage("You are in the wrong position.")
    end

    for i = 1, #monsters do
        local toPos = monsters[i].pos
        if not Tile(toPos) then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end

    local cid_array = {}
    for i = 1, #participants do
        participants[i].participant:teleportTo(participants[i].toPos)
        participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
        cid_array[#cid_array + 1] = participants[i].participant.uid
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
    end

    item:transform(config.pulled_id)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
    return true
end

Line 70 for config

Lua:
local config = {
    duration = 10, -- time till reset, in minutes
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
     if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local cooldown = 15 -- in seconds - (Make it 'seconds * minutes * hours' - its will be '60 * 60 * 20' for 20 hours), anyway check this 15 second first for script work
    if player:getStorageValue(112285) >= os.time() then
    if item.itemid ~= config.lever_id then
        return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
    end

    local participants, pull_player = {}, false
    for i = 1, #player_positions do
        local fromPos = player_positions[i].fromPos
        local tile = Tile(fromPos)
        if not tile then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end

        local creature = tile:getBottomCreature()
        if creature then
            local participant = creature:getPlayer()
            if not participant then
                return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
            end

            if participant:getLevel() < config.level_req then
                return player:sendCancelMessage(participant:getName() .. " is not the required level.")
            end

            if participant.uid == player.uid then
                pull_player = true
            end

            participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
        end
    end

    if #participants < config.min_players then
        return player:sendCancelMessage("You do not have the required amount of participants.")
    end

    if not pull_player then
        return player:sendCancelMessage("You are in the wrong position.")
    end

    for i = 1, #monsters do
        local toPos = monsters[i].pos
        if not Tile(toPos) then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end

    local cid_array = {}
    for i = 1, #participants do
        participants[i].participant:teleportTo(participants[i].toPos)
        participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
        cid_array[#cid_array + 1] = participants[i].participant.uid
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
    end

    item:transform(config.pulled_id)
    player:setStorageValue(112285, os.time() + cooldown)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
    return true
    end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Lever is broke, try tomorrow")
end
 
Line 70 for config

Lua:
local config = {
    duration = 10, -- time till reset, in minutes
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
     if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local cooldown = 15 -- in seconds - (Make it 'seconds * minutes * hours' - its will be '60 * 60 * 20' for 20 hours), anyway check this 15 second first for script work
    if player:getStorageValue(112285) >= os.time() then
    if item.itemid ~= config.lever_id then
        return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
    end

    local participants, pull_player = {}, false
    for i = 1, #player_positions do
        local fromPos = player_positions[i].fromPos
        local tile = Tile(fromPos)
        if not tile then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end

        local creature = tile:getBottomCreature()
        if creature then
            local participant = creature:getPlayer()
            if not participant then
                return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
            end

            if participant:getLevel() < config.level_req then
                return player:sendCancelMessage(participant:getName() .. " is not the required level.")
            end

            if participant.uid == player.uid then
                pull_player = true
            end

            participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
        end
    end

    if #participants < config.min_players then
        return player:sendCancelMessage("You do not have the required amount of participants.")
    end

    if not pull_player then
        return player:sendCancelMessage("You are in the wrong position.")
    end

    for i = 1, #monsters do
        local toPos = monsters[i].pos
        if not Tile(toPos) then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end

    local cid_array = {}
    for i = 1, #participants do
        participants[i].participant:teleportTo(participants[i].toPos)
        participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
        cid_array[#cid_array + 1] = participants[i].participant.uid
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
    end

    item:transform(config.pulled_id)
    player:setStorageValue(112285, os.time() + cooldown)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
    return true
    end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Lever is broke, try tomorrow")
end
help :(
ljDpYDz.png


won't let me try, that message appears
 
help :(
ljDpYDz.png


won't let me try, that message appears
Lua:
local config = {
    duration = 10, -- time till reset, in minutes
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
     if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local cooldown = 15 -- in seconds - (Make it 'seconds * minutes * hours' - its will be '60 * 60 * 20' for 20 hours), anyway check this 15 second first for script work
    if player:getStorageValue(112285) >= os.time() then
    if item.itemid ~= config.lever_id then
        return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
    end

    local participants, pull_player = {}, false
    for i = 1, #player_positions do
        local fromPos = player_positions[i].fromPos
        local tile = Tile(fromPos)
        if not tile then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end

        local creature = tile:getBottomCreature()
        if creature then
            local participant = creature:getPlayer()
            if not participant then
                return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
            end

            if participant:getLevel() < config.level_req then
                return player:sendCancelMessage(participant:getName() .. " is not the required level.")
            end

            if participant.uid == player.uid then
                pull_player = true
            end

            participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
        end
    end

    if #participants < config.min_players then
        return player:sendCancelMessage("You do not have the required amount of participants.")
    end

    if not pull_player then
        return player:sendCancelMessage("You are in the wrong position.")
    end

    for i = 1, #monsters do
        local toPos = monsters[i].pos
        if not Tile(toPos) then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end

    local cid_array = {}
    for i = 1, #participants do
        participants[i].participant:teleportTo(participants[i].toPos)
        participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
        cid_array[#cid_array + 1] = participants[i].participant.uid
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
    end

    item:transform(config.pulled_id)
    player:setStorageValue(112285, os.time() + cooldown)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
    return true

    else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Lever is broke, try tomorrow")
end
end
 
13:18 Lever is broke, try tomorrow
Post automatically merged:

Lua:
local config = {
    duration = 10, -- time till reset, in minutes
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
     if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local cooldown = 15 -- in seconds - (Make it 'seconds * minutes * hours' - its will be '60 * 60 * 20' for 20 hours), anyway check this 15 second first for script work
    if player:getStorageValue(112285) >= os.time() then
    if item.itemid ~= config.lever_id then
        return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
    end

    local participants, pull_player = {}, false
    for i = 1, #player_positions do
        local fromPos = player_positions[i].fromPos
        local tile = Tile(fromPos)
        if not tile then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end

        local creature = tile:getBottomCreature()
        if creature then
            local participant = creature:getPlayer()
            if not participant then
                return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
            end

            if participant:getLevel() < config.level_req then
                return player:sendCancelMessage(participant:getName() .. " is not the required level.")
            end

            if participant.uid == player.uid then
                pull_player = true
            end

            participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
        end
    end

    if #participants < config.min_players then
        return player:sendCancelMessage("You do not have the required amount of participants.")
    end

    if not pull_player then
        return player:sendCancelMessage("You are in the wrong position.")
    end

    for i = 1, #monsters do
        local toPos = monsters[i].pos
        if not Tile(toPos) then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end

    local cid_array = {}
    for i = 1, #participants do
        participants[i].participant:teleportTo(participants[i].toPos)
        participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
        cid_array[#cid_array + 1] = participants[i].participant.uid
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
    end

    item:transform(config.pulled_id)
    player:setStorageValue(112285, os.time() + cooldown)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
    return true

    else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Lever is broke, try tomorrow")
end
end

13:18 Lever is broke, try tomorrow
13:18 Lever is broke, try tomorrow
 
13:18 Lever is broke, try tomorrow
Post automatically merged:



13:18 Lever is broke, try tomorrow
13:18 Lever is broke, try tomorrow
Lua:
local config = {
    cooldown = 15, -- in seconds - (Make it 'seconds * minutes * hours' - its will be '60 * 60 * 20' for 20 hours) (player cooldown)
    cooldown_storage = 45001,
    duration = 10, -- time till reset, in minutes (lever cooldown)
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)
 
    local tile = Tile(position)
 
    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end
 
    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end
 
    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end
 
    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end
 
    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
    if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end
 
    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.cooldown_storage) >= os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Lever is broke, try tomorrow")
        return true
    end
 
    if item.itemid ~= config.lever_id then
        return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
    end
 
    local participants, pull_player = {}, false
    for i = 1, #player_positions do
        local fromPos = player_positions[i].fromPos
        local tile = Tile(fromPos)
        if not tile then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
 
        local creature = tile:getBottomCreature()
        if creature then
            local participant = creature:getPlayer()
            if not participant then
                return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
            end
 
            if participant:getLevel() < config.level_req then
                return player:sendCancelMessage(participant:getName() .. " is not the required level.")
            end
 
            if participant.uid == player.uid then
                pull_player = true
            end
 
            participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
        end
    end
 
    if #participants < config.min_players then
        return player:sendCancelMessage("You do not have the required amount of participants.")
    end
 
    if not pull_player then
        return player:sendCancelMessage("You are in the wrong position.")
    end
 
    for i = 1, #monsters do
        local toPos = monsters[i].pos
        if not Tile(toPos) then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end
 
    local cid_array = {}
    for i = 1, #participants do
        participants[i].participant:teleportTo(participants[i].toPos)
        participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
        cid_array[#cid_array + 1] = participants[i].participant.uid
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
    end
 
    item:transform(config.pulled_id)
    player:setStorageValue(config.cooldown_storage, os.time() + config.cooldown)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
    return true
end
 
Last edited:
Lua:
local config = {
    cooldown = 15, -- in seconds - (Make it 'seconds * minutes * hours' - its will be '60 * 60 * 20' for 20 hours) (player cooldown)
    cooldown_storage = 45001,
    duration = 10, -- time till reset, in minutes (lever cooldown)
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
    if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.cooldown_storage) >= os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Lever is broke, try tomorrow")
        return true
    end

    if item.itemid ~= config.lever_id then
        return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
    end

    local participants, pull_player = {}, false
    for i = 1, #player_positions do
        local fromPos = player_positions[i].fromPos
        local tile = Tile(fromPos)
        if not tile then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end

        local creature = tile:getBottomCreature()
        if creature then
            local participant = creature:getPlayer()
            if not participant then
                return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
            end

            if participant:getLevel() < config.level_req then
                return player:sendCancelMessage(participant:getName() .. " is not the required level.")
            end

            if participant.uid == player.uid then
                pull_player = true
            end

            participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
        end
    end

    if #participants < config.min_players then
        return player:sendCancelMessage("You do not have the required amount of participants.")
    end

    if not pull_player then
        return player:sendCancelMessage("You are in the wrong position.")
    end

    for i = 1, #monsters do
        local toPos = monsters[i].pos
        if not Tile(toPos) then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end

    local cid_array = {}
    for i = 1, #participants do
        participants[i].participant:teleportTo(participants[i].toPos)
        participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
        cid_array[#cid_array + 1] = participants[i].participant.uid
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
    end

    item:transform(config.pulled_id)
    player:setStorageValue(config.cooldown_storage, os.time() + config.cooldown)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
    return true
end
all the time, it says: The quest is currently in use. Cooldown is 10 minutes.
Post automatically merged:

Lua:
local config = {
    cooldown = 15, -- in seconds - (Make it 'seconds * minutes * hours' - its will be '60 * 60 * 20' for 20 hours) (player cooldown)
    cooldown_storage = 45001,
    duration = 10, -- time till reset, in minutes (lever cooldown)
    level_req = 150, -- minimum level to do quest
    min_players = 1, -- minimum players to join quest
    lever_id = 9825, -- id of lever before pulled
    pulled_id = 9826, -- id of lever after pulled
}

local player_positions = {
    [1] = {fromPos = Position(33455, 31493, 13), toPos = Position(33457, 31465, 13)},
    [2] = {fromPos = Position(33456, 31493, 13), toPos = Position(33457, 31465, 13)},
    [3] = {fromPos = Position(33457, 31493, 13), toPos = Position(33457, 31465, 13)},
    [4] = {fromPos = Position(33458, 31493, 13), toPos = Position(33457, 31465, 13)},
    [5] = {fromPos = Position(33459, 31493, 13), toPos = Position(33457, 31465, 13)}
}

local monsters = {
    [1] = {pos = Position(33457, 31475, 13), name = "Duke Krule"}
}
local quest_range = {fromPos = Position(33445, 31463, 13), toPos = Position(33464, 31482, 13)} -- see image in thread for explanation

local exit_position = Position(32352, 32161, 13) -- Position completely outside the quest area

function doResetTheBossDukeKrule(position, cid_array)

    local tile = Tile(position)

    local item = tile and tile:getItemById(config.pulled_id)
    if not item then
        return
    end

    local monster_names = {}
    for key, value in pairs(monsters) do
        if not isInArray(monster_names, value.name) then
            monster_names[#monster_names + 1] = value.name
        end
    end

    for i = 1, #monsters do
        local creatures = Tile(monsters[i].pos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for i = 1, #player_positions do
        local creatures = Tile(player_positions[i].toPos):getCreatures()
        for key, creature in pairs(creatures) do
            if isInArray(monster_names, creature:getName()) then
                creature:remove()
            end
        end
    end

    for key, cid in pairs(cid_array) do
        local participant = Player(cid)
    if participant and isInRange(participant:getPosition(), quest_range.fromPos, quest_range.toPos) then
            participant:teleportTo(exit_position)
            exit_position:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end

    item:transform(config.lever_id)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.cooldown_storage) >= os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Lever is broke, try tomorrow")
        return true
    end

    if item.itemid ~= config.lever_id then
        return player:sendCancelMessage("The quest is currently in use. Cooldown is " .. config.duration .. " minutes.")
    end

    local participants, pull_player = {}, false
    for i = 1, #player_positions do
        local fromPos = player_positions[i].fromPos
        local tile = Tile(fromPos)
        if not tile then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. fromPos.x .. ", " .. fromPos.y .. ", " .. fromPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end

        local creature = tile:getBottomCreature()
        if creature then
            local participant = creature:getPlayer()
            if not participant then
                return player:sendCancelMessage(participant:getName() .. " is not a valid participant.")
            end

            if participant:getLevel() < config.level_req then
                return player:sendCancelMessage(participant:getName() .. " is not the required level.")
            end

            if participant.uid == player.uid then
                pull_player = true
            end

            participants[#participants + 1] = {participant = participant, toPos = player_positions[i].toPos}
        end
    end

    if #participants < config.min_players then
        return player:sendCancelMessage("You do not have the required amount of participants.")
    end

    if not pull_player then
        return player:sendCancelMessage("You are in the wrong position.")
    end

    for i = 1, #monsters do
        local toPos = monsters[i].pos
        if not Tile(toPos) then
            print(">> ERROR: Annihilator tile does not exist for Position(" .. toPos.x .. ", " .. toPos.y .. ", " .. toPos.z .. ").")
            return player:sendCancelMessage("There is an issue with this quest. Please contact an administrator.")
        end
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end

    local cid_array = {}
    for i = 1, #participants do
        participants[i].participant:teleportTo(participants[i].toPos)
        participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
        cid_array[#cid_array + 1] = participants[i].participant.uid
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have 10 minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.")
    end

    item:transform(config.pulled_id)
    player:setStorageValue(config.cooldown_storage, os.time() + config.cooldown)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 1000,  toPosition, cid_array)
    return true
end

now it works, but the problem is when I leave the room, the boss doesn't disappear. so the next one to enter, stay with 2 boss
 
Last edited:
Back
Top