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

RevScripts [otbr] Boss arena

walltimer

Active Member
Joined
Aug 5, 2020
Messages
170
Reaction score
26
Why this script from one user of forum doesnt want to work for me? 'cant use lever'
Lua:
local configQuest = {
    actionId = 901,
    players = { -- Positions where players are standing to enter
        Tile(3051, 1828, 8),
        Tile(3051, 1829, 8),
        Tile(3051, 1830, 8),
        Tile(3051, 1831, 8),
        Tile(3051, 1832, 8),
        Tile(3051, 1833, 8),
        Tile(3051, 1834, 8)
    },
    minPlayers = 1, -- Minimum number of players that can enter. in this case 1 or more
    destination = Position(3056, 1831, 8), -- Position where the players will be teleported when entering the room
    requirements = {
        level = 2000, -- level required to enter the room
        storages = {} -- if you need some storage to be able to enter or several storages
    },
    room = {
        centerPos = Position(3068, 1831, 8), -- center of the room
        fromPos = Position(3055, 1812, 8), -- the upper left corner of the room
        toPos = Position(3084, 1844, 8) -- the lower right corner of the room
    },
    boss = {
        name = "Demon", -- boss name
        spawnPos = Position(3068, 1831, 8), -- spawn boss position
        exitIn = 1 -- minutes to get out of the room
    },
    debug = {
        enabled = false, -- for testing with /reload scripts
        exitPos = Position(3051, 1826, 8), -- Position to which players will be sent off after a while
        leverIds = {1945, 1946}, -- lever on / lever off
        admins = false -- detect administrators in the room
    }
}

