• 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 🌏Small Dungeon [using Canary]🌏

Tampek

ECHO 'Zarkonia.online';
Joined
Dec 29, 2015
Messages
478
Solutions
5
Reaction score
33
Location
Spain
Hello yesterday with some big join i copied the Annihilator lever to simulate a Dungeon system.
But i have problems with center postion to check players inside i think...

Room size:
-112sqm /\ \/
-108sqm < >

Can anyone know what i need change to try again?🌏
Lua:
local setting = {
    -- At what level can do the quest?
    requiredLevel = 450,
    -- Can it be done daily? true = yes, false = no
    daily = false,
    -- Do not change from here down
    centerDemonRoomPosition = {x = 4899, y = 3741, z = 15},
    demonsPositions = {   
        {x = 4869, y = 3779, z = 15},
        {x = 4887, y = 3780, z = 15},
        {x = 4883, y = 3766, z = 15},
        {x = 4900, y = 3777, z = 15},
        {x = 4917, y = 3773, z = 15},
        {x = 4939, y = 3776, z = 15},
        {x = 4950, y = 3778, z = 15},
        {x = 4946, y = 3759, z = 15},
        {x = 4943, y = 3747, z = 15},
        {x = 4933, y = 3747, z = 15},
        {x = 4925, y = 3753, z = 15},
        {x = 4928, y = 3738, z = 15},
        {x = 4917, y = 3748, z = 15},
        {x = 4905, y = 3755, z = 15},
        {x = 4889, y = 3751, z = 15},
        {x = 4899, y = 3737, z = 15},
        {x = 4870, y = 3753, z = 15},
        {x = 4855, y = 3756, z = 15},
        {x = 4857, y = 3751, z = 15},
        {x = 4870, y = 3735, z = 15},
        {x = 4857, y = 3728, z = 15},
        {x = 4868, y = 3714, z = 15},
        {x = 4858, y = 3708, z = 15},
        {x = 4854, y = 3700, z = 15},
        {x = 4877, y = 3709, z = 15},
        {x = 4883, y = 3698, z = 15}
    },
    towerPositions = {   
        {x = 4882, y = 3784, z = 15},
        {x = 4878, y = 3746, z = 15}
    },   
    bossPositions = {   
        {x = 4907, y = 3717, z = 15}
    },
    towerbossPositions = {   
        {x = 4909, y = 3707, z = 15}
    },   
    playersPositions = {
        {fromPos = {x = 4978, y = 5016, z = 9}, toPos = {x = 4860, y = 3784, z = 15}},
        {fromPos = {x = 4979, y = 5016, z = 9}, toPos = {x = 4861, y = 3784, z = 15}},
        {fromPos = {x = 4980, y = 5016, z = 9}, toPos = {x = 4862, y = 3784, z = 15}},
        {fromPos = {x = 4981, y = 5016, z = 9}, toPos = {x = 4863, y = 3784, z = 15}},
    }
}

local lever = Action()

function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 2772 then
        -- Checks if you have the 4 players and if they have the required level
        for i = 1, #setting.playersPositions do
            local creature = Tile(setting.playersPositions[i].fromPos):getTopCreature()
            if not creature then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Four players are required to start the dungeon level 1.")
                return true
            end
            if creature and creature:getLevel() < setting.requiredLevel then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All the players need to be level ".. setting.requiredLevel .." or higher.")
                return true
            end
        end

        -- Checks if there are still players inside the room, if so, return true
        if Position.hasPlayer(setting.centerDemonRoomPosition, 4, 4) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A team is already inside the dungeon.")
            return true
        end

        -- Create monsters
        for i = 1, #setting.demonsPositions do
            Game.createMonster("Elder Mage", setting.demonsPositions[i])
        end
        -- Create towers
        for i = 1, #setting.towerPositions do
            Game.createMonster("Force Field", setting.towerPositions[i])
        end
        -- Create boss
        for i = 1, #setting.bossPositions do
            Game.createMonster("The Abomination", setting.bossPositions[i])
        end
        -- Create bosstower
        for i = 1, #setting.towerbossPositions do
            Game.createMonster("Magic Field", setting.towerbossPositions[i])
        end       
        
        -- Get players from the tiles "playersPositions" and teleport to the demons room if all of the above requirements are met
        for i = 1, #setting.playersPositions do
            local creature = Tile(setting.playersPositions[i].fromPos):getTopCreature()
            if creature and creature:isPlayer() then
                creature:teleportTo(setting.playersPositions[i].toPos)
                creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            else
                return false
            end
        end
        item:transform(2773)
    elseif item.itemid == 2773 then
        -- If it has "daily = true" then it will execute this function
        if setting.daily then
            player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            return true
        end
        -- Not be able to push the lever back if someone is still inside the monsters room
        if Position.hasPlayer(setting.centerDemonRoomPosition, 4, 4) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A team is already inside the dungeon.")
            return true
        end
        -- Removes all monsters so that the next team can enter
        if Position.removeMonster(setting.centerDemonRoomPosition, 4, 4) then
            return true
        end
        item:transform(2772)
    end
    return true
