• 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 getting more than one name from table

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,571
Solutions
3
Reaction score
98
Location
Portugal
hey, I got this code, but like you can see it only gets the name of 1 monster...

can some1 explain me how can I check the names of all monsters arround?

Code:
local specs = getCustomSpectators(creature:getPosition(), false, false, true, false, 15, 15, 15, 15)

    for i = 1, #specs do
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You must kill the following monsters: "..specs[i]:getName().." before get your reward.")
    return false
    end
 
hey, I got this code, but like you can see it only gets the name of 1 monster...

can some1 explain me how can I check the names of all monsters arround?

Code:
local specs = getCustomSpectators(creature:getPosition(), false, false, true, false, 15, 15, 15, 15)

    for i = 1, #specs do
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You must kill the following monsters: "..specs[i]:getName().." before get your reward.")
    return false
    end

Code:
local specs = getCustomSpectators(creature:getPosition(), false, false, true, false, 15, 15, 15, 15)
local monstersNames = ''

    for i = 1, #specs do
        monstersNames = monstersNames .. ', '.. specs[i]:getName()
    end
    if monstersNames ~= '' then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You must kill the following monsters: "..specs[i]:getName().." before get your reward.")
        return false
    end
    return true

?
 
Code:
local specs = getCustomSpectators(creature:getPosition(), false, false, true, false, 15, 15, 15, 15)
local monstersNames = ''

    for i = 1, #specs do
        monstersNames = monstersNames .. ', '.. specs[i]:getName()
    end
    if monstersNames ~= '' then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You must kill the following monsters: "..specs[i]:getName().." before get your reward.")
        return false
    end
    return true

?
Whats that?
Code:
local specs = getCustomSpectators(creature:getPosition(), false, false, true, false, 15, 15, 15, 15)
local monstersNames = ''

    for i = 1, #specs do
        monstersNames = monstersNames .. ', '.. specs[i]:getName()
    end
    if monstersNames ~= '' then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You must kill the following monsters: "..monstersNames.." before get your reward.")
        return false
    end
    return true

but i thing its the iterator which is not working
 
Code:
    for _, spectator in ipairs(Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]]) do
        if spectator:isMonster() then
            print(spectator:getName())
        end
    end
 
solved, thanks every1

the solution is

Code:
local specs = getCustomSpectators(creature:getPosition(), false, false, true, false, 15, 15, 15, 15)
local names = ""
  
    if #specs > 0 then
        for i = 1, #specs do
            if(names == "") then
                    names = specs[i]:getName()
            else
                    names = names .. "\n"..specs[i]:getName()
            end
        end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot receive your reward before kill the following monsters:\n"..names.."")
    return true
    end
 
Back
Top