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

Lua remove player in boss room

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
What is happening is that this function is removing players out of nowhere when they rotate the bosses on my server, as I have an area only of bosses so they can do several, and when a certain boss arrives it simply throws them out of the room .

Lua:
local config = {
    bossPosition = Position(532, 462, 10),
    bossName = "World Devourer",
    playerPositions = {
        Position(493, 454, 10),
        Position(493, 455, 10),
        Position(493, 456, 10),
        Position(493, 457, 10),
        Position(493, 458, 10),
        Position(494, 454, 10),
        Position(494, 455, 10),
        Position(494, 456, 10),
        Position(494, 457, 10),
        Position(494, 458, 10),
        Position(495, 454, 10),
        Position(495, 455, 10),
        Position(495, 456, 10),
        Position(495, 457, 10),
        Position(495, 458, 10)

    },
    newPositions = {
        Position(523, 461, 10),
        Position(523, 462, 10),
        Position(523, 463, 10),
        Position(523, 464, 10),
        Position(522, 464, 10),
        Position(522, 463, 10),
        Position(522, 462, 10),
        Position(522, 461, 10),
        Position(521, 461, 10),
        Position(521, 462, 10),
        Position(521, 463, 10),
        Position(521, 464, 10),
        Position(520, 462, 10),
        Position(520, 463, 10),
        Position(525, 462, 10)
    },   
    attempts = {     
        storage = 15695, -- Storage where we keep the waiting time
        hours = 12, -- 12 hours
        hoursVip = 8, -- 8 hours
        kickTime = 25 -- 25 minutes
    },       
    bossArea = {
        fromPos = Position(512, 451, 10), -- Upper left corner of the room
        toPos = Position(542, 478, 10), -- Lower right corner of the room     
        exitPosition = Position(498, 457, 10) -- If the participants take too long they will be kicked from the room to this position
    },   
}

local function getSpectators()
    if not config.centerPosition then
        config.diffX = math.ceil((config.bossArea.toPos.x - config.bossArea.fromPos.x) / 2)
        config.diffY = math.ceil((config.bossArea.toPos.y - config.bossArea.fromPos.y) / 2)
        config.centerPosition = config.bossArea.fromPos + Position(config.diffX, config.diffY, 0)
    end
    return Game.getSpectators(config.centerPosition, false, false, config.diffX, config.diffX, config.diffY, config.diffY)
end

function onUse(player, item, fromPosition, target, toPosition, monster, isHotkey)
    if item.itemid == 9825 then
        if player:getPosition() ~= Position(494, 454, 10) then
            Position(494, 454, 10):sendMagicEffect(CONST_ME_TUTORIALARROW)   
            item:transform(9826)
            return true
        end   
    
        local participants, playerTile = {}   
        for index, pos in pairs(config.playerPositions) do
            local tile = Tile(pos)
            
            if not tile then                 
                return true
            end
            
            local participant = tile:getTopCreature(player)
            
            if participant and participant:isPlayer() then
                
                if participant:getStorageValue(config.attempts.storage) >= os.time() then
                    player:sendCancelMessage(string.format("The player %s must wait a while before being able to enter again.", participant:getName()))
                    return true
                end
    
                participants[#participants +1] = participant           
            end           
        end
        
        local spectators = getSpectators()
        for _, spectator in pairs(spectators) do
            if spectator:isPlayer() then
                player:sendCancelMessage("At this time the room is occupied, please try again later.")           
                return true
            end
        end       

        for index, participant in pairs(participants) do           
            participant:getPosition():sendMagicEffect(CONST_ME_POFF)               
            participant:teleportTo(config.newPositions[index], false)
            participant:getPosition():sendMagicEffect(CONST_ME_TELEPORT)           
        
            if participant:isVip() then
                participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.hoursVip * 3600)
            else
                participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.hours * 3600)
            end                           
        end
        
        for _, spectator in pairs(spectators) do spectator:remove() end
        local monster = Game.createMonster(config.bossName, config.bossPosition)
    
        if monster then
            monster:setReward(true)
        end               

        player:say(string.format('You have %i minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.', config.attempts.kickTime), TALKTYPE_MONSTER_SAY)
       kickerPlayerRoomAfferMin(participants, config.bossArea.fromPos, config.bossArea.toPos, config.bossArea.exitPosition, "You were kicked for exceeding the time limit within the boss room.", '', config.attempts.kickTime, true)   
        
    end

    item:transform(item.itemid == 9826 and 9825 or 9826)
    return true
end

