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

TFS 1.X+ Problem with script createcriature

Nuelman

Member
Joined
Nov 9, 2017
Messages
98
Solutions
1
Reaction score
6
Hello,
I am currently using a script which does the following:
(raid scripts)
Create a monster and remove a magic wall through a "raid" which is only for 5 hours and if no one kills it, the monster disappears and the magic wall is created again in the same position after 5 hours.

- The problem is that the monster (it works perfectly) is created in the indicated position and after 5 hours the monster is eliminated.
But the magic wall : it is removed but " it is not created again after 5 hours...

PS : if instead of 5 hours I write 1 minute " local timeToRemove = 1"
everything works perfectly.

Where can be the fault if after 5 hours everything does not work, but after 1 minute everything works correctly?
thanks



Lua:
local mwallPos = Position(32991, 32299, 7)
local mwallId = 1498
local timeToRemove = 300 -- 300 minutes / 5 hours

function onRaid()
Game.broadcastMessage("The portal Of Bazir on Bosses Quest Room It's open for 5 hours, access from DP THAIS!", MESSAGE_EVENT_ADVANCE)
local monster = Game.createMonster("Bazir", Position(33052, 32304, 7))
    monster:setReward(true)
    local item = Tile(mwallPos):getItemById(mwallId)
    if item then
        item:remove()
    end
    addEvent(removeBossCreateMwall, timeToRemove * 60 * 1000, monster:getId())
end

function removeBossCreateMwall(monsterId)
    local item = Tile(mwallPos):getItemById(mwallId)
    if not item then
        Game.createItem(mwallId, 1, mwallPos)
    end

    local boss = Monster(monsterId)

    if boss then
        boss:remove()
    end
end
Post automatically merged:

nothing?
 
Last edited:
Solution
If you have 2 codes that are the same for your raids you need to change the names of the function removeBossCreateWall.

So one can be
removeBossCreateWall1

the other
removeBossCreateWall2
@Nuelman

I'm not sure why it didn't work in 5 hours vs 1 minute but try this small change, instead of an addEvent that comes 5 hours later, we instead check every 1 second if 5 hours have passed:

Lua:
local mwallPos = Position(32991, 32299, 7)
local mwallId = 1498
local timeToRemove = 300 * 60 -- 300 minutes / 5 hours
local resetTime = os.time()

function onRaid()
    Game.broadcastMessage("The portal Of Bazir on Bosses Quest Room It's open for 5 hours, access from DP THAIS!", MESSAGE_EVENT_ADVANCE)
    local monster = Game.createMonster("Bazir", Position(33052, 32304, 7))
    monster:setReward(true)
    local item = Tile(mwallPos):getItemById(mwallId)
    if item then
        item:remove()
    end

    resetTime = os.time() + timeToRemove
    addEvent(removeBossCreateMwall, 1000, monster:getId())
end

function removeBossCreateMwall(monsterId)
    -- if 5 hours has not passed then check again in 1 second
    if resetTime > os.time() then
        return addEvent(removeBossCreateMwall, 1000, monsterId)
    end

    local item = Tile(mwallPos):getItemById(mwallId)
    if not item then
        Game.createItem(mwallId, 1, mwallPos)
    end

    local boss = Monster(monsterId)
    if boss then
        boss:remove()
    end
end
 
I tried for 5 mint, and it works fine, now it's time for the truth, I'll try 5 hours on the server... tomorrow I'll tell you how I went
 
@NuelmanI'm not sure why it didn't work in 5 hours vs 1 minute but try this small change, instead of an addEvent that comes 5 hours later, we instead check every 1 second if 5 hours have passed:
My only guess is that whereever this information is stored, was over-written / used by another process, thereby eliminating/destroying the addEvent.

cycling the addevent every second is probably just a waste of resources though. xD
If it works with 1 second over 5 hours, I'd probably adjust it to every 5 or 10 minutes to refresh, just to save on server resources.
 
I would create a global variable to hold the monsters ID then make a global event that runs every hour and checks what time it is. If the time is lined up with the time the monster should be removed or the wall replaced then it does so. That way there isn’t an open add event and you know it will always run correctly.
 
What @Xikini refers to may make a lot of sense,
since I run the same script with different position and different boss.
One runs at 6:00 pm every day and the other at 7:00 pm.
Could it be that he failed there?
Post automatically merged:

@
imkingran

First I want to thank you for your work,
But the script doesn't work, because it doesn't create the monster in the indicated position

Any ideas?
 
Last edited:
What @Xikini refers to may make a lot of sense,
since I run the same script with different position and different boss.
One runs at 6:00 pm every day and the other at 7:00 pm.
Could it be that he failed there?
Post automatically merged:

@
imkingran

First I want to thank you for your work,
But the script doesn't work, because it doesn't create the monster in the indicated position

Any ideas?

Hmm, well I didn't make any changes to the part of your code that spawns the monster, only how we remove the monster after 5 hours.

I think you can adjust your Game.createMonster and add some params to force the spawn:
Game.createMonster(monsterName, position[, extended = false[, force = false]])

So change to this to force respawn, that way even if their is something blocking that tile like magic field, etc, it will spawn anyways.
local monster = Game.createMonster("Bazir", Position(33052, 32304, 7), false, true)
 
Hello again.

I change :
removeBossCreateMwall
to
removeBossCreatewall

I remove "M" and now work....
I don't know if this has anything to do with it, now I'll try 5 hours to see if it really works!
 
If you have 2 codes that are the same for your raids you need to change the names of the function removeBossCreateWall.

So one can be
removeBossCreateWall1

the other
removeBossCreateWall2
 
Solution
@Nuelman

@Itutorial Bring's up a good point. Since there is no local keyword in front of your function it could interfere with another function inside the same scope that has the same name. You can either add local in front and move it on top of the other function or if you need to access it in another file and you wanna leave it as global then you can do as Itutorial mentioned and give them specific names.
 
Back
Top