• 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 remover monster

leandroluck

New Member
Joined
Dec 24, 2010
Messages
104
Reaction score
1
Code:
local function roomIsOccupied(bossposition, rangeX, rangeY)
    local spectators = Game.getSpectators(bossposition, false, false, rangeX, rangeX, rangeY, rangeY)
    if #spectators ~= 0 then
        return true
    end

    return false
end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
   
    if not player then
        return true
    end
   
 
         
            if roomIsOccupied(tmpConfig.bossposition, tmpConfig.rangeX, tmpConfig.rangeY) then
            player:sendTextMessage(MESSAGE_STATUS_WARNING, 'There is someone in the room.')
              player:teleportTo(fromPosition, true)
            fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

well this is part of my script if you have a player in the room it will not let you in this part works I would like it to check if it has only monsters in the room if it removes the monster
 
Solution
Lua:
local config = {
    requiredLevel = 100,
    daily = false,
    centerPosition = Position(32799, 32829, 14),
    rangeX = 20,
    rangeY = 20,
    timeopen = 1200,
    timekill = 15, 
    playerPositions = {
        Position(32759, 32868, 14),
    },
    newPositions = {
        Position(32795, 32816, 14),
    },
    demonPositions = {
        Position(32799, 32829, 14)
    }
}
local function checkPlayers(centerPosition, rangeX, rangeY)
    local spectators = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
    for _, spec in ipairs(spectators) do
        if spec:isPlayer() then
            return true
        end
    end
    return false
end

local function cleanBossRoom(centerPosition, rangeX...
Use this function

Lua:
function clearBossRoom(playerId, centerPosition, rangeX, rangeY, exitPosition)
    local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isPlayer() and spectator.uid == playerId then
            spectator:teleportTo(exitPosition)
            exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
        end

        if spectator:isMonster() then
            spectator:remove()
        end
    end
end

Credits to Vankk
 
Use this function

Lua:
function clearBossRoom(playerId, centerPosition, rangeX, rangeY, exitPosition)
    local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isPlayer() and spectator.uid == playerId then
            spectator:teleportTo(exitPosition)
            exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
        end

        if spectator:isMonster() then
            spectator:remove()
        end
    end
end

Credits to Vankk
the problem with this function in my test is if player in the room was removing the monster
 
I can't understand ... Do you want the function to work in what way?
player + monster in the room do nothing
room with only monster clean room.


Its even function with the player in the room she is removing the monster

bump

bump

bump

bump

bump

bump
 
Last edited by a moderator:
Lua:
local function roomHasPlayer(centerPosition, rangeX, rangeY)
    return #(Game.getSpectators(centerPosition, false, true, rangeX, rangeX, rangeY, rangeY)) > 0
end

function clearBossRoom(playerId, centerPosition, rangeX, rangeY, exitPosition)
    if roomHasPlayer(centerPosition, rangeX, rangeY) then
        return
    end
    local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isMonster() then
            spectator:remove()
        end
    end
end
 
Lua:
local function roomHasPlayer(centerPosition, rangeX, rangeY)
    return #(Game.getSpectators(centerPosition, false, true, rangeX, rangeX, rangeY, rangeY)) > 0
end

function clearBossRoom(playerId, centerPosition, rangeX, rangeY, exitPosition)
    if roomHasPlayer(centerPosition, rangeX, rangeY) then
        return
    end
    local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isMonster() then
            spectator:remove()
        end
    end
end
teste
same problem.
played in the room does not let enter(ok)
monster in the room just is not deleting the monster

The action I'm trying to create is below


Code:
local config = {
    requiredLevel = 100,
    daily = false,
    centerDemonRoomPosition = Position(32799, 32829, 14),
        rangeX = 20, 
    rangeY = 20,
    timeopen = 1200,
       timekill = 15,  
    playerPositions = {
        Position(32759, 32868, 14),

    },
    newPositions = {
    Position(32795, 32816, 14),

    },
    demonPositions = {
        Position(32799, 32829, 14)
    }
}

local function roomIsOccupied(bossposition, rangeX, rangeY)
    local spectators = Game.getSpectators(bossposition, false, false, rangeX, rangeX, rangeY, rangeY)
    if #spectators ~= 0 then
        return true
    end

    return false
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 9826 then
    local storePlayers, playerTile = {}
   
local tmpConfig = config
    if not tmpConfig then
        return true
    end
   
        for i = 1, #config.playerPositions do
            playerTile = Tile(config.playerPositions[i]):getTopCreature()
           
        if playerTile and playerTile:getLevel() < config.requiredLevel then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "All the players need to be level ".. config.requiredLevel .." or higher.")
                return true
            end

            storePlayers[#storePlayers + 1] = playerTile
        end
        if roomIsOccupied(tmpConfig.centerDemonRoomPosition, tmpConfig.rangeX, tmpConfig.rangeY) then
              player:sendTextMessage(TALKTYPE_MONSTER_SAY, 'There is someone in the room.')
            return true
    end
        local specs, spec = Game.getSpectators(config.centerDemonRoomPosition, false, false, 3, 3, 2, 2)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Uma equipe ja esta dentro da sala de quest,aguarde..")
                return true
            end

            spec:remove()
        end

        for i = 1, #config.demonPositions do

            Game.createMonster("demon", config.demonPositions[i])
            end

        local players
        for i = 1, #storePlayers do
            players = storePlayers[i]
            config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
            players:teleportTo(config.newPositions[i])
            player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You have ' .. config.timekill .. ' minute(s) to kill lloyd.')
            config.newPositions[i]:sendMagicEffect(CONST_ME_ENERGYAREA)
            players:setDirection(DIRECTION_EAST)
        end
    elseif item.itemid == 9825 then
        if config.daily then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE))
            return true
        end
    end

    item:transform(item.itemid == 9826 and 9825 or 9826)
    return true
