• 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!

Use X to X

Mera Mero

Guess Who?
Joined
Dec 27, 2014
Messages
417
Reaction score
86
Greeting otlanders
I just wanted to ask if there is something like If you click on lever create monsters?
In this room? And if there monsters in this room and someone clicked on the lever do not create monsters until they are killed(MONSTERS) ? and if there is X kind of monster you can't create Y monster until you kill X monsters? because i will use this system on castles ,my plan is to do levers and every lever create X amount of X monsters and its working like i said to you but these levers will have level to use X level can be used by X lever and Y lever can be used by Y level etc
Thanks ,i hope you're understanding me
@Flatlander
 
Last edited:
This is for TFS 1.1 and has not been tested.
Code:
local levers = {
    [5000] = { -- Action ID of lever
        area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}, -- Area to check for monsters
        levelReq = 100, -- Level requirement
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        area = {from = {x = 300, y = 300, z = 7}, to = {x = 400, y = 400, z = 7}},
        levelReq = 50,
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(player, item, position, itemEx, toPosition)
    local lever = levers[item:getActionId()]
    if player:getLevel() < lever.levelReq then
        player:sendCancelMessage("You need to be at least level " .. lever.levelReq .. " to use this lever.")
        return false
    end

    for z = lever.area.from.z, lever.area.to.z do
        for x = lever.area.from.x, lever.area.to.x do
            for y = lever.area.from.y, lever.area.to.y do
                local tile = Tile({x = x, y = y, z = z})
                if tile then
                    local creature = tile:getTopCreature()
                    if creature and creature:isMonster() then
                        for _, mob in ipairs(lever.monsters) do
                            if creature:getName() == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    for _, mob in ipairs(lever.monsters) do
        Game.createMonster(mob.name, mob.position)
    end
    return true
end

I believe TFS 1.0 works like this:
Code:
local levers = {
    [5000] = { -- Action ID of lever
        area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}, -- Area to check for monsters
        levelReq = 100, -- Level requirement
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        area = {from = {x = 300, y = 300, z = 7}, to = {x = 400, y = 400, z = 7}},
        levelReq = 50,
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    local lever = levers[item.actionid]
    local player = Player(cid)
    if player:getLevel() < lever.levelReq then
        player:sendCancelMessage("You need to be at least level " .. lever.levelReq .. " to use this lever.")
        return false
    end

    for z = lever.area.from.z, lever.area.to.z do
        for x = lever.area.from.x, lever.area.to.x do
            for y = lever.area.from.y, lever.area.to.y do
                local tile = Tile({x = x, y = y, z = z})
                if tile then
                    local creature = tile:getTopCreature()
                    if creature and creature:isMonster() then
                        for _, mob in ipairs(lever.monsters) do
                            if creature:getName() == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    for _, mob in ipairs(lever.monsters) do
        Game.createMonster(mob.name, mob.position)
    end
    return true
end
 
Last edited:
This is for TFS 1.1 and has not been tested.
Code:
local levers = {
    [5000] = { -- Action ID of lever
        area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}, -- Area to check for monsters
        levelReq = 100, -- Level requirement
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        area = {from = {x = 300, y = 300, z = 7}, to = {x = 400, y = 400, z = 7}},
        levelReq = 50,
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(player, item, position, itemEx, toPosition)
    local lever = levers[item:getActionId()]
    if player:getLevel() < lever.levelReq then
        player:sendCancelMessage("You need to be at least level " .. lever.levelReq .. " to use this lever.")
        return false
    end

    for z = lever.area.from.z, lever.area.to.z do
        for x = lever.area.from.x, lever.area.to.x do
            for y = lever.area.from.y, lever.area.to.y do
                local tile = Tile({x = x, y = y, z = z})
                if tile then
                    local creature = tile:getTopCreature()
                    if creature and creature:isMonster() then
                        for _, mob in ipairs(lever.monsters) do
                            if creature:getName == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    for j, mob in ipairs(lever.monsters) do
        Game.createMonster(mob.name, mob.position)
    end
    return true
end

I believe TFS 1.0 works like this:
Code:
local levers = {
    [5000] = { -- Action ID of lever
        area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}, -- Area to check for monsters
        levelReq = 100, -- Level requirement
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        area = {from = {x = 300, y = 300, z = 7}, to = {x = 400, y = 400, z = 7}},
        levelReq = 50,
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    local lever = levers[item.actionid]
    local player = Player(cid)
    if player:getLevel() < lever.levelReq then
        player:sendCancelMessage("You need to be at least level " .. lever.levelReq .. " to use this lever.")
        return false
    end
 
    for z = lever.area.from.z, lever.area.to.z do
        for x = lever.area.from.x, lever.area.to.x do
            for y = lever.area.from.y, lever.area.to.y do
                local tile = Tile({x = x, y = y, z = z})
                if tile then
                    local creature = tile:getTopCreature()
                    if creature and creature:isMonster() then
                        for _, mob in ipairs(lever.monsters) do
                            if creature:getName == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end
 
    for j, mob in ipairs(lever.monsters) do
        Game.createMonster(mob.name, mob.position)
    end
    return true
end
function iterateArea(func, from, to)
 
Code:
function iterateArea(func, from, to)
    for z = from.z, to.z do
        for y = from.y, to.y do
            for x = from.x, to.x do
                func(Position(x, y, z))
            end
        end
    end
end
 
This is for TFS 1.1 and has not been tested.
Code:
local levers = {
    [5000] = { -- Action ID of lever
        area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}, -- Area to check for monsters
        levelReq = 100, -- Level requirement
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        area = {from = {x = 300, y = 300, z = 7}, to = {x = 400, y = 400, z = 7}},
        levelReq = 50,
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(player, item, position, itemEx, toPosition)
    local lever = levers[item:getActionId()]
    if player:getLevel() < lever.levelReq then
        player:sendCancelMessage("You need to be at least level " .. lever.levelReq .. " to use this lever.")
        return false
    end

    for z = lever.area.from.z, lever.area.to.z do
        for x = lever.area.from.x, lever.area.to.x do
            for y = lever.area.from.y, lever.area.to.y do
                local tile = Tile({x = x, y = y, z = z})
                if tile then
                    local creature = tile:getTopCreature()
                    if creature and creature:isMonster() then
                        for _, mob in ipairs(lever.monsters) do
                            if creature:getName() == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    for _, mob in ipairs(lever.monsters) do
        Game.createMonster(mob.name, mob.position)
    end
    return true
end

I believe TFS 1.0 works like this:
Code:
local levers = {
    [5000] = { -- Action ID of lever
        area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}, -- Area to check for monsters
        levelReq = 100, -- Level requirement
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        area = {from = {x = 300, y = 300, z = 7}, to = {x = 400, y = 400, z = 7}},
        levelReq = 50,
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    local lever = levers[item.actionid]
    local player = Player(cid)
    if player:getLevel() < lever.levelReq then
        player:sendCancelMessage("You need to be at least level " .. lever.levelReq .. " to use this lever.")
        return false
    end

    for z = lever.area.from.z, lever.area.to.z do
        for x = lever.area.from.x, lever.area.to.x do
            for y = lever.area.from.y, lever.area.to.y do
                local tile = Tile({x = x, y = y, z = z})
                if tile then
                    local creature = tile:getTopCreature()
                    if creature and creature:isMonster() then
                        for _, mob in ipairs(lever.monsters) do
                            if creature:getName() == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    for _, mob in ipairs(lever.monsters) do
        Game.createMonster(mob.name, mob.position)
    end
    return true
end
like kosheis quest room with level req?
Thanks but i need it tfs 0.3.6 and need more explain please or i think you didn't understand my request :( a lever for level X will summon like 10 monsters on random places and if there are any monsters on this room you can't use this lever till you kill all these monsters :)
 
That's exactly what this does, and it supports multiple levers.

TFS 0.3.6
Code:
local levers = {
    [5000] = { -- Action ID of lever
        area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}, -- Area to check for monsters
        levelReq = 100, -- Level requirement
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        area = {from = {x = 300, y = 300, z = 7}, to = {x = 400, y = 400, z = 7}},
        levelReq = 50,
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    local lever = levers[item.actionid]
    if getPlayerLevel(cid) < lever.levelReq then
        doPlayerSendCancel(cid, "You need to be at least level " .. lever.levelReq .. " to use this lever.")
        return false
    end

    for z = lever.area.from.z, lever.area.to.z do
        for x = lever.area.from.x, lever.area.to.x do
            for y = lever.area.from.y, lever.area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for _, mob in ipairs(lever.monsters) do
                        if getCreatureName(creature.uid) == mob.name then
                            return false
                        end
                    end
                end
            end
        end
    end

    for _, mob in ipairs(lever.monsters) do
        doSummonCreature(mob.name, mob.position)
    end
    return true
end


If you don't want any levers to work unless all monsters are dead in just one area, you can use this:
Code:
local area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}} -- Area to check for monsters
local levelReq = 100 -- Level requirement

local levers = {
    [5000] = { -- Action ID of lever
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    if getPlayerLevel(cid) < levelReq then
        doPlayerSendCancel(cid, "You need to be at least level " .. levelReq .. " to use this lever.")
        return false
    end

    for z = area.from.z, area.to.z do
        for x = area.from.x, area.to.x do
            for y = area.from.y, area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for i, l in ipairs(levers) do
                        for _, mob in ipairs(l.monsters) do
                            if getCreatureName(creature.uid) == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    local lever = levers[item.actionid]
    for _, mob in ipairs(lever.monsters) do
        doSummonCreature(mob.name, mob.position)
    end
    return true
end
 
That's exactly what this does, and it supports multiple levers.

TFS 0.3.6
Code:
local levers = {
    [5000] = { -- Action ID of lever
        area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}, -- Area to check for monsters
        levelReq = 100, -- Level requirement
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        area = {from = {x = 300, y = 300, z = 7}, to = {x = 400, y = 400, z = 7}},
        levelReq = 50,
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    local lever = levers[item.actionid]
    if getPlayerLevel(cid) < lever.levelReq then
        doPlayerSendCancel(cid, "You need to be at least level " .. lever.levelReq .. " to use this lever.")
        return false
    end

    for z = lever.area.from.z, lever.area.to.z do
        for x = lever.area.from.x, lever.area.to.x do
            for y = lever.area.from.y, lever.area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for _, mob in ipairs(lever.monsters) do
                        if getCreatureName(creature.uid) == mob.name then
                            return false
                        end
                    end
                end
            end
        end
    end

    for _, mob in ipairs(lever.monsters) do
        doSummonCreature(mob.name, mob.position)
    end
    return true
end


If you don't want any levers to work unless all monsters are dead in just one area, you can use this:
Code:
local area = {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}} -- Area to check for monsters
local levelReq = 100 -- Level requirement

local levers = {
    [5000] = { -- Action ID of lever
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 150, y = 150, z = 7}},
            {name = "Rotworm", position = {x = 125, y = 125, z = 7}}
        }
    },
    [5001] = {
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    if getPlayerLevel(cid) < levelReq then
        doPlayerSendCancel(cid, "You need to be at least level " .. levelReq .. " to use this lever.")
        return false
    end

    for z = area.from.z, area.to.z do
        for x = area.from.x, area.to.x do
            for y = area.from.y, area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for i, l in ipairs(levers) do
                        for _, mob in ipairs(l.monsters) do
                            if getCreatureName(creature.uid) == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    local lever = levers[item.actionid]
    for _, mob in ipairs(lever.monsters) do
        doSummonCreature(mob.name, mob.position)
    end
    return true
end
mmm thanks for your work but doesn't work
action.xml
lelo.lua
Code:
local area = {from = {x = 1107, y = 571, z = 7}, to = {x = 1120, y = 584, z = 7}} -- Area to check for monsters
local levelReq = 100 -- Level requirement

local levers = {
    [5000] = { -- Action ID of lever
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 1110, y = 574, z = 7}},
            {name = "Rat", position = {x = 1116, y = 576, z = 7}},
            {name = "Rat", position = {x = 1116, y = 582, z = 7}},
            {name = "Rat", position = {x = 1108, y = 582, z = 7}},
            {name = "Rat", position = {x = 1118, y = 583, z = 7}},
            {name = "Rotworm", position = {x = 1114, y = 572, z = 7}}
        }
    },
    [5001] = {
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    if getPlayerLevel(cid) < levelReq then
        doPlayerSendCancel(cid, "You need to be at least level " .. levelReq .. " to use this lever.")
        return false
    end

    for z = area.from.z, area.to.z do
        for x = area.from.x, area.to.x do
            for y = area.from.y, area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for i, l in ipairs(levers) do
                        for _, mob in ipairs(l.monsters) do
                            if getCreatureName(creature.uid) == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    local lever = levers[item.actionid]
    for _, mob in ipairs(lever.monsters) do
        doSummonCreature(mob.name, mob.position)
    end
    return true
end
i've set id of action 5000 on that lever and added UID for it 6547 to able to use the script but created monsters and there were monsters
9aclc3.jpg

EDITED
didn't get any error
 
You don't need a unique id, just set the lever to action id 5000 and add this to actions.xml.
Code:
<action actionid="5000" script="lelo.lua"/>

I have trouble understanding you.
 
You don't need a unique id, just set the lever to action id 5000 and add this to actions.xml.
Code:
<action actionid="5000" script="lelo.lua"/>

I have trouble understanding you.
i see and sorry for my bad english ,When lever is used more than once didn't check spwan if there are monsters or not And still create the monsters as shown in the picture
 
Try this.

Code:
local area = {from = {x = 1107, y = 571, z = 7}, to = {x = 1120, y = 584, z = 7}} -- Area to check for monsters
local levelReq = 100 -- Level requirement

local levers = {
    [5000] = { -- Action ID of lever
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 1110, y = 574, z = 7}},
            {name = "Rat", position = {x = 1116, y = 576, z = 7}},
            {name = "Rat", position = {x = 1116, y = 582, z = 7}},
            {name = "Rat", position = {x = 1108, y = 582, z = 7}},
            {name = "Rat", position = {x = 1118, y = 583, z = 7}},
            {name = "Rotworm", position = {x = 1114, y = 572, z = 7}}
        }
    },
    [5001] = {
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    if getPlayerLevel(cid) < levelReq then
        doPlayerSendCancel(cid, "You need to be at least level " .. levelReq .. " to use this lever.")
        return false
    end

    for z = area.from.z, area.to.z do
        for x = area.from.x, area.to.x do
            for y = area.from.y, area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for i, l in pairs(levers) do
                        for _, mob in ipairs(l.monsters) do
                            if getCreatureName(creature.uid) == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    local lever = levers[item.actionid]
    for _, mob in ipairs(lever.monsters) do
        doSummonCreature(mob.name, mob.position)
    end
    return true
end
 
Last edited:
Try this.
Code:
local area = {from = {x = 1107, y = 571, z = 7}, to = {x = 1120, y = 584, z = 7}} -- Area to check for monsters
local levelReq = 100 -- Level requirement

local levers = {
    [5000] = { -- Action ID of lever
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 1110, y = 574, z = 7}},
            {name = "Rat", position = {x = 1116, y = 576, z = 7}},
            {name = "Rat", position = {x = 1116, y = 582, z = 7}},
            {name = "Rat", position = {x = 1108, y = 582, z = 7}},
            {name = "Rat", position = {x = 1118, y = 583, z = 7}},
            {name = "Rotworm", position = {x = 1114, y = 572, z = 7}}
        }
    },
    [5001] = {
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    if getPlayerLevel(cid) < levelReq then
        doPlayerSendCancel(cid, "You need to be at least level " .. levelReq .. " to use this lever.")
        return false
    end

    for z = area.from.z, area.to.z do
        for x = area.from.x, area.to.x do
            for y = area.from.y, area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for l, i in pairs(levers) do
                        for _, mob in ipairs(l.monsters) do
                            if getCreatureName(creature.uid) == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    local lever = levers[item.actionid]
    for _, mob in ipairs(lever.monsters) do
        doSummonCreature(mob.name, mob.position)
    end
    return true
end

If that doesn't work, try this.
Code:
local area = {from = {x = 1107, y = 571, z = 7}, to = {x = 1120, y = 584, z = 7}} -- Area to check for monsters
local levelReq = 100 -- Level requirement

local levers = {
    [5000] = { -- Action ID of lever
        monsters = { -- Monsters to spawn
            {name = "Rat", position = {x = 1110, y = 574, z = 7}},
            {name = "Rat", position = {x = 1116, y = 576, z = 7}},
            {name = "Rat", position = {x = 1116, y = 582, z = 7}},
            {name = "Rat", position = {x = 1108, y = 582, z = 7}},
            {name = "Rat", position = {x = 1118, y = 583, z = 7}},
            {name = "Rotworm", position = {x = 1114, y = 572, z = 7}}
        }
    },
    [5001] = {
        monsters = {
            {name = "Bat", position = {x = 150, y = 150, z = 7}}
        }
    }
}

function onUse(cid, item, position, itemEx, toPosition)
    if getPlayerLevel(cid) < levelReq then
        doPlayerSendCancel(cid, "You need to be at least level " .. levelReq .. " to use this lever.")
        return false
    end

    for z = area.from.z, area.to.z do
        for x = area.from.x, area.to.x do
            for y = area.from.y, area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for i, l in pairs(levers) do
                        for _, mob in ipairs(l.monsters) do
                            if getCreatureName(creature.uid) == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end

    local lever = levers[item.actionid]
    for _, mob in ipairs(lever.monsters) do
        doSummonCreature(mob.name, mob.position)
    end
    return true
end
When i used it once its worked fine but when i tried to use it twice found this error
Code:
[06/02/2015 22:03:54] [Error - Action Interface]
[06/02/2015 22:03:55] data/actions/scripts/lelo.lua:onUse
[06/02/2015 22:03:55] Description:
[06/02/2015 22:03:55] data/actions/scripts/lelo.lua:34: attempt to index local 'l' (a number value)
[06/02/2015 22:03:55] stack traceback:
[06/02/2015 22:03:55]     data/actions/scripts/lelo.lua:34: in function <data/actions/scripts/lelo.lua:22>
 
Last edited:
Use getSpectators
Code:
    local spectators = getSpectators({x = 1000, y = 1000, z = 7}, 6, 6, false) -- getSpectators(centerPosition, rangeX, rangeY, multiFloors)
    if spectators then
        for i = 1, #spectators do
            if isMonster(spectators[i]) then
                return false
            end
        end
    end
instead of
Code:
    for z = area.from.z, area.to.z do
        for x = area.from.x, area.to.x do
            for y = area.from.y, area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for i, l in pairs(levers) do
                        for _, mob in ipairs(l.monsters) do
                            if getCreatureName(creature.uid) == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end
 
Last edited:
Did you try both scripts?
Tell me the errors for both.

I don't remember the order and difference between the ipairs and pairs loop, so I need to know which one the error was from.

If I remember correctly, an ipairs loop works only without a custom index, such as [5000].
But a pairs loop works with those.

The error you sent is because the "l" in that loop is the index (5000), so the other one should be the table, and that's how it is in the other script.
both of them gave me same error
Use getSpectators instead :p
Code:
    local spectators = getSpectators({x = 1000, y = 1000, z = 7}, 6, 6, false) -- getSpectators(centerPosition, rangeX, rangeY, multiFloors)
    if spectators then
        for i = 1, #spectators do
            if isMonster(spectators[i]) then
                return false
            end
        end
    end
excuse me? i didn't understand ,sorry may you explain what i should remove/add?
 
You can do what Ninja said if you don't have any other kind of monsters in that area except the ones from the script, which I guess you don't.
I did it this way to make sure you wouldn't get any bugs later on.
 
Use getSpectators
Code:
    local spectators = getSpectators({x = 1000, y = 1000, z = 7}, 6, 6, false) -- getSpectators(centerPosition, rangeX, rangeY, multiFloors)
    if spectators then
        for i = 1, #spectators do
            if isMonster(spectators[i]) then
                return false
            end
        end
    end
instead of
Code:
    for z = area.from.z, area.to.z do
        for x = area.from.x, area.to.x do
            for y = area.from.y, area.to.y do
                local creature = getTopCreature({x = x, y = y, z = z})
                if creature.uid > 0 and isMonster(creature.uid) then
                    for i, l in pairs(levers) do
                        for _, mob in ipairs(l.monsters) do
                            if getCreatureName(creature.uid) == mob.name then
                                return false
                            end
                        end
                    end
                end
            end
        end
    end
hmmm changed it like you said but created too many monsters when i uesd it too many times that's mean this one didn't check monsters on area same problem such as the photo UP
 
You also need to change the parameters of getSpectators to the position in the middle of your room and the radius (currently 6, 6).
 
Last edited:
Back
Top