end

lever:uid(30038)
lever:register()

Error console:
1707766834726.pngReproduce: when all players are whaiting in lever positions appear that error.
 
Hello yesterday with some big join i copied the Annihilator lever to simulate a Dungeon system.
But i have problems with center postion to check players inside i think...

Room size:
-112sqm /\ \/
-108sqm < >

Can anyone know what i need change to try again?🌏
Lua:
local setting = {
    -- At what level can do the quest?
    requiredLevel = 450,
    -- Can it be done daily? true = yes, false = no
    daily = false,
    -- Do not change from here down
    centerDemonRoomPosition = {x = 4899, y = 3741, z = 15},
    demonsPositions = {  
        {x = 4869, y = 3779, z = 15},
        {x = 4887, y = 3780, z = 15},
        {x = 4883, y = 3766, z = 15},
        {x = 4900, y = 3777, z = 15},
        {x = 4917, y = 3773, z = 15},
        {x = 4939, y = 3776, z = 15},
        {x = 4950, y = 3778, z = 15},
        {x = 4946, y = 3759, z = 15},
        {x = 4943, y = 3747, z = 15},
        {x = 4933, y = 3747, z = 15},
        {x = 4925, y = 3753, z = 15},
        {x = 4928, y = 3738, z = 15},
        {x = 4917, y = 3748, z = 15},
        {x = 4905, y = 3755, z = 15},
        {x = 4889, y = 3751, z = 15},
        {x = 4899, y = 3737, z = 15},
        {x = 4870, y = 3753, z = 15},
        {x = 4855, y = 3756, z = 15},
        {x = 4857, y = 3751, z = 15},
        {x = 4870, y = 3735, z = 15},
        {x = 4857, y = 3728, z = 15},
        {x = 4868, y = 3714, z = 15},
        {x = 4858, y = 3708, z = 15},
        {x = 4854, y = 3700, z = 15},
        {x = 4877, y = 3709, z = 15},
        {x = 4883, y = 3698, z = 15}
    },
    towerPositions = {  
        {x = 4882, y = 3784, z = 15},
        {x = 4878, y = 3746, z = 15}
    },  
    bossPositions = {  
        {x = 4907, y = 3717, z = 15}
    },
    towerbossPositions = {  
        {x = 4909, y = 3707, z = 15}
    },  
    playersPositions = {
        {fromPos = {x = 4978, y = 5016, z = 9}, toPos = {x = 4860, y = 3784, z = 15}},
        {fromPos = {x = 4979, y = 5016, z = 9}, toPos = {x = 4861, y = 3784, z = 15}},
        {fromPos = {x = 4980, y = 5016, z = 9}, toPos = {x = 4862, y = 3784, z = 15}},
        {fromPos = {x = 4981, y = 5016, z = 9}, toPos = {x = 4863, y = 3784, z = 15}},
    }
}

local lever = Action()

function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 2772 then
        -- Checks if you have the 4 players and if they have the required level
        for i = 1, #setting.playersPositions do
            local creature = Tile(setting.playersPositions[i].fromPos):getTopCreature()
            if not creature then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Four players are required to start the dungeon level 1.")
                return true
            end
            if creature and creature:getLevel() < setting.requiredLevel then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All the players need to be level ".. setting.requiredLevel .." or higher.")
                return true
            end
        end

        -- Checks if there are still players inside the room, if so, return true
        if Position.hasPlayer(setting.centerDemonRoomPosition, 4, 4) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A team is already inside the dungeon.")
            return true
        end

        -- Create monsters
        for i = 1, #setting.demonsPositions do
            Game.createMonster("Elder Mage", setting.demonsPositions[i])
        end
        -- Create towers
        for i = 1, #setting.towerPositions do
            Game.createMonster("Force Field", setting.towerPositions[i])
        end
        -- Create boss
        for i = 1, #setting.bossPositions do
            Game.createMonster("The Abomination", setting.bossPositions[i])
        end
        -- Create bosstower
        for i = 1, #setting.towerbossPositions do
            Game.createMonster("Magic Field", setting.towerbossPositions[i])
        end      
       
        -- Get players from the tiles "playersPositions" and teleport to the demons room if all of the above requirements are met
        for i = 1, #setting.playersPositions do
            local creature = Tile(setting.playersPositions[i].fromPos):getTopCreature()
            if creature and creature:isPlayer() then
                creature:teleportTo(setting.playersPositions[i].toPos)
                creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            else
                return false
            end
        end
        item:transform(2773)
    elseif item.itemid == 2773 then
        -- If it has "daily = true" then it will execute this function
        if setting.daily then
            player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            return true
        end
        -- Not be able to push the lever back if someone is still inside the monsters room
        if Position.hasPlayer(setting.centerDemonRoomPosition, 4, 4) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A team is already inside the dungeon.")
            return true
        end
        -- Removes all monsters so that the next team can enter
        if Position.removeMonster(setting.centerDemonRoomPosition, 4, 4) then
            return true
        end
        item:transform(2772)
    end
    return true
