• 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] getFreeHouses

Crypton3

Retired
Joined
Mar 13, 2010
Messages
549
Reaction score
139
Simple function for getting all free houses. Works well with TFS 0.4. Can be useful in script that teleports player to random / first free house.

Code:
function getFreeHouses()
   local towns = getTownList()
   local houses = {}

   for i = 1, #towns do
     local list = getTownHouses(towns[i].id)
     for j = 1, #list do
       if list[j] then
         if getHouseOwner(list[j]) == 0 then
           table.insert(houses, list[j])
         end
       end
     end
   end

   if #houses == 0 then
     return nil
   end

   return houses
end
 
Last edited:
Please learn how to tab..
Code:
function getFreeHouses()
    local towns = getTownList()
    local houses = {}
   
    for i = 1, #towns do
        local list = getTownHouses(towns[i].id)
        for j = 1, #list do
            if list[j] then
                if getHouseOwner(list[j]) == 0 then
                    table.insert(houses, list[j])
                end
            end
        end
    end
    if(#houses == 0) then
        return nil
    end
return houses
end

But nicely done, even tho Cykotitan made this a while ago, for donation castles.
 
@WibbenZ

Is there any reason why you added redundant parentheses around #houses == 0? :p
 
@WibbenZ

Is there any reason why you added redundant parentheses around #houses == 0? :p

Haha its just a thing I feel makes it easier to read, and according to Elf(somewhere on the forum - was some troll thread with cyko about making smaller scripts I think) he wrote that you should always use if() and not without brakets. :)
 
Back
Top