• 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 Script not working correctly

mimsol

New Member
Joined
Mar 18, 2020
Messages
83
Reaction score
2
Anyone have an idee why Only 1 person gets Teleported into a Boss room even when 5 positions are given ?

Lua:
-- lever to DukeKrule
local config = {
    requiredLevel = 0,
    daily = true,
    roomCenterPosition = Position(33456, 31473, 13),
    playerPositions = {
        Position(33424, 31413, 13),
        Position(33425, 31413, 13),
        Position(33426, 31413, 13),
        Position(33427, 31413, 13),
        Position(33428, 31413, 13)
    },
    teleportPosition = Position(33424, 31447, 13),
    bossPosition = Position(33424, 31436, 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):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.Kilmaresh.UrmahlulluTimer) > 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
            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("Sir Baeloc", config.bossPosition)

        -- Teleport team participants
        for i = 1, #team do
            team:getPosition():sendMagicEffect(CONST_ME_POFF)
            team:teleportTo(config.teleportPosition)
            -- Assign boss timer
            team:setStorageValue(Storage.dark_trails.DukeTimer, os.time() + 4*60*60) -- 4 hours
        end

        config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
    end

    item:transform(9825)
    return true
end

leverboss:aid(65006)
leverboss:register()
 
Solution
B
Yes. In the first iteration of the loop, the player is teleported at line 68, but then the script breaks because of the error on line 70.

Once you've fixed the storage issue, the script wont break and it will loop through and teleport all players as intended.
Try

Lua:
-- lever to DukeKrule
local config = {
    requiredLevel = 0,
    daily = true,
    roomCenterPosition = Position(33456, 31473, 13),
    playerPositions = {
        Position(33424, 31413, 13),
        Position(33425, 31413, 13),
        Position(33426, 31413, 13),
        Position(33427, 31413, 13),
        Position(33428, 31413, 13)
    },
    teleportPosition = Position(33424, 31447, 13),
    bossPosition = Position(33424, 31436, 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.Kilmaresh.UrmahlulluTimer) > 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("Sir Baeloc", config.bossPosition)

        -- Teleport team participants
        for _, p in pairs(team) do
            p:getPosition():sendMagicEffect(CONST_ME_POFF)
            p:teleportTo(config.teleportPosition)
            -- Assign boss timer
            p:setStorageValue(Storage.dark_trails.DukeTimer, os.time() + 4*60*60) -- 4 hours
        end

        config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
    end

    item:transform(9825)
    return true
end

leverboss:aid(65006)
leverboss:register()
 
Last edited:
Line 30:
Lua:
participant = Tile(config.playerPositions):getTopCreature()

You're not using the incremented "i" in the for loop.

Replace line 30 with:
Lua:
participant = Tile(config.playerPositions[i]):getTopCreature()
 
1628146144322.png
Okey i inserted the Line from @Boy67 and checked the Tile cord there was one wrong position but i still get this error here and still only 1 person get telported into the room ;/
Post automatically merged:

-- lever to DukeKrule
local config = {
requiredLevel = 0,
daily = true,
roomCenterPosition = Position(33424, 31438, 13),
playerPositions = {
Position(33424, 31413, 13),
Position(33425, 31413, 13),
Position(33426, 31413, 13),
Position(33427, 31413, 13),
Position(33428, 31413, 13)
},
teleportPosition = Position(33424, 31447, 13),
bossPosition = Position(33424, 31436, 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):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.Kilmaresh.UrmahlulluTimer) > 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
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("Sir Baeloc", config.bossPosition)

-- Teleport team participants
for _, p in pairs(team) do
p:getPosition():sendMagicEffect(CONST_ME_POFF)
p:teleportTo(config.teleportPosition)
-- Assign boss timer
p:setStorageValue(Storage.dark_trails.DukeTimer, os.time() + 4*60*60) -- 4 hours
end

config.teleportPosition:sendMagicEffect(CONST_ME_ENERGYAREA)
end

item:transform(9825)
return true
end

leverboss:aid(65006)
leverboss:register()
 

Attachments

Last edited:
Line 70:
Lua:
p:setStorageValue(Storage.dark_trails.DukeTimer, os.time() + 4*60*60) -- 4 hours

dark_trails storage doesn't exist.

I haven't coded OT servers for 10 years so I wouldn't know where to instantiate it.
 
Yes. In the first iteration of the loop, the player is teleported at line 68, but then the script breaks because of the error on line 70.

Once you've fixed the storage issue, the script wont break and it will loop through and teleport all players as intended.
 
Solution
Back
Top