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

Solved lever with a little loop

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
211
hello folks, I'm working on a quest that have one lever...
is 15 SQM's
divided like this:
LuQyGgK.png

then I need teleport each team to different rooms
each team must to be 3 players.... exemple:
if the team 1 have TWO players the third player must be the first of team 2
I do some code but it don't work :/
Code:
local Rooms = {
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)}
}

local PlayerPositions = {
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)},
    {position = Position(x, y, z)}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local roomIndex, storePlayers = 1, {}
    for i = 1, #PlayerPositions do
        local position = PlayerPositions[i].position
        local playerTile = Tile(PlayerPositions[i].position):getTopCreature()
        if playerTile then
            storePlayers[#storePlayers + 1] = playerTile
            for a = 1, 3 do
                local player = storePlayers[a]
                if player then
                    local position = Rooms[roomIndex].position
                    player:teleportTo(position)
                    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                    print('player Name: ' ..player:getName())
                end
                if a == 3 then
                    storePlayers = {}
                    roomIndex = roomIndex + 1
                end
            end
        end
    end
    return true
end
I got error in:
local position = Rooms[roomIndex].position
and ofc I don't check if the creature in the sqm is player, I'm testing with monsters :p
I can't see what is wrong in this line, please someone give me a light
thank you
edit: with this code the first creatures go to different rooms,
player 1 is teleported to room 1....
the problem seems with how I handle with each team and the index, but I can't solve :mad:
 
Last edited:
SOLVED! Thanks for @Xikini for the feed in private!
I was wrong, I store just the first player of each team and send to separeted rooms...
just move the loop for a = 1, 3 do to another place :)
 
Back
Top