• 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 Loop not running and cant target the monster

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
176
Location
Sweden
This function prints 'not nil' but it wont print 'looping' and I dont get why. Also, how would one target a monster inside the spectate (monsters) and get the monsters health? As the monsters[v] is simple a number/id.

Lua:
function startup(level)  
 local setArea = nil
 local lizardDungeon = {
    [1] = {tpPos = {x = 1937, y = 859, z = 12}, specPos = {x = 1904, y = 879, z = 12}, specAreaY = 60, specAreaX = 40},
    [2] = {tpPos = {x = 2062, y = 859, z = 12}, specPos = {x = 2029, y = 879, z = 12}, specAreaY = 60, specAreaX = 40},
    [3] = {tpPos = {x = 2190, y = 859, z = 12}, specPos = {x = 2157, y = 879, z = 12}, specAreaY = 60, specAreaX = 40},
                }

    for i = 1, #lizardDungeon do
        local sP = getSpectators(lizardDungeon[i].specPos, lizardDungeon[i].specAreaX, lizardDungeon[i].specAreaY, true, true)
     if sP == nil then
       setArea = i
      break
     end
    end
  
    local monsters = Game.getSpectators(lizardDungeon[setArea].specPos, true, false, lizardDungeon[setArea].specAreaX, lizardDungeon[setArea].specAreaY)
        if monsters ~= nil then
            print("not nil")
            for v = 1, #monsters do
                print("looping")
              if isMonster(monsters[v]) then
           getCreatureHealth(monsters[v])
        print("suck me dack")
            print(monsters[v]:getName())
              end
        end
     end
  
    player:teleportTo(lizardDungeon[setArea].tpPos)
end
 
local sP = getSpectators
Missing Game.
Yeah about that, that loop actually work.
Aka it will print setArea and give it correct loop value.
First loop checks for players in area and if its clean assign setArea that table value.
 
Game.getSpectators returns table no matter what, even if its empty. Empty table is not null, so check for #monsters > 0 rather than ~= nil
 
Game.getSpectators returns table no matter what, even if its empty. Empty table is not null, so check for #monsters > 0 rather than ~= nil
Lua:
function startup(level) 
    local setArea = nil
    local lizardDungeon = {
        [1] = {tpPos = {x = 1937, y = 859, z = 12}, specPos = {x = 1904, y = 879, z = 12}, specAreaY = 60, specAreaX = 40},
        [2] = {tpPos = {x = 2062, y = 859, z = 12}, specPos = {x = 2029, y = 879, z = 12}, specAreaY = 60, specAreaX = 40},
        [3] = {tpPos = {x = 2190, y = 859, z = 12}, specPos = {x = 2157, y = 879, z = 12}, specAreaY = 60, specAreaX = 40},
    }

    for i = 1, #lizardDungeon do
        local sP = Game.getSpectators(lizardDungeon[i].specPos, lizardDungeon[i].specAreaX, lizardDungeon[i].specAreaY, true, true)
        if #sP <= 0 then
            setArea = i
            break
        end
    end

    local monsters = Game.getSpectators(lizardDungeon[setArea].specPos, true, false, lizardDungeon[setArea].specAreaX, lizardDungeon[setArea].specAreaY)
    if #monsters > 0 then
        print("not empty")
        for v = 1, #monsters do
            print("looping")
            if isMonster(monsters[v]) then
                getCreatureHealth(monsters[v])
                print("suck me dack")
                print(monsters[v]:getName())
            end
        end
    end

    player:teleportTo(lizardDungeon[setArea].tpPos)
end
 
Game.getSpectators returns table no matter what, even if its empty. Empty table is not null, so check for #monsters > 0 rather than ~= nil
Good call, me no good think.
Lua:
function startup(level)
    local setArea = nil
    local lizardDungeon = {
        [1] = {tpPos = {x = 1937, y = 859, z = 12}, specPos = {x = 1904, y = 879, z = 12}, specAreaY = 60, specAreaX = 40},
        [2] = {tpPos = {x = 2062, y = 859, z = 12}, specPos = {x = 2029, y = 879, z = 12}, specAreaY = 60, specAreaX = 40},
        [3] = {tpPos = {x = 2190, y = 859, z = 12}, specPos = {x = 2157, y = 879, z = 12}, specAreaY = 60, specAreaX = 40},
    }

    for i = 1, #lizardDungeon do
        local sP = Game.getSpectators(lizardDungeon[i].specPos, lizardDungeon[i].specAreaX, lizardDungeon[i].specAreaY, true, true)
        if #sP <= 0 then
            setArea = i
            break
        end
    end

    local monsters = Game.getSpectators(lizardDungeon[setArea].specPos, true, false, lizardDungeon[setArea].specAreaX, lizardDungeon[setArea].specAreaY)
    if #monsters > 0 then
        print("not empty")
        for v = 1, #monsters do
            print("looping")
            if isMonster(monsters[v]) then
                getCreatureHealth(monsters[v])
                print("suck me dack")
                print(monsters[v]:getName())
            end
        end
    end

    player:teleportTo(lizardDungeon[setArea].tpPos)
end
Good cleanup of the code but no major changes.

HOWEVER I found my silly problem, I simply forgot to extend the getSpectators x-position to reach the monsters i placed out.
 
Back
Top