end
 
Lua:
local config = {
    requiredLevel = 100,
    daily = false,
    centerPosition = Position(32799, 32829, 14),
    rangeX = 20,
    rangeY = 20,
    timeopen = 1200,
    timekill = 15, 
    playerPositions = {
        Position(32759, 32868, 14),
    },
    newPositions = {
        Position(32795, 32816, 14),
    },
    demonPositions = {
        Position(32799, 32829, 14)
    }
}
local function checkPlayers(centerPosition, rangeX, rangeY)
    local spectators = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
    for _, spec in ipairs(spectators) do
        if spec:isPlayer() then
            return true
        end
    end
    return false
end

local function cleanBossRoom(centerPosition, rangeX, rangeY)
    local spectators = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
    for _, spec in ipairs(spectators) do
        if spec:isMonster() then
            spec:remove()
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 9826 then
        local storePlayers, playerTile = {}
        local tmpConfig = config
        if not tmpConfig then
            return true
        end
  
        for i = 1, #config.playerPositions do
            playerTile = Tile(config.playerPositions[i]):getTopCreature()
            if playerTile and playerTile:getLevel() < config.requiredLevel then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "All the players need to be level ".. config.requiredLevel .." or higher.")
                return true
            end
            storePlayers[#storePlayers + 1] = playerTile
        end

        if roomIsOccupied(tmpConfig.centerPosition, tmpConfig.rangeX, tmpConfig.rangeY) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'There is someone in the room.')
            return true
        end


        cleanBossRoom(tmpConfig.centerPosition, tmpConfig.rangeX, tmpConfig.rangeY)
       
        for i = 1, #config.demonPositions do
            Game.createMonster("demon", config.demonPositions[i])
        end
        local players
        for i = 1, #storePlayers do
            players = storePlayers[i]
            config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
            players:teleportTo(config.newPositions[i])
            player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You have ' .. config.timekill .. ' minute(s) to kill lloyd.')
            config.newPositions[i]:sendMagicEffect(CONST_ME_ENERGYAREA)
            players:setDirection(DIRECTION_EAST)
        end
    elseif item.itemid == 9825 then
        if config.daily then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE))
            return true
        end
    end
    item:transform(item.itemid == 9826 and 9825 or 9826)
    return true
end
 
Solution
Back
Top