Lua:
function kickerPlayerRoomAfferMin(playername, fromPosition, toPosition, teleportPos, message, monsterName, minutes,
            firstCall)
    local players = false
    if type(playername) == table then
        players = true
    end
    local player = false
    if not players then
        player = Player(playername)
    end
    local monster = {}
    if monsterName ~= "" then
        monster = getMonstersInArea(fromPosition, toPosition, monsterName)
    end
    if player == false and players == false then
        return false
    end
    if not players and player then
        if player:getPosition():isInRange(fromPosition, toPosition) and minutes == 0 then
            if monsterName ~= "" then
                for _, pid in pairs(monster) do
                    if pid:isMonster() then
                        if pid:getStorageValue("playername") == playername then
                            pid:remove()
                        end
                    end
                end
            else           

                cleanAreaQuest(fromPosition, toPosition)
            end
            player:teleportTo(teleportPos, true)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
            return true
        end
    else
        if minutes == 0 then
            if monsterName ~= "" then
                for _, pid in pairs(monster) do
                    if pid:isMonster() then
                        if pid:getStorageValue("playername") == playername then
                            pid:remove()
                        end
                    end
                end
            else               
                cleanAreaQuest(fromPosition, toPosition)
            end
            for _, pid in pairs(playername) do
                local player = Player(pid)
                if player and player:getPosition():isInRange(fromPosition, toPosition) then
                    player:teleportTo(teleportPos, true)
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
                end
            end
            return true
        end
    end
    local min = 60 -- Use the 60 for 1 minute
    if (firstCall) then
        addEvent( kickerPlayerRoomAfferMin, 1000, playername, fromPosition, toPosition, teleportPos, message,
                monsterName, minutes, false)
    else
        local subt = minutes - 1
        if (monsterName ~= "") then
            if minutes > 3 and table.maxn(monster) == 0 then
                subt = 2
            end
        end
        addEvent(kickerPlayerRoomAfferMin, min * 1000, playername, fromPosition, toPosition, teleportPos, message,
                monsterName, subt, false)
    end
end
 
What is happening is that this function is removing players out of nowhere when they rotate the bosses on my server, as I have an area only of bosses so they can do several, and when a certain boss arrives it simply throws them out of the room .

Lua:
local config = {
    bossPosition = Position(532, 462, 10),
    bossName = "World Devourer",
    playerPositions = {
        Position(493, 454, 10),
        Position(493, 455, 10),
        Position(493, 456, 10),
        Position(493, 457, 10),
        Position(493, 458, 10),
        Position(494, 454, 10),
        Position(494, 455, 10),
        Position(494, 456, 10),
        Position(494, 457, 10),
        Position(494, 458, 10),
        Position(495, 454, 10),
        Position(495, 455, 10),
        Position(495, 456, 10),
        Position(495, 457, 10),
        Position(495, 458, 10)

    },
    newPositions = {
        Position(523, 461, 10),
        Position(523, 462, 10),
        Position(523, 463, 10),
        Position(523, 464, 10),
        Position(522, 464, 10),
        Position(522, 463, 10),
        Position(522, 462, 10),
        Position(522, 461, 10),
        Position(521, 461, 10),
        Position(521, 462, 10),
        Position(521, 463, 10),
        Position(521, 464, 10),
        Position(520, 462, 10),
        Position(520, 463, 10),
        Position(525, 462, 10)
    },
    attempts = {  
        storage = 15695, -- Storage where we keep the waiting time
        hours = 12, -- 12 hours
        hoursVip = 8, -- 8 hours
        kickTime = 25 -- 25 minutes
    },    
    bossArea = {
        fromPos = Position(512, 451, 10), -- Upper left corner of the room
        toPos = Position(542, 478, 10), -- Lower right corner of the room  
        exitPosition = Position(498, 457, 10) -- If the participants take too long they will be kicked from the room to this position
    },
}

local function getSpectators()
    if not config.centerPosition then
        config.diffX = math.ceil((config.bossArea.toPos.x - config.bossArea.fromPos.x) / 2)
        config.diffY = math.ceil((config.bossArea.toPos.y - config.bossArea.fromPos.y) / 2)
        config.centerPosition = config.bossArea.fromPos + Position(config.diffX, config.diffY, 0)
    end
    return Game.getSpectators(config.centerPosition, false, false, config.diffX, config.diffX, config.diffY, config.diffY)
end

