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

RevScripts Destroy an item id outside of area? + Kill monsters inside radius?

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,099
Solutions
15
Reaction score
385
Location
Sweden
YouTube
Joriku
Hi,
how can I destroy an item of id outside of x y z top, bottom positions?

Not sure if this would be done using an aid put onto the given item to the player, the point of this is if an player leaves, dies or logs out of area in one way or another. The item removes itself from the player's backpack.

Then second question would be, how would I kill monsters inside the same radius of the first item?
Just slay, not remove since if they're removed, spawners will go out of work.

Here are some functions of an arena script I use to delete/reset if it helps with the process
Lua:
-- Outdated functions but works, remove mobs + players
local function doRemoveMonsterFromArea(fromPos, toPos)
    for _x = fromPos.x, toPos.x do
        for _y = fromPos.y, toPos.y do
            for _z = fromPos.z, toPos.z do
                local creature = getTopCreature({x = _x, y = _y, z = _z})
                if creature ~= nil then
                    if isMonster(creature.uid) then
                        doRemoveCreature(creature.uid)
                        --print("There's a creature, removing it..")
                    elseif isPlayer(creature.uid) then
                        local exitPosition = Position(1199, 888, 7) -- Exit position
                        local specs = Game.getSpectators(Position(1134, 830, 4), false, false, 20, 20, 20, 20) -- Radius of center square of arena
                        for _, spec in ipairs(specs) do
                            if spec:isPlayer() then
                                spec:teleportTo(exitPosition)
                            end
                        end
                        --print("There's a player or more, teleporting them out of the boss room..")
                    end
                else
                    --print("No creature found at position:", _x, _y, _z)
                end
            end
        end
    end
    return false
end

-- Check for monsters in arena
local function isMonstersInsideArena()
    for x = config.specPos.from.x, config.specPos.to.x do
        for y = config.specPos.from.y, config.specPos.to.y do
            for z = config.specPos.from.z, config.specPos.to.z do
                local tile = Tile(Position(x, y, z))
                local creatures = tile:getCreatures()
                if creatures then
                    for _, creature in ipairs(creatures) do
                        if creature:isMonster() then
                            return true
                        end
                    end
                end
            end
        end
    end
    return false
end

-- Check for players in arena
local function isPlayerInArena()
    for x = config.specPos.from.x, config.specPos.to.x do
        for y = config.specPos.from.y, config.specPos.to.y do
            for z = config.specPos.from.z, config.specPos.to.z do
                local tile = Tile(Position(x, y, z))
                local creatures = tile:getCreatures()
                if creatures then
                    for _, creature in ipairs(creatures) do
                        if creature:isPlayer() then
                            return true
                        end
                    end
                end
            end
        end
    end
    return false
end
 
(Note: The solution below will work best with an enclosed arena, with only one way in or out such as a teleport, otherwise it can get messy...)
You can assign events to a player when they enter the arena, and unregister them when they leave (death or logout will ofc remove them by default). The events should include onDeath and onLogout. In these events you can all call the same function, to remove the item.

For your second question, I'm not quite sure what you mean, but if you want something to happen if you kill within the arena, then the principles of of what I wrote above can also apply to this too. (You can just add an onKill event alongside the others)

Here is an example:
Lua:
local config = {
    enterAid = 3000, --action id to enter the arena
    leaveAid = 3001, --action id to leave the arena
    events = {
        "arenaDeath",
        "arenaLogout",
    },
}

local function checkItem(player)
    --algorithm to check and remove item here
end

local arenaLogout = CreatureEvent("arenaLogout")
function arenaLogout.onLogout(player)
    checkItem(player)
    return true
end
arenaLogout:register()

local arenaDeath = CreatureEvent("arenaDeath")
function arenaDeath.onPrepareDeath(player, killer)
    checkItem(player)
    return true
end
arenaDeath:register()

local arenaLeave = MoveEvent()
function arenaLeave.onStepIn(player, item, position, fromPosition)
    if not player:isPlayer() then
        return false
    end
 
    for _, event in pairs(config.events) do
        player:unregisterEvent(event)
    end
 
    checkItem(player)
    return true
end
arenaLeave:aid(config.leaveAid)
arenaLeave:register()

local arenaEnter = MoveEvent()
function arenaEnter.onStepIn(player, item, position, fromPosition)
    if not player:isPlayer() then
        return false
    end
 
    for _, event in pairs(config.events) do
        player:registerEvent(event)
    end
 
    return true
end
arenaEnter:aid(config.enterAid)
arenaEnter:register()
 
Last edited:
Back
Top