• 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 command to kill all creatures in area

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,312
Reaction score
135
Healhy living, life to all :) , i hope all good :) i want to ask for a help on making a such script:

a god command /clearmaincity to kill all creatures/monsters in xx/yy/z -- xxx/yyy/z, and so i can also set multiple areas with different command word like /cleartemple, /clearentrance etc, just in one revscript for 1.3+++
 
Solution
Just type /clear followed by a space and the name of the area you want to clear in the game chat to execute the command.
/clear maincity



@Fjorda I accept your advice, could you take a look and see if the script turned out well? What else needs to be corrected or removed? Should I implement more functions? I'm open to hearing your input :)

Lua:
local areasToClear = {
    ["maincity"] = {
        fromPosition = Position(2500, 2500, 7),
        toPosition = Position(2550, 2550, 7)
    },
    ["temple"] = {
        fromPosition = Position(2600, 2500, 7),
        toPosition = Position(2650, 2550, 7)
    },
    ["entrance"] = {
        fromPosition = Position(2500, 2600, 7),
        toPosition = Position(2550, 2650, 7)
    }...
Healhy living, life to all :) , i hope all good :) i want to ask for a help on making a such script:

a god command /clearmaincity to kill all creatures/monsters in xx/yy/z -- xxx/yyy/z, and so i can also set multiple areas with different command word like /cleartemple, /clearentrance etc, just in one revscript for 1.3+++

Not tested:

Lua:
local fromPosition = Position(2500, 2500, 7)
local toPosition = Position(2550, 2550, 7)

local function removeCreaturesInRange(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                local tile = Tile(x, y, z)
                if tile then
                    local creatures = tile:getCreatures()
                    if creatures then
                        for i = 1, #creatures do
                            local creature = creatures[i]
                            if creature:isMonster() or creature:isNpc() then
                                creature:remove()
                            end
                        end
                    end
                end
            end
        end
    end
end

local talkActionRemoveCity = TalkAction("/removecity")

function talkActionRemoveCity.onSay(player, words, param)
    removeCreaturesInRange(fromPosition, toPosition)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "All creatures in the specified area have been removed.")
    return false
end

talkActionRemoveCity:register()
 
Just type /clear followed by a space and the name of the area you want to clear in the game chat to execute the command.
/clear maincity



@Fjorda I accept your advice, could you take a look and see if the script turned out well? What else needs to be corrected or removed? Should I implement more functions? I'm open to hearing your input :)

Lua:
local areasToClear = {
    ["maincity"] = {
        fromPosition = Position(2500, 2500, 7),
        toPosition = Position(2550, 2550, 7)
    },
    ["temple"] = {
        fromPosition = Position(2600, 2500, 7),
        toPosition = Position(2650, 2550, 7)
    },
    ["entrance"] = {
        fromPosition = Position(2500, 2600, 7),
        toPosition = Position(2550, 2650, 7)
    }
-- Add new areas as needed.
}

local function removeCreaturesInRange(fromPos, toPos)
    for z = fromPos.z, toPos.z do
        for y = fromPos.y, toPos.y do
            for x = fromPos.x, toPos.x do
                local tile = Tile(x, y, z)
                if tile then
                    local creatures = tile:getCreatures()
                    for i = 1, tile:getCreatureCount() do
                        local creature = creatures[i]
                        if creature and creature:isMonster() then
                            creature:remove()
                        end
                    end
                end
            end
        end
    end
end

local function clearArea(player, areaName)
    if not player:getGroup():getAccess() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have permission to use this command.")
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your account type is not high enough to use this command.")
        return false
    end

    local area = areasToClear[areaName]
    if area then
        removeCreaturesInRange(area.fromPosition, area.toPosition)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "All creatures in the " .. areaName .. " have been removed.")
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "The specified area does not exist.")
    end
    return false
end

local clear = TalkAction("/clear")

function clear.onSay(player, words, param)
    if param and areasToClear[param] then
        return clearArea(player, param)
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Please specify a valid area name.")
        return false
    end
end

clear:separator(" ")
clear:register()
 
Last edited:
Solution
Not tested:

Lua:
local fromPosition = Position(2500, 2500, 7)
local toPosition = Position(2550, 2550, 7)

local function removeCreaturesInRange(fromPos, toPos)
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                local tile = Tile(x, y, z)
                if tile then
                    local creatures = tile:getCreatures()
                    if creatures then
                        for i = 1, #creatures do
                            local creature = creatures[i]
                            if creature:isMonster() or creature:isNpc() then
                                creature:remove()
                            end
                        end
                    end
                end
            end
        end
    end
end

local talkActionRemoveCity = TalkAction("/removecity")

function talkActionRemoveCity.onSay(player, words, param)
    removeCreaturesInRange(fromPosition, toPosition)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "All creatures in the specified area have been removed.")
    return false
end

