• 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 kick boss

mattehj

Member
Joined
Oct 8, 2009
Messages
80
Reaction score
16
Hello. I've made a custom boss. The problem is if another team use lever while a player inside, the boss disappear. It just poffs away

How can you fix this? :eek:

Oh lol i forgott to add script. I'm stupid.
Sorry! Here it is
Lua:
-- lever to MoneyPls

local config = {
    requiredLevel = 20,
    daily = true,
    roomCenterPosition = Position(33349, 27225, 13),
    playerPositions = {
        Position(33346, 27243, 13),
        Position(33347, 27243, 13),
        Position(33348, 27243, 13),
        Position(33349, 27243, 13),
        Position(33350, 27243, 13)
    },
    teleportPosition = Position(33349, 27230, 13),
    bossPosition = Position(33349, 27225, 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.EgnaBossar.MoneyPls) > 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("MoneyPls", 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.EgnaBossar.MoneyPls, os.time() + 20*60*60) -- 20 hours
        end
        
        config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
    end

    item:transform(9825)
    return true
end

leverboss:uid(13000)
leverboss:register()
 
Add a check to see if there are players inside the room and you will have it working as you want, use spectators or whatever you want
 
How do i implement deleting old mobs?
Should it be local specs, loop = Game.getSpectators(config.roomCenterPosition, false, false, 14, 14, 13, 13)
?
 
Use a function:
Lua:
function Player:doCheckBossRoom(bossName, fromPos, toPos)
    if self then
        for x = fromPos.x, toPos.x do
            for y = fromPos.y, toPos.y do
                for z = fromPos.z, toPos.z do
                    local sqm = Tile(Position(x, y, z))
                    if sqm then
                        if sqm:getTopCreature() and sqm:getTopCreature():isPlayer() then
                            self:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You must wait. Someone is challenging '..bossName..' now.')
                            return false
                        end
                    end
                end
            end
        end
        -- Room cleaning
        for x = fromPos.x, toPos.x do
            for y = fromPos.y, toPos.y do
                for z = fromPos.z, toPos.z do
                    local sqm = Tile(Position(x, y, z))
                    if sqm and sqm:getTopCreature() then
                        local monster = sqm:getTopCreature()
                        if monster then
                            monster:remove()
                        end
                    end
                end
            end
        end
    end
    return true
end

then in script
Code:
        if not player:doCheckBossRoom(bossName, roomLeftTopPos, roomRightBottomPos) then
            return true
        end
instead of:
Lua:
        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
 
I did this now, And now i cant use lever at all

Lua:
-- lever to MoneyPls

local config = {
    requiredLevel = 20,
    daily = true,
    roomCenterPosition = Position(33349, 27225, 13),
    playerPositions = {
        Position(33346, 27243, 13),
        Position(33347, 27243, 13),
        Position(33348, 27243, 13),
        Position(33349, 27243, 13),
        Position(33350, 27243, 13)
    },
    teleportPosition = Position(33349, 27230, 13),
    bossPosition = Position(33349, 27225, 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.EgnaBossar.MoneyPls) > 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


         if not player:doCheckBossRoom(bossName, roomLeftTopPos, roomRightBottomPos) then
            return true
        end
        -- Spawn boss
        Game.createMonster("MoneyPls", 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.EgnaBossar.MoneyPls, os.time() + 20*60*60) -- 20 hours
        end
        
        config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
    end

    item:transform(9825)
    return true
end

leverboss:uid(13000)
leverboss:register()
 
Erm, write values in function's params.
Now i cant use the lever when adding the values

Lua:
-- lever to MoneyPls

local config = {
    requiredLevel = 20,
    daily = true,
    roomCenterPosition = Position(33349, 27225, 13),
    playerPositions = {
        Position(33346, 27243, 13),
        Position(33347, 27243, 13),
        Position(33348, 27243, 13),
        Position(33349, 27243, 13),
        Position(33350, 27243, 13)
    },
         roomLeftTopPos(33346,27216,13),
         roomRightBottomPos(33352,27233,13)
    teleportPosition = Position(33349, 27230, 13),
    bossPosition = Position(33349, 27225, 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.EgnaBossar.MoneyPls) > 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
           if not player:doCheckBossRoom(bossName, roomLeftTopPos, roomRightBottomPos) then
            return true
        end
        -- Spawn boss
        Game.createMonster("MoneyPls", 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.EgnaBossar.MoneyPls, os.time() + 20*60*60) -- 20 hours
        end
        
        config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
    end

    item:transform(9825)
    return true
end

leverboss:uid(13000)
leverboss:register()
 
Now i cant use the lever when adding the values

Lua:
-- lever to MoneyPls

local config = {
    requiredLevel = 20,
    daily = true,
    roomCenterPosition = Position(33349, 27225, 13),
    playerPositions = {
        Position(33346, 27243, 13),
        Position(33347, 27243, 13),
        Position(33348, 27243, 13),
        Position(33349, 27243, 13),
        Position(33350, 27243, 13)
    },
         roomLeftTopPos(33346,27216,13),
         roomRightBottomPos(33352,27233,13)
    teleportPosition = Position(33349, 27230, 13),
    bossPosition = Position(33349, 27225, 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.EgnaBossar.MoneyPls) > 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
           if not player:doCheckBossRoom(bossName, roomLeftTopPos, roomRightBottomPos) then
            return true
        end
        -- Spawn boss
        Game.createMonster("MoneyPls", 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.EgnaBossar.MoneyPls, os.time() + 20*60*60) -- 20 hours
        end
       
        config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
    end

    item:transform(9825)
    return true
end

leverboss:uid(13000)
leverboss:register()
You forgot config. before params
 
Back
Top