• 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 how to access the table array?

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
I want to try to access the table according to the name of the monster it will respawn in a certain area.

Lua:
config = {
    [{'demon, demon skeleton'}] = {
        fromPositionArea = Position(1001, 780, 7), -- fromPosition
        toPositionArea = Position(1097, 871, 7), -- toPosition
    },
    [{'goblin, rat'}] = {
        fromPositionArea = Position(1001, 780, 7), -- fromPosition
        toPositionArea = Position(1097, 871, 7), -- toPosition
    },
}

local function dungeonMonster(name, position, fromPosition, toPosition)
    Game.createMonster(name, position, true, true)
end

function onDeath(monster, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    local monsterName = monster:getName()
    
    for configs, bonus in pairs(config) do
        local randomTime = math.random(2, 3)   
        local monsterName, monsterPosition = monster:getName(), monster:getPosition()
        addEvent(dungeonMonster, randomTime * 60 * 1000, monsterName, monsterPosition)
    end

    return true
end
 
Solution
You can check if the table contains the name you are looking for
Lua:
local monsterName = monster:getName()
    for configs, bonus in pairs(config) do
        if table.contains(configs, monsterName) then -- here
            local randomTime = math.random(2, 3)  
            local monsterPosition = monster:getPosition()
            addEvent(dungeonMonster, randomTime * 60 * 1000, monsterName, monsterPosition)
        end
 end

Lua:
local config = {
    [{'demon', 'demon skeleton'}] = {
        fromPositionArea = Position(1001, 780, 7), -- fromPosition
        toPositionArea = Position(1097, 871, 7), -- toPosition
    },
    [{'goblin', 'rat'}] = {
        fromPositionArea = Position(1001, 780, 7), -- fromPosition
        toPositionArea =...
You can check if the table contains the name you are looking for
Lua:
local monsterName = monster:getName()
    for configs, bonus in pairs(config) do
        if table.contains(configs, monsterName) then -- here
            local randomTime = math.random(2, 3)  
            local monsterPosition = monster:getPosition()
            addEvent(dungeonMonster, randomTime * 60 * 1000, monsterName, monsterPosition)
        end
 end

Lua:
local config = {
    [{'demon', 'demon skeleton'}] = {
        fromPositionArea = Position(1001, 780, 7), -- fromPosition
        toPositionArea = Position(1097, 871, 7), -- toPosition
    },
    [{'goblin', 'rat'}] = {
        fromPositionArea = Position(1001, 780, 7), -- fromPosition
        toPositionArea = Position(1097, 871, 7), -- toPosition
    },
}
 
Solution
Back
Top