talkActionRemoveCity:register()

i will test Matues script,. it looks more to what i asked, tho big thanks for giving your time for this! i see this script prolly will benefit more devs :))

will
Just type /clear followed by a space and the name of the area you want to clear in the game chat to execute the command.




@Fjorda I accept your advice, could you take a look and see if the script turned out well? What else needs to be corrected or removed? Should I implement more functions? I'm open to hearing your input :)

Lua:
local areasToClear = {
    ["maincity"] = {
        fromPosition = Position(2500, 2500, 7),
        toPosition = Position(2550, 2550, 7)
    },
    ["temple"] = {
        fromPosition = Position(2600, 2500, 7),
        toPosition = Position(2650, 2550, 7)
    },
    ["entrance"] = {
        fromPosition = Position(2500, 2600, 7),
        toPosition = Position(2550, 2650, 7)
    }
-- Add new areas as needed.
}

local function removeCreaturesInRange(fromPos, toPos)
    for z = fromPos.z, toPos.z do
        for y = fromPos.y, toPos.y do
            for x = fromPos.x, toPos.x do
                local tile = Tile(x, y, z)
                if tile then
                    local creatures = tile:getCreatures()
                    for i = 1, tile:getCreatureCount() do
                        local creature = creatures[i]
                        if creature and creature:isMonster() then
                            creature:remove()
                        end
                    end
                end
            end
        end
    end
end

local function clearArea(player, areaName)
    if not player:getGroup():getAccess() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have permission to use this command.")
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your account type is not high enough to use this command.")
        return false
    end

    local area = areasToClear[areaName]
    if area then
        removeCreaturesInRange(area.fromPosition, area.toPosition)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "All creatures in the " .. areaName .. " have been removed.")
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "The specified area does not exist.")
    end
    return false
end

local clear = clearAction("/clear")

function clear.onSay(player, words, param)
    if param and areasToClear[param] then
        return clearArea(player, param)
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Please specify a valid area name.")
        return false
    end
end

clear:separator(" ")
clear:register()

Will test it and tell how it goes :)
 
i will test Matues script,. it looks more to what i asked, tho big thanks for giving your time for this! i see this script prolly will benefit more devs :))

will


Will test it and tell how it goes :)
If there are errors or it doesn't work, just post here. Actually, I haven't tested it yet. I'm at work and have nothing to do, so I decided to make the script. When I get home, I will test it to see if it works or not, and I can fix any errors or issues.
Post automatically merged:

Tested and functioning perfectly... fixed a few small issues... the post is edited, okay... :)
 
Last edited:
Just type /clear followed by a space and the name of the area you want to clear in the game chat to execute the command.




@Fjorda I accept your advice, could you take a look and see if the script turned out well? What else needs to be corrected or removed? Should I implement more functions? I'm open to hearing your input :)

Lua:
local areasToClear = {
    ["maincity"] = {
        fromPosition = Position(2500, 2500, 7),
        toPosition = Position(2550, 2550, 7)
    },
    ["temple"] = {
        fromPosition = Position(2600, 2500, 7),
        toPosition = Position(2650, 2550, 7)
    },
    ["entrance"] = {
        fromPosition = Position(2500, 2600, 7),
        toPosition = Position(2550, 2650, 7)
    }
-- Add new areas as needed.
}

local function removeCreaturesInRange(fromPos, toPos)
    for z = fromPos.z, toPos.z do
        for y = fromPos.y, toPos.y do
            for x = fromPos.x, toPos.x do
                local tile = Tile(x, y, z)
                if tile then
                    local creatures = tile:getCreatures()
                    for i = 1, tile:getCreatureCount() do
                        local creature = creatures[i]
                        if creature and creature:isMonster() then
                            creature:remove()
                        end
                    end
                end
            end
        end
    end
end

local function clearArea(player, areaName)
    if not player:getGroup():getAccess() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have permission to use this command.")
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your account type is not high enough to use this command.")
        return false
    end

    local area = areasToClear[areaName]
    if area then
        removeCreaturesInRange(area.fromPosition, area.toPosition)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "All creatures in the " .. areaName .. " have been removed.")
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "The specified area does not exist.")
    end
    return false
end

local clear = TalkAction("/clear")

function clear.onSay(player, words, param)
    if param and areasToClear[param] then
        return clearArea(player, param)
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Please specify a valid area name.")
        return false
    end
end

clear:separator(" ")
clear:register()
I actually wanted to add config, but then I forgot about it. XD
 
If there are errors or it doesn't work, just post here. Actually, I haven't tested it yet. I'm at work and have nothing to do, so I decided to make the script. When I get home, I will test it to see if it works or not, and I can fix any errors or issues.
Post automatically merged:

Tested and functioning perfectly... fixed a few small issues... the post is edited, okay... :)
works like a charm :O huge thanks :)))
 
Back
Top