• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Removing monsters from selected area

Hernest

New Member
Joined
Jul 26, 2010
Messages
152
Reaction score
3
Location
poland
Hello, so i need to remove monsters from selected area, from x to y. I tried a lot of ur code but it doesn't work, for example:
http://pastebin.com/tNxVNdPP
I have just removed teleport.
TFS 0.4 LINUX

My code:
http://pastebin.com/qB60vGd8

I tried this in a lot of cominations:
http://pastebin.com/nn1xrveU

No errors, just nothing happend.

How it should work:
On 'stepin' monsters from selected area are removed. Only player can stay.

Sorry for my bad english.
 
The first code, if there is a player in that area it won't remove the monsters.
So you can remove this
Code:
if v.type == 1 then
     return
And change elseif under that to if.

The second code is basicly like that, but there is this "if getCreatureName(v) == monster then", both v and monster are nil there.
If all monsters should be removed, then checking for the name won't be needed.
If it should only remove monsters with a certain name and use the creature id, so v.uid when it's added to the table or monsters[ i] when it's already in the table but removed ingame.
 
Code:
function onStepIn(cid, item, position, fromPosition)
        doCreatureSetStorage(cid, 156661, 1)
        doPlayerSendTextMessage(cid,20,'Available commands:\n 1. /arena1 monster name, example: /arena1 Demon\n 2. !s1 - spawning monster in arena No.1\n 3. !huntexit - if u want to leave hunting arena')

local from = {x=4052, y=1817, z=7}
local to = {x=4070, y=1804, z=7}

local monsters = {}

for x = from.x, to.x do
        for y = from.y, to.y do
                for z = from.z, to.z do
                        local v = getTopCreature({x=x, y=y, z=z})
                        if v.type == 2 then
                                table.insert(monsters, v.uid)
                        end
                end
        end
end

for i = 1, #monsters do
        doRemoveCreature(monsters[i])
end
end
I tried this, doesn't work.
 
http://scr.hu/2kai/qq55u
Doesn't work
Code:
function onStepIn(cid, item, position, fromPosition)
        doCreatureSetStorage(cid, 156661, 1)
        doPlayerSendTextMessage(cid,20,'Available commands:\n 1. /arena1 monster name, example: /arena1 Demon\n 2. !s1 - spawning monster in arena No.1\n 3. !huntexit - if u want to leave hunting arena')

local from = {x=4052, y=1817, z=7}
local to = {x=4070, y=1804, z=7}

local monsters = {}

for x = from.x, to.x do
        for y = from.y, to.y do
                for z = from.z, to.z do
                        local v = getTopCreature({x=x, y=y, z=z})
                        if isMonster(v.uid) then
                                table.insert(monsters, v.uid)
                        end
                end
        end
end

for i = 1, #monsters do
        doRemoveCreature(monsters[i])
end
end

In first hunting area i used:
Code:
function getCreaturesInRange(position, radiusx, radiusy, showMonsters, showPlayers, showSummons)
    local creaturesList = {}
    for x = -radiusx, radiusx do
        for y = -radiusy, radiusy do
            if not (x == 0 and y == 0) then
                local creature = getTopCreature({x = position.x+x, y = position.y+y, z = position.z})
                if (creature.type == 1 and showPlayers) or (creature.type == 2 and showMonsters and (not showSummons or (showSummons and getCreatureMaster(creature.uid) == (creature.uid)))) then
                    table.insert(creaturesList, creature.uid)
                end
            end
        end
    end
    local creature = getTopCreature(position)
    if (creature.type == 1 and showPlayers) or (creature.type == 2 and showMonsters and (not showSummons or (showSummons and getCreatureMaster(creature.uid) == (creature.uid)))) then
        if not(table.find(creaturesList, creature.uid)) then
            table.insert(creaturesList, creature.uid)
        end
    end
        return creaturesList
end
Code:
local creatures = getCreaturesInRange(xyz, 6, 6, TRUE, FALSE)
                for i = 1, #creatures do
                    doRemoveCreature(creatures[i])
                end

But this time it's returning nil value.
 
Are you sure the position is correct?
You can also use getSpectators
Code:
local spec = getSpectators({x=4060, y=1810, z=7}, 10, 10)
if spec ~= nil then
     for _, s in pairs(spec) do
         if isMonster(s) then
             doRemoveCreature(s)
         end
     end
end
 
Back
Top