• 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.2 filter script

undead mage

Active Member
Joined
Mar 25, 2012
Messages
364
Solutions
2
Reaction score
47
Location
Amsterdam
Hi, so im trying to make a boss script and im looking into other scripts how ppl have done it and I found this part but I just can't figure out what it does. Can anyone help me understand this? :p

Code:
local function filter(list, f, i)
    if i < #list then
        if f(list[i]) then
            return list[i], filter(list, f, i + 1)
        else
            return filter(list, f, i + 1)
        end
    elseif list[i] and f(list[i]) then
        return list[i]
    end
end

Code:
    local spectators = Game.getSpectators(info.center, false, false, 0, info.rangeX, 0, info.rangeY)
    if not filter(spectators, function(c) return c:isMonster() end, 1) then
        local boss = Game.createMonster(info.boss, info.center)
        boss:registerEvent('WarzoneBossDeath')
    end
 
Solution
I guess this. It will check for the spectators and then check if there is a monster around. If there is no monster "not filter" it will create the monster.
I guess this. It will check for the spectators and then check if there is a monster around. If there is no monster "not filter" it will create the monster.
 
Solution
Maybe the thing that is strange for you its the "f" function execution inside the filter function. That part is where all happens. Thats the inside check and the main reason why filter function was created.
 
Back
Top