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

Question about monster:remove()

bizao030188

Member
Joined
Jun 4, 2012
Messages
50
Solutions
2
Reaction score
7
Hey there!
I am working in a new system in which I want to create summons for players and then at some point I want to remove these summons.
To create summons I am using

Lua:
local monster = Game.createMonster(name, playerPos)
if monster ~= nil then
        monster:setMaster(player)
end

The point is that if I remove the summon using summon:remove() command the surrounding monsters keep walking (I mean, the AI still working - so increasing CPU usage).
On the other hand, if I remove the summon using summon:addHealth(-summon:getHealth()) it does not happen but there is a delay and an animation on this process which I would like to avoid.

Any idea on how to make summon:remove() work as I want?
Thanks in advance.
 
Solution
Hi @Nekiro, thanks for your answer!

I figured that out...
The problem was that when using monster:remove() the summon stills in the target list and takes long time to be removed (really long). So I created a function player:doRemoveSummon() that basically removes the summon from the target list of the spectators.
In case someone is also interested:

Lua:
function Player.doRemoveSummon(self)
    local summons = self:getSummons()
    local summon = Creature(summons[1])
    local summonPos = summon:getPosition()
    local attackers = Game.getSpectators(summonPos, true, false)
    for i = 1, #attackers do
        local attacker = attackers[i]
        if attacker and attacker:isMonster() then
            local targetList =...
Monsters will be idle when no one is on screen (gms does not count). TFS is continuosly checking for that, so if something is on the screen monsters can be alive for some time after it dissapear.
You can safely use monster:remove()
 
Last edited:
Hi @Nekiro, thanks for your answer!

I figured that out...
The problem was that when using monster:remove() the summon stills in the target list and takes long time to be removed (really long). So I created a function player:doRemoveSummon() that basically removes the summon from the target list of the spectators.
In case someone is also interested:

Lua:
function Player.doRemoveSummon(self)
    local summons = self:getSummons()
    local summon = Creature(summons[1])
    local summonPos = summon:getPosition()
    local attackers = Game.getSpectators(summonPos, true, false)
    for i = 1, #attackers do
        local attacker = attackers[i]
        if attacker and attacker:isMonster() then
            local targetList = attacker:getTargetList()
            for j = 1, #targetList do
                if targetList[j] == summon then
                    attacker:removeTarget(summon)
                    attacker:setIdle()
                end
            end
        end
    end
    summonPos:sendMagicEffect(CONST_ME_POFF)
    summon:remove()
    return true
end
 
Solution
Hi @Nekiro, thanks for your answer!

I figured that out...
The problem was that when using monster:remove() the summon stills in the target list and takes long time to be removed (really long). So I created a function player:doRemoveSummon() that basically removes the summon from the target list of the spectators.
In case someone is also interested:

Lua:
function Player.doRemoveSummon(self)
    local summons = self:getSummons()
    local summon = Creature(summons[1])
    local summonPos = summon:getPosition()
    local attackers = Game.getSpectators(summonPos, true, false)
    for i = 1, #attackers do
        local attacker = attackers[i]
        if attacker and attacker:isMonster() then
            local targetList = attacker:getTargetList()
            for j = 1, #targetList do
                if targetList[j] == summon then
                    attacker:removeTarget(summon)
                    attacker:setIdle()
                end
            end
        end
    end
    summonPos:sendMagicEffect(CONST_ME_POFF)
    summon:remove()
    return true
end

Hi, can you explain how/where to use this script? Pls
 
Hi!
It is usually not needed if you are running your server in a good computer. I used this just in order to minimize the cpu usage of my server in a new script that uses the monster:remove() function.
 
Back
Top