• 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 [TFS 1.2] Remove monster doesn't always work

guiismiti

Well-Known Member
Joined
May 19, 2014
Messages
315
Solutions
3
Reaction score
68
Hello,

I have a weird issue...
My code randomly works.
I have a creaturescript to remove raid bosses, so they won't duplicate
It is registered like this
Code:
<event type="think" name="RemoveBoss" script="others/removeboss.lua"/>
In the monster file, I added this to the monsters that should be removed after some time
Code:
    <script>
        <event name="RemoveBoss" />
    </script>
And here is the script.
Code:
seconds = 3600

function onThink(cid)
        addEvent(killboss,1000*seconds, {cid=cid})
    return true
end

function killboss(cid)
local cid = cid.cid
    if isCreature(cid) then
            doRemoveCreature(cid)
    end
    return true
end
So, sometimes it works, sometimes it doesn't (more often, it does).

Any ideas?
Can I change the type in creatures.xml? I'm using "think" because I don't know if I can use "spawn" or something like that.
 
Uhmmm try to change your code to this...
Code:
seconds = 3600


function onThink(creature)
    addEvent(killboss,1000*seconds, creature)
    return true
end

function killboss(creature)
    if creature then
        creature:remove()
    end
end

i didn't test it myself but i hope it works!
 
Code:
seconds = 3600

function onThink(cid, interval)

    if not isMonster(cid) then
        return true
    end
  
    local id = cid
  
    addEvent(
        function(cid)
            if isMonster(cid) then
                doRemoveCreature(cid)
            end
        end,
        seconds,
        id
    )
    return true
end
 
Last edited:
Using both codes I got the same error, saying that in function addEvent the Argument #3 is unsafe

By the way, the second code is missing a comma after "seconds"
 
Code:
seconds = 3600

function onThink(cid, interval)

    if not isMonster(cid) then
        return true
    end
 
    local id = cid
 
    addEvent(
        function(x)
            if isMonster(x) then
                doRemoveCreature(x)
            end
        end,
        seconds,
        id
    )
    return true
end
 
Last edited:
Still got the same "argument #3 is unsafe" error.

By the way, the missing comma is before 'seconds,' and not after


Ok, I solved the unsafe argument thing by using 'id.uid' instead of 'id'.
I have also tried using 'cid.uid', but in both cases, the problem persists - it won't remove the monster every time.
 
Last edited:
Ok, some more details about it, since I've just noticed something.

I have something called a raid room. Everytime a raid boss spawns, it also spawns one second later inside the raid room (so players who have been offline during a raid broadcast will know that it happened).
This is the room, and, since the bosses here spawn 1 second after the bosses in the regular boss locations, they are also supposed to be removed 1 second after.

What I've noticed is, the bosses in the regular bosses locations are removed, and the bosses in the raid room are the ones who aren't being removed sometimes.
Still, I have no clue what is causing this.

This is the raid room
m8coqu.jpg
 
onThink is a bad way todo this!! Very bad! Since onThink is getting executed every second and you want to send addEvent only once! So i recommend to use onCreatureAppear.

Go into monsters and create folder name it scripts and inside scripts create lua and name it "bossAI.lua" and paste this code:
Code:
local time = 3600

function removeBoss(cid)
    local monster = Monster(cid)
    if monster then
        monster:remove()
    end
end

function onCreatureAppear(self, creature)
    if self == creature then
        addEvent(removeBoss, time * 1000, self:getId())
    end
end

Now go into your boss xml file and paste this next to manacost, should look something like this:
Code:
manacost="0" script="bossAI.lua"

This would be the best way todo it.
 
Back
Top