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

Lua What's wrong with that?

slavi

#define SLAVI32 _WIN32
Senator
Joined
Sep 9, 2015
Messages
681
Solutions
11
Reaction score
560
GitHub
slavidodo
TFS 1.1 , it's giving error,

the code meant to if no player is in range to remove firewalkerwall, reset firewalker quest and remove monsters
in the same range..
It's working well but it's giving error globalevents think [ failed to execute firewalker event]
PHP:
function onThink(interval)
    local specs = Game.getSpectators({x=7681,y=9294,z=0}, false, true, 0, 15, 0, 12)
    local monsterspecs = Game.getSpectators({x=7681,y=9294,z=0}, false, false, 0, 15, 0, 12)
    for i = 0, #specs do
        if not(#specs >= 1) then
            if(firewalkerwall) then
                firewalkerwall:remove()                  
            end
            resetFirewalker()      
            for s = 1, #monsterspecs do
                if(#monsterspecs >= 1) then
                    monsterspecs[s]:remove()
                end              
            end
        return false      
        end
    end
end



-- EDIT --
Depending on @forgee 's tips.

PHP:
function onThink(interval)
    local specs = Game.getSpectators({x=7681,y=9294,z=0}, false, true, 0, 15, 0, 12)   
    for i = 0, #specs do
        if not(#specs >= 1) then
            local monsterspecs = Game.getSpectators({x=7681,y=9294,z=0}, false, false, 0, 15, 0, 12)
            if(firewalkerwall) then
                firewalkerwall:remove()                   
            end
            resetFirewalker()       
            for s = 1, #monsterspecs do
                if(#monsterspecs >= 1) then
                    monsterspecs[s]:remove()
                end           
            end   
        end
        return true   
    end
end
 
Last edited:
I think the error is because you return false, or nil if there are no players in the area. onThink() should always return true as far as I know.
You should check the table count before starting the loop, though, and in the case of specs, you don't acutally do anything with the table. Lua table indexes starts at 1 and not 0, so you should check if the table has anything in it, then start the loop from index 1.
Game.getSpectators is rather heavy function, relatively speaking, so it's good to try not to use it when it's not needed. In this case, you only need to check for monsters if there are no players around since you won't remove the monsters if there are players there.

Here I have addressed the points I mentioned above:
Code:
function onThink(interval)
    local specs = Game.getSpectators({x=7681,y=9294,z=0}, false, true, 0, 15, 0, 12)
    if (#specs == 0) then
        local monsterspecs = Game.getSpectators({x=7681,y=9294,z=0}, false, false, 0, 15, 0, 12)
        if(firewalkerwall) then
            firewalkerwall:remove()
        end
        resetFirewalker()
        if (#monsterspecs > 0) then
            for s = 1, #monsterspecs do
                monsterspecs[s]:remove()
            end
        end  
    end
    return true
end
Since we don't see where firewalkerwall and resetFireWalker() are defined, I'm assuming they work as intended.
 
I think the error is because you return false, or nil if there are no players in the area. onThink() should always return true as far as I know.
You should check the table count before starting the loop, though, and in the case of specs, you don't acutally do anything with the table. Lua table indexes starts at 1 and not 0, so you should check if the table has anything in it, then start the loop from index 1.
Game.getSpectators is rather heavy function, relatively speaking, so it's good to try not to use it when it's not needed. In this case, you only need to check for monsters if there are no players around since you won't remove the monsters if there are players there.

Here I have addressed the points I mentioned above:
Code:
function onThink(interval)
    local specs = Game.getSpectators({x=7681,y=9294,z=0}, false, true, 0, 15, 0, 12)
    if (#specs == 0) then
        local monsterspecs = Game.getSpectators({x=7681,y=9294,z=0}, false, false, 0, 15, 0, 12)
        if(firewalkerwall) then
            firewalkerwall:remove()
        end
        resetFirewalker()
        if (#monsterspecs > 0) then
            for s = 1, #monsterspecs do
                monsterspecs[s]:remove()
            end
        end
    end
    return true
end
Since we don't see where firewalkerwall and resetFireWalker() are defined, I'm assuming they work as intended.
Firstly the same error happened when i replaced false with true.
Secondly I defined firewalkerwall and resetFireWalker() in /lib and I said in main post that they are working well.

And game.getspectators is needed instead of using isInRange as it will have a very big loop which will be heavier. And the script needs to check players before monsters because there must be no players in that range and i assure i used the best way, and as i understood from you , you meant that my pc can't host that? oh no man 16 gb ram with core i7 processor.
 
Last edited:
Read my post carefully one more time.
I said I assumed that firewalkerwall and resetFireWalker() were working correctly. I said you didn't need to check for monsters before you check if there are players there.

And the script needs to check players before monsters because there must be no players in that range and i assure i used the best way,
That is exactly what I told you, check if there are players in the area before you search for monsters. Only you don't do that, you search for players and monsters before you check if you found any players.

and as i understood from you , you meant that my pc can't host that? oh no man 16 gb ram with core i7 processor.
I did not mention your computer or whether it could handle the script or not what so ever. It is not a question of if it can handle it or not, of course if can, it's all about efficiency. Unnecessary calls to resource intensive functions is just wasted processing time.

I tried to give you a few tips on how you could improve the script, and yes, maybe learn something.
But you "assure you used the best way", so who am I to argue. Have a good day. :)
 
But you "assure you used the best way", so who am I to argue. Have a good day.
We are not arguing.

I tried to give you a few tips on how you could improve the script, and yes, maybe learn something.
Ye thanks a lot, you gave me some tips about what should become first , i updated the script to become

PHP:
function onThink(interval)
    local specs = Game.getSpectators({x=7681,y=9294,z=0}, false, true, 0, 15, 0, 12)   
    for i = 0, #specs do
        if not(#specs >= 1) then
            local monsterspecs = Game.getSpectators({x=7681,y=9294,z=0}, false, false, 0, 15, 0, 12)
            if(firewalkerwall) then
                firewalkerwall:remove()                   
            end
            resetFirewalker()       
            for s = 1, #monsterspecs do
                if(#monsterspecs >= 1) then
                    monsterspecs[s]:remove()
                end           
            end   
        end
        return true   
    end
end
And depending on your tips, it's really great to figure out how to make other scripts better, so thanks alot.
 
Back
Top