function onUse(player, item, fromPosition, target, toPosition, monster, isHotkey)
    if item.itemid == 9825 then
        if player:getPosition() ~= Position(494, 454, 10) then
            Position(494, 454, 10):sendMagicEffect(CONST_ME_TUTORIALARROW)
            item:transform(9826)
            return true
        end
 
        local participants, playerTile = {}
        for index, pos in pairs(config.playerPositions) do
            local tile = Tile(pos)
         
            if not tile then              
                return true
            end
         
            local participant = tile:getTopCreature(player)
         
            if participant and participant:isPlayer() then
             
                if participant:getStorageValue(config.attempts.storage) >= os.time() then
                    player:sendCancelMessage(string.format("The player %s must wait a while before being able to enter again.", participant:getName()))
                    return true
                end
 
                participants[#participants +1] = participant        
            end        
        end
     
        local spectators = getSpectators()
        for _, spectator in pairs(spectators) do
            if spectator:isPlayer() then
                player:sendCancelMessage("At this time the room is occupied, please try again later.")        
                return true
            end
        end    

        for index, participant in pairs(participants) do        
            participant:getPosition():sendMagicEffect(CONST_ME_POFF)            
            participant:teleportTo(config.newPositions[index], false)
            participant:getPosition():sendMagicEffect(CONST_ME_TELEPORT)        
     
            if participant:isVip() then
                participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.hoursVip * 3600)
            else
                participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.hours * 3600)
            end                        
        end
     
        for _, spectator in pairs(spectators) do spectator:remove() end
        local monster = Game.createMonster(config.bossName, config.bossPosition)
 
        if monster then
            monster:setReward(true)
        end            

        player:say(string.format('You have %i minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.', config.attempts.kickTime), TALKTYPE_MONSTER_SAY)
       kickerPlayerRoomAfferMin(participants, config.bossArea.fromPos, config.bossArea.toPos, config.bossArea.exitPosition, "You were kicked for exceeding the time limit within the boss room.", '', config.attempts.kickTime, true)
     
    end

    item:transform(item.itemid == 9826 and 9825 or 9826)
    return true
end

I dont understand what you want, but if you want them never to be kicked out of the room just remove these two lines

Lua:
player:say(string.format('You have %i minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.', config.attempts.kickTime), TALKTYPE_MONSTER_SAY)
       kickerPlayerRoomAfferMin(participants, config.bossArea.fromPos, config.bossArea.toPos, config.bossArea.exitPosition, "You were kicked for exceeding the time limit within the boss room.", '', config.attempts.kickTime, true)

And if you want the players go in and out of the boss room at any moment(no 12h waiting) remove these lines

Lua:
if participant:getStorageValue(config.attempts.storage) >= os.time() then
                    player:sendCancelMessage(string.format("The player %s must wait a while before being able to enter again.", participant:getName()))
                    return true
                end

Lua:
if participant:isVip() then
                participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.hoursVip * 3600)
            else
                participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.hours * 3600)
            end


and if none of what I said here is what you want, try one more time to explain
 
Last edited:
I dont understand what you want, but if you want them never to be kicked out of the room just remove these two lines

Lua:
player:say(string.format('You have %i minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.', config.attempts.kickTime), TALKTYPE_MONSTER_SAY)
       kickerPlayerRoomAfferMin(participants, config.bossArea.fromPos, config.bossArea.toPos, config.bossArea.exitPosition, "You were kicked for exceeding the time limit within the boss room.", '', config.attempts.kickTime, true)

And if you want the players go in and out of the boss room at any moment(no 12h waiting) remove these lines

Lua:
if participant:getStorageValue(config.attempts.storage) >= os.time() then
                    player:sendCancelMessage(string.format("The player %s must wait a while before being able to enter again.", participant:getName()))
                    return true
                end

Lua:
if participant:isVip() then
                participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.hoursVip * 3600)
            else
                participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.hours * 3600)
            end


and if none of what I said here is what you want, try one more time to explain
What happens is that:

1. If the player makes the first boss in which the time is 15 minutes.
2. He kills the boss in 10 minutes, that is, there are 5 minutes left.
3. If he's going to kill another boss in a row, it doesn't seem to reset this time and simply kicks the player out of the room. It rarely happens on my server I had to take the kick because they were harming the players.
 
What happens is that:

1. If the player makes the first boss in which the time is 15 minutes.
2. He kills the boss in 10 minutes, that is, there are 5 minutes left.
3. If he's going to kill another boss in a row, it doesn't seem to reset this time and simply kicks the player out of the room. It rarely happens on my server I had to take the kick because they were harming the players.
So, the idea is, if he kill monster he gains + minutes in the room?

I'll take a look, but idk how long to come with a possible answear, hope some1 come first

But, i think its possible with creaturescript onkill,
 
Back
Top