• 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!

Boss lever

dfs1

Member
Joined
Aug 27, 2011
Messages
82
Solutions
1
Reaction score
8
Hello, someone help me with these scripts please, give only the time Storage to the person who clicks the lever, the others do not give time storage and they can do it as many times as they want

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

local player_positions = {
    [1] = {fromPos = Position(579, 390, 5), toPos = Position(589, 394, 7)},
    [2] = {fromPos = Position(580, 390, 5), toPos = Position(589, 394, 7)},
    [3] = {fromPos = Position(581, 390, 5), toPos = Position(589, 394, 7)},
    [4] = {fromPos = Position(582, 390, 5), toPos = Position(589, 394, 7)}
}

local monsters = {
    [1] = {pos = Position(601, 396, 7), name = "dragon lord"}
}
local quest_range = {fromPos = Position(583, 388, 7), toPos = Position(605, 403, 7)} -- see image in thread for explanation

local exit_position = Position(584, 390, 6) -- Position completely outside the quest area

local theUnwelcome = Action()

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

local function removeBoss()
local specs, spec = Game.getSpectators(Position(595, 396, 7), false, false, 10, 10, 10, 10)
    for j = 1, #specs do
        spec = specs[j]
        if spec:getName():lower() == 'dragon lord' then
            spec:remove()
        end
    end
end

function theUnwelcome.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.cooldown_storage) >= os.time() then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Try Again in 20 Hours.")
        return true
    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: Soul Quest 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: Soul Quest 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
        removeBoss()
        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 * 2000,  toPosition, cid_array)
    return true
end

theUnwelcome:uid(42606)
theUnwelcome:register()
 
Solution
Try this one, just replace onUse function
Lua:
function theUnwelcome.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.cooldown_storage) >= os.time() then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot use this lever.")
        return true
    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: Soul Quest 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...
Try this one, just replace onUse function
Lua:
function theUnwelcome.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(config.cooldown_storage) >= os.time() then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot use this lever.")
        return true
    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: Soul Quest 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: Soul Quest 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
        removeBoss()
        Game.createMonster(monsters[i].name, monsters[i].pos, false, true)
    end
 
    local cid_array = {}
    for i = 1, #participants do
        local cid = participants[i].participant
        if cid:getStorageValue(config.cooldown_storage) < os.time() then
            cid:setStorageValue(config.cooldown_storage, os.time() + config.cooldown)
            cid: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.")
            cid:teleportTo(participants[i].toPos)
            participants[i].toPos:sendMagicEffect(CONST_ME_TELEPORT)
            cid_array[#cid_array + 1] = participants[i].participant.uid
        else
            cid:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You still cannot enter to this boss.")
        end
    end
    -- no need but just in case
    if (#cid_array == 0) then
        return true
    end

    item:transform(config.pulled_id)
    addEvent(doResetTheBossDukeKrule, config.duration * 60 * 2000,  toPosition, cid_array)
    return true
end
 
Last edited:
Solution
Remove (L-144)
Lua:
player:setStorageValue(config.cooldown_storage, os.time() + config.cooldown)

Add this
Lua:
participants[i].participant:setStorageValue(config.cooldown_storage, os.time() + config.cooldown)

Below (L-137)
Lua:
participants[i].participant:teleportTo(participants[i].toPos)
 
It didn't work, you can enter as many times as you want :/
Yeah, i see the issue now (only works at pulling the lever) but how exactly do you want it? Lets say, you have 4 players and 1 of them still cant enter, script should only teleport the 3 remained players or totally block the lever?
 
yes, it only works when using the lever, if you don't pull the lever the player who already entered teleports too.
Post automatically merged:

Yeah, i see the issue now (only works at pulling the lever) but how exactly do you want it? Lets say, you have 4 players and 1 of them still cant enter, script should only teleport the 3 remained players or totally block the lever?
It is what I need, that the player who has already entered cannot pass again.
 
yes, it worked, it leaves out the player who already did the mission, but now, more players can enter when there are players inside.
 
yes, it worked, it leaves out the player who already did the mission, but now, more players can enter when there are players inside.
I dont see any check for players inside on default script, are you sure it was working that way before?
 
Correct, I made a mistake in the script, lol
but I solved the problem, only if I kill the boss it doesn't clean the room you can see if there is something strange in the script I didn't find that error, only that is missing.

Lua:
local config = {
    leverUniqueID = 49006,
    requiredLevel = 100,
    daily = true,
    bossName = "dragon",
    storage = 7500,
    roomCenterPosition = Position(423, 483, 7),
    playerPositions = {
        Position(425, 488, 7),
        Position(424, 488, 7),
        Position(423, 488, 7),
        Position(422, 488, 7),
        Position(421, 488, 7)
    },
    teleportPosition = Position(423, 481, 7),
    bossPosition = Position(426, 485, 7),

    kickMinutes = 10, -- minutes
    kickPosition = Position(423, 490, 7)
}

local leverBoss = Action()

function leverBoss.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() == 1945 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, 3, 3, 3, 3)) 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, 3, 3, 3, 3)) 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 * 600)
    end

    item:transform(1945)
    return true
end

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

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