local function getPlayersInQuest()
    local spectators = Game.getSpectators(configQuest.room.centerPos, false, true, configQuest.radius.x, configQuest.radius.x, configQuest.radius.y, configQuest.radius.y)
    local players = {}
    for _, spectator in pairs(spectators) do
        if spectator:getGroup():getId() == 1 or configQuest.debug.admins then
            players[#players +1] = spectator
        end
    end
    return players
end

local function closeQuest()
    local ground = configQuest.players[1]:getGround()
    for _, p in pairs(getPlayersInQuest()) do
        p:teleportTo(configQuest.debug.exitPos)
    end
    local boss = Monster(ground:getCustomAttribute("bossId"))
    if boss then
        boss:remove()
    end
    ground:removeCustomAttribute("evId")
end

local action = Action()
function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not configQuest.radius then
        configQuest.radius = {
            x = math.ceil((configQuest.room.toPos.x - configQuest.room.fromPos.x) / 2),
            y = math.ceil((configQuest.room.toPos.y - configQuest.room.fromPos.y) / 2)
        }
    end
    local leverCanUse = false
    local playerPosition = player:getPosition()
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end
    if not leverCanUse then
        return false
    end
    local questPlayers = getPlayersInQuest()
    for _, p in pairs(questPlayers) do
        if configQuest.debug.enabled then
            p:teleportTo(configQuest.debug.exitPos)
        end
    end
    if configQuest.debug.enabled then
        configQuest.debug.exitPos:sendMagicEffect(CONST_ME_TELEPORT)
    end
    local ground = configQuest.players[1]:getGround()
    local boss = Monster(ground:getCustomAttribute("bossId"))
    if boss then
        if configQuest.debug.enabled or #questPlayers == 0 then
            boss:remove()
            stopEvent(ground:getCustomAttribute("evId"))
            ground:removeCustomAttribute("evId")
        else
            player:sendCancelMessage(string.format("You must wait for the boss to be defeated or wait %d seconds.", ground:getCustomAttribute("now") - os.time()))
            return true
        end
    end
    local players = {}
    for _, tile in pairs(configQuest.players) do
        local p = tile:getTopCreature()
        if p and p:isPlayer() then
            if p:getLevel() < configQuest.requirements.level then
                player:sendCancelMessage(string.format("%s must be level %d or higher.", p:getName(), configQuest.requirements.level))
                p:getPosition():sendMagicEffect(CONST_ME_POFF)
                return true
            end
            for _, storage in pairs(configQuest.requirements.storages) do
                if p:getStorageValue(storage) == -1 then
                    player:sendCancelMessage(string.format("%s still cannot face this boss.", p:getName()))
                    p:getPosition():sendMagicEffect(CONST_ME_POFF)
                    return true
                end
            end
            players[#players +1] = p
        end
    end
    if #players < configQuest.minPlayers then
        player:sendCancelMessage(string.format("Sorry, only groups of %d or more players are allowed.", configQuest.minPlayers))
        return true
    end
    for _, p in pairs(players) do
        p:getPosition():sendMagicEffect(CONST_ME_POFF)
        p:teleportTo(configQuest.destination)
    end
    configQuest.destination:sendMagicEffect(CONST_ME_TELEPORT)
    boss = Game.createMonster(configQuest.boss.name, configQuest.boss.spawnPos)
    if boss then
        ground:setCustomAttribute("bossId", boss:getId())
        ground:setCustomAttribute("evId", addEvent(closeQuest, configQuest.boss.exitIn * 60 * 1000))
        ground:setCustomAttribute("now", os.time() + (configQuest.boss.exitIn * 60))
    end
    item:transform(item:getId() == configQuest.debug.leverIds[1] and configQuest.debug.leverIds[2] or configQuest.debug.leverIds[1])
    return true
end

action:aid(configQuest.actionId)
action:register()
 
Last edited by a moderator:
nothing..
Try adding print('lever used') at the beginning of onUse function.

If this prints 'lever used' in console then go ahead and verify the positions in configQuest.players:
Lua:
    local leverCanUse = false
    local playerPosition = player:getPosition()
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end

    if not leverCanUse then
        return false
    end
 
Try adding print('lever used') at the beginning of onUse function.

If this prints 'lever used' in console then go ahead and verify the positions in configQuest.players:
Lua:
    local leverCanUse = false
    local playerPosition = player:getPosition()
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end

    if not leverCanUse then
        return false
    end
nothing shows in console.
 
might be this ? L:67
Lua:
    local leverCanUse = false
because you have this
Code:
    if not leverCanUse then
        return false
    end
not false means true so that one says in true then return false end so the code doesn't continue the thing
 
nothing shows in console.
So this was a lie...

I just tested and it stops here:
Lua:
    local leverCanUse = false
    local playerPosition = player:getPosition()
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end
    if not leverCanUse then
        print('asd')
        return false -- STOPS HERE
    end
 
So this was a lie...

I just tested and it stops here:
Lua:
    local leverCanUse = false
    local playerPosition = player:getPosition()
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end
    if not leverCanUse then
        print('asd')
        return false -- STOPS HERE
    end
might be this ? L:67
Lua:
    local leverCanUse = false
because you have this
Code:
    if not leverCanUse then
        return false
    end
not false means true so that one says in true then return false end so the code doesn't continue the thing
because the variable leverCanUse should be true
 
because the variable leverCanUse should be true
Removing that part of the code will definitely solve the problem but I'm guessing he wishes to verfiy that the player stands on one of the tiles:
Lua:
    local leverCanUse = false
    local playerPosition = player:getPosition()
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end
 
Removing that part of the code will definitely solve the problem but I'm guessing he wishes to verfiy that the player stands on one of the tiles:
Lua:
    local leverCanUse = false
    local playerPosition = player:getPosition()
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end
then it should be like this not completely removed (if he want to confirm player's position
Lua:
    local leverCanUse = false
    local playerPosition = player:getPosition()
    if playerPosition == ADDHEREEXPECTEDPOSITIONVARIABLE then
        leverCanUse = true
    end
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end
 
then it should be like this not completely removed (if he want to confirm player's position
Lua:
    local leverCanUse = false
    local playerPosition = player:getPosition()
    if playerPosition == ADDHEREEXPECTEDPOSITIONVARIABLE then
        leverCanUse = true
    end
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end
This seems to be for that purpose
Lua:
leverCanUse = playerPosition == tile:getPosition()

But can't know for sure since mr walltimer hasn't said how he wants this to work.
 
then it should be like this not completely removed (if he want to confirm player's position
Lua:
    local leverCanUse = false
    local playerPosition = player:getPosition()
    if playerPosition == ADDHEREEXPECTEDPOSITIONVARIABLE then
        leverCanUse = true
    end
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end

ADDHEREEXPECTEDPOSITIONVARIABLE - what to add here, and how? show me axample ;P
This seems to be for that purpose
Lua:
leverCanUse = playerPosition == tile:getPosition()

But can't know for sure since mr walltimer hasn't said how he wants this to work.
its from this forum, u step on ground tile, press the lever and tp to room :)
 
1 player or 4 players? or for any count as there is players standing on the tiles? ex (3 on tiles then teleport 3, 5 on tiles teleport 5) i can't think of a better way to ask the question
 
1 player or 4 players? or for any count as there is players standing on the tiles? ex (3 on tiles then teleport 3, 5 on tiles teleport 5) i can't think of a better way to ask the question
besy way will be four player :) and only forum. Is there any option to make them (when teleport) remove each 5min 10cc ? if they dont have kick to temple?
 
Back
Top