end

lever:uid(30038)
lever:register()

Error console:
View attachment 82057Reproduce: when all players are whaiting in lever positions appear that error.

It looks like you're not using hasPlayer correctly, you're defining the positions like this:

Lua:
centerDemonRoomPosition = {x = 4899, y = 3741, z = 15},

After looking at the hasPlayer function it looks like it's expecting it to be like this (Added "Position" before coordinates):

Lua:
local setting = {
    centerDemonRoomPosition = Position{x = 4899, y = 3741, z = 15}
}
 
still the same
Post automatically merged:

Lua:
local setting = {
    centerRoom = {x = 4899, y = 3741, z = 15},
    range = 50,
    playerPositions = {
        Position{x = 4978, y = 5016, z = 9},
        Position{x = 4979, y = 5016, z = 9},
        Position{x = 4980, y = 5016, z = 9},
        Position{x = 4981, y = 5016, z = 9}
    },
    newPositions = {
        Position{x = 4860, y = 3784, z = 15},
        Position{x = 4861, y = 3784, z = 15},
        Position{x = 4862, y = 3784, z = 15},
        Position{x = 4863, y = 3784, z = 15}
    },
    demonsPositions = {
        {x = 4869, y = 3779, z = 15},
        {x = 4887, y = 3780, z = 15},
        {x = 4883, y = 3766, z = 15},
        {x = 4900, y = 3777, z = 15},
        {x = 4917, y = 3773, z = 15},
        {x = 4939, y = 3776, z = 15},
        {x = 4950, y = 3778, z = 15},
        {x = 4946, y = 3759, z = 15},
        {x = 4943, y = 3747, z = 15},
        {x = 4933, y = 3747, z = 15},
        {x = 4925, y = 3753, z = 15},
        {x = 4928, y = 3738, z = 15},
        {x = 4917, y = 3748, z = 15},
        {x = 4905, y = 3755, z = 15},
        {x = 4889, y = 3751, z = 15},
        {x = 4899, y = 3737, z = 15},
        {x = 4870, y = 3753, z = 15},
        {x = 4855, y = 3756, z = 15},
        {x = 4857, y = 3751, z = 15},
        {x = 4870, y = 3735, z = 15},
        {x = 4857, y = 3728, z = 15},
        {x = 4868, y = 3714, z = 15},
        {x = 4858, y = 3708, z = 15},
        {x = 4854, y = 3700, z = 15},
        {x = 4877, y = 3709, z = 15},
        {x = 4883, y = 3698, z = 15}
    },
    towerPositions = {   
        {x = 4882, y = 3784, z = 15},
        {x = 4878, y = 3746, z = 15}
    },   
    towerbossPositions = {   
        {x = 4909, y = 3707, z = 15}
    },   
}

local leverTheRavager = Action()
function leverTheRavager.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 2772 then
        if roomIsOccupied(setting.centerRoom, false, setting.range, setting.range) then
            player:say("A team is already inside.", TALKTYPE_MONSTER_SAY)
            return true
        end

        local storePlayers, playerTile = {}
        for i = 1, #setting.playerPositions do
            local creature = Tile(setting.playerPositions[i]):getTopCreature()
            if not creature or not creature:isPlayer() then
                player:sendCancelMessage("You need 4 of players to enter.")
                return true
            end
            storePlayers[#storePlayers + 1] = playerTile
        end
        -- Create monsters
        for i = 1, #setting.demonsPositions do
            Game.createMonster("Elder Mage", setting.demonsPositions[i])
        end
        -- Create towers
        for i = 1, #setting.towerPositions do
            Game.createMonster("Force Field", setting.towerPositions[i])
        end
        -- Create bosstower
        for i = 1, #setting.towerbossPositions do
            Game.createMonster("Magic Field", setting.towerbossPositions[i])
        end           
        Game.createMonster("The Abomination", { x = 4909, y = 3707, z = 15 })

        local players
        for i = 1, #storePlayers do
            players = storePlayers[i]
            setting.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
            players:teleportTo(setting.newPositions[i])
            setting.newPositions[i]:sendMagicEffect(CONST_ME_ENERGYAREA)
        end
        item:transform(2773)
    elseif item.itemid == 2773 then
        item:transform(2772)
    end
    return true
end

leverTheRavager:uid(30038)
leverTheRavager:register()

in this the players are not teleported
Post automatically merged:

1707774634393.png
 
Last edited:
Lua:
storePlayers[#storePlayers + 1] = playerTile
On line 68 above, youre storing playerTile into storePlayers at the most available index. However, playerTile is just an empty table which is declared on line 61...

You can just store the players userdata in the table instead, then use this later after the creatures have spawned.

Lua:
local setting = {
    centerRoom = {x = 4899, y = 3741, z = 15},
    range = 50,
    playerPositions = {
        Position(4978, 5016, 9),
        Position(4979, 5016, 9),
        Position(4980, 5016, 9),
        Position(4981, 5016, 9)
    },
    newPositions = {
        Position(4860, 3784, 15),
        Position(4861, 3784, 15),
        Position(4862, 3784, 15),
        Position(4863, 3784, 15)
    },
    demonsPositions = {
        {x = 4869, y = 3779, z = 15},
        {x = 4887, y = 3780, z = 15},
        {x = 4883, y = 3766, z = 15},
        {x = 4900, y = 3777, z = 15},
        {x = 4917, y = 3773, z = 15},
        {x = 4939, y = 3776, z = 15},
        {x = 4950, y = 3778, z = 15},
        {x = 4946, y = 3759, z = 15},
        {x = 4943, y = 3747, z = 15},
        {x = 4933, y = 3747, z = 15},
        {x = 4925, y = 3753, z = 15},
        {x = 4928, y = 3738, z = 15},
        {x = 4917, y = 3748, z = 15},
        {x = 4905, y = 3755, z = 15},
        {x = 4889, y = 3751, z = 15},
        {x = 4899, y = 3737, z = 15},
        {x = 4870, y = 3753, z = 15},
        {x = 4855, y = 3756, z = 15},
        {x = 4857, y = 3751, z = 15},
        {x = 4870, y = 3735, z = 15},
        {x = 4857, y = 3728, z = 15},
        {x = 4868, y = 3714, z = 15},
        {x = 4858, y = 3708, z = 15},
        {x = 4854, y = 3700, z = 15},
        {x = 4877, y = 3709, z = 15},
        {x = 4883, y = 3698, z = 15}
    },
    towerPositions = {
        {x = 4882, y = 3784, z = 15},
        {x = 4878, y = 3746, z = 15}
    },
    towerbossPositions = {
        {x = 4909, y = 3707, z = 15}
    },
}

local leverTheRavager = Action()
function leverTheRavager.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 2772 then
        if roomIsOccupied(setting.centerRoom, false, setting.range, setting.range) then
            player:say("A team is already inside.", TALKTYPE_MONSTER_SAY)
            return true
        end

        local participants = {}
        for _, playerPosition in ipairs(setting.playerPositions) do
            local creature = playerPosition:getTile():getTopCreature()
            if not creature or not creature:isPlayer() then
                player:sendCancelMessage("You need 4 players to enter.")
                return true
            end
            table.insert(participants, creature)
        end

        for i = 1, #setting.demonsPositions do
            Game.createMonster("Elder Mage", setting.demonsPositions[i])
        end

        for i = 1, #setting.towerPositions do
            Game.createMonster("Force Field", setting.towerPositions[i])
        end

        for i = 1, #setting.towerbossPositions do
            Game.createMonster("Magic Field", setting.towerbossPositions[i])
        end
        Game.createMonster("The Abomination", { x = 4909, y = 3707, z = 15 })

        for i = 1, 4 do
            setting.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
            participants[i]:teleportTo(setting.newPositions[i])
            setting.newPositions[i]:sendMagicEffect(CONST_ME_ENERGYAREA)
        end
 
        item:transform(2773)
    elseif item.itemid == 2773 then
        item:transform(2772)
    end
    return true
end

leverTheRavager:uid(30038)
leverTheRavager:register()

@Terminology
A Position(class) can be created using any of the two following, 1 parameter(table) or 3/4 parameters (x,y,z[, stackpos])
Code:
int LuaScriptInterface::luaPositionCreate(lua_State* L)
{
    // Position([x = 0[, y = 0[, z = 0[, stackpos = 0]]]])
    // Position([position])
Lua:
--using a table
local t = {x = 1000, y = 1000, z = 7}
local pos = Position(t)
--//inline version--
local pos = Position({x = 1000, y = 1000, z = 7})

--or using integers--
local pos = Position(1000, 1000, 7)

EDIT:

I have since learned {} can be used as a constructor. very interesting indeed.
 
Last edited:
Back
Top