• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua Create random arena from config

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,033
Solutions
15
Reaction score
323
Location
Sweden
YouTube
Joriku
Hi, so I got hard stuck... talking haaard stuck.
So i am trying to get the script to put teleport on location (TPS) and randomize an arena from cgf.arena to be placed upon the map for 10 minutes then be removed.

For the moment being, i am stuck and would love someone to help me out

Lua:
local lms = TalkAction("/lms3")

local tps =
{
    [1] = {x= 1007, y= 1001, z= 5},  -- where tp is created
    [2] = {x= 1007, y= 1002, z= 5}, -- where tp is created
    [3] = {x= 1007, y= 1003, z= 5}, -- where tp is created
};

local arena1 =
{
    [1] = {x= 976, y= 1025, z= 11}, -- arena positions
    [2] = {x= 987, y= 1029, z= 11},
    [3] = {x= 984, y= 1019, z= 11},
};

local arena2 =
{
    [1] = {x= 958, y= 1046, z= 2},
    [2] = {x= 960, y= 1036, z= 2},
    [3] = {x= 965, y= 1042, z= 2},
};

local arena3 =
{
    [1] = {x= 1026, y= 1017, z= 7},
    [2] = {x= 1021, y= 1021, z= 7},
    [3] = {x= 1031, y= 1013, z= 7},
};

local cfg =
{
    arena = { 'arena1', 'arena2', 'arena3' }, -- variable for the arenas 1 to 3
    messagea1 = 'Arena1', -- test message to check if it works
    messagea2= 'Arena2',
    messagea3 = 'Arena3',
    messagecreate = 'LMS has been opened up for 10 minutes, you can find the teleports at the bridge.', -- broadcast message on create
    messageremove = 'LMS has ended, better luck next time!', -- broadcast message on remove
    minutes = 10*(60*1000) -- amount of minutes to wait
}

function lms.onSay(cid, words, param) -- new usage, trying to write here
    for k in pairs(cfg.arena) do
    local a = Tile(tps):math.random([k])
    -- trying to take it from "arena" to randomize an arena to put out the teleports at "tps" locations table above
        return true
    end
    
function lms.onSay(cid, words, param) -- old usage
  doCreateTeleport(1387, cfg.tpto, tps[1])
  doCreateTeleport(1387, cfg.tpto1, tps[2])
  doCreateTeleport(1387, cfg.tpto2, tps[3])
  Game.broadcastMessage(cfg.messagecreate)
  addEvent(onRemoveItem, cfg.minutes)
return true
end

function onRemoveItem() -- removing the teleports
    for i = 1, #tps do 
        local item = Tile(tps[i]):getItemById(1387)
        if item then
            item:remove()
            doSendMagicEffect(tps[i], CONST_ME_POFF)
        end
    end 
    Game.broadcastMessage(cfg.messageremove)  
return true
end

lms:separator(" ")
lms:register()
 
Solution
Hi, so I got hard stuck... talking haaard stuck.
So i am trying to get the script to put teleport on location (TPS) and randomize an arena from cgf.arena to be placed upon the map for 10 minutes then be removed.

For the moment being, i am stuck and would love someone to help me out

Lua:
local lms = TalkAction("/lms3")

local tps =
{
    [1] = {x= 1007, y= 1001, z= 5},  -- where tp is created
    [2] = {x= 1007, y= 1002, z= 5}, -- where tp is created
    [3] = {x= 1007, y= 1003, z= 5}, -- where tp is created
};

local arena1 =
{
    [1] = {x= 976, y= 1025, z= 11}, -- arena positions
    [2] = {x= 987, y= 1029, z= 11},
    [3] = {x= 984, y= 1019, z= 11},
};

local arena2 =
{
    [1] = {x= 958, y= 1046, z= 2},
    [2] = {x= 960, y=...

Danger II

tibiara.com
Premium User
Joined
Nov 21, 2012
Messages
1,641
Solutions
12
Reaction score
549
Location
Germany
Your thread is not helping much if we don't know what's the issue. You're telling us that you're stuck but for me, I have no idea what's the exact problem. Please try to explain it a little bit better for us.

“What did you want to happen?” ✔️
“Paste the shortest block of code that reproduces the problem.” ✔️
“What actually happened? (Include any error details)” ❌
“Describe what you’ve tried so far” ❌
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,222
Solutions
137
Reaction score
1,512
Location
London
GitHub
MillhioreBT
Twitch
millhiore_bt
YouTube
millhiorebt
Hi, so I got hard stuck... talking haaard stuck.
So i am trying to get the script to put teleport on location (TPS) and randomize an arena from cgf.arena to be placed upon the map for 10 minutes then be removed.

For the moment being, i am stuck and would love someone to help me out

Lua:
local lms = TalkAction("/lms3")

local tps =
{
    [1] = {x= 1007, y= 1001, z= 5},  -- where tp is created
    [2] = {x= 1007, y= 1002, z= 5}, -- where tp is created
    [3] = {x= 1007, y= 1003, z= 5}, -- where tp is created
};

local arena1 =
{
    [1] = {x= 976, y= 1025, z= 11}, -- arena positions
    [2] = {x= 987, y= 1029, z= 11},
    [3] = {x= 984, y= 1019, z= 11},
};

local arena2 =
{
    [1] = {x= 958, y= 1046, z= 2},
    [2] = {x= 960, y= 1036, z= 2},
    [3] = {x= 965, y= 1042, z= 2},
};

local arena3 =
{
    [1] = {x= 1026, y= 1017, z= 7},
    [2] = {x= 1021, y= 1021, z= 7},
    [3] = {x= 1031, y= 1013, z= 7},
};

local cfg =
{
    arena = { 'arena1', 'arena2', 'arena3' }, -- variable for the arenas 1 to 3
    messagea1 = 'Arena1', -- test message to check if it works
    messagea2= 'Arena2',
    messagea3 = 'Arena3',
    messagecreate = 'LMS has been opened up for 10 minutes, you can find the teleports at the bridge.', -- broadcast message on create
    messageremove = 'LMS has ended, better luck next time!', -- broadcast message on remove
    minutes = 10*(60*1000) -- amount of minutes to wait
}

function lms.onSay(cid, words, param) -- new usage, trying to write here
    for k in pairs(cfg.arena) do
    local a = Tile(tps):math.random([k])
    -- trying to take it from "arena" to randomize an arena to put out the teleports at "tps" locations table above
        return true
    end
  
function lms.onSay(cid, words, param) -- old usage
  doCreateTeleport(1387, cfg.tpto, tps[1])
  doCreateTeleport(1387, cfg.tpto1, tps[2])
  doCreateTeleport(1387, cfg.tpto2, tps[3])
  Game.broadcastMessage(cfg.messagecreate)
  addEvent(onRemoveItem, cfg.minutes)
return true
end

function onRemoveItem() -- removing the teleports
    for i = 1, #tps do
        local item = Tile(tps[i]):getItemById(1387)
        if item then
            item:remove()
            doSendMagicEffect(tps[i], CONST_ME_POFF)
        end
    end
    Game.broadcastMessage(cfg.messageremove)
return true
end

lms:separator(" ")
lms:register()
I think what you want is something like this:
Lua:
local createTpPos = {
    Position(1007, 1001, 5),
    Position(1007, 1002, 5},
    Position(1007, 1003, 5}
}

local arenas = {
    -- Arena 1
    {Position(976, 1025, 11),
    Position(987, 1029, 11),
    Position(984, 1019, 11)},
    -- Arena 2
    {Position(958, 1046, 2),
    Position(960, 1036, 2),
    Position(965, 1042, 2)},
    -- Arena 3
    {Position(1026, 1017, 7),
    Position(1021, 1021, 7),
    Position(1031, 1013, 7)}
}

local config = {
    teleportItemId = 1387,
    createMessage = "createMessage",
    removeMessage = "removeMessage",
    minutesToRemoveTps = 3 * 1000 -- 3 seconds
}

local lms = TalkAction("/lms3")

function lms.onSay(player, words, param, type)
    -- Create Teleports
    for _, createPos in pairs(createTpPos) do
        local tile = createPos:getTile()
        if tile then
            local teleport = Game.createItem(config.teleportItemId, 1, createPos)
            if teleport then
                local arena = arenas[math.random(1, #arenas)]
                teleport:setDestination(arena[math.random(1, #arena)])
            end
        end
    end

    -- Show Create Message
    Game.broadcastMessage(config.createMessage)

    -- Add Event Remove Teleports
    addEvent(function ()
        for _, createPos in pairs(createTpPos) do
            local tile = createPos:getTile()
            if tile then
                local teleport = tile:getItemById(config.teleportItemId)
                    if teleport then
                    pos:sendMagicEffect(CONST_ME_POFF)
                    teleport:remove()
                end
            end
        end

        Game.broadcastMessage(config.removeMessage)
    end, config.minutesToRemoveTps)
    return false
end

lms:separator(" ")
lms:register()
 
Solution
OP
OP
Joriku

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,033
Solutions
15
Reaction score
323
Location
Sweden
YouTube
Joriku
I think what you want is something like this:
Lua:
local createTpPos = {
    Position(1007, 1001, 5),
    Position(1007, 1002, 5},
    Position(1007, 1003, 5}
}

local arenas = {
    -- Arena 1
    {Position(976, 1025, 11),
    Position(987, 1029, 11),
    Position(984, 1019, 11)},
    -- Arena 2
    {Position(958, 1046, 2),
    Position(960, 1036, 2),
    Position(965, 1042, 2)},
    -- Arena 3
    {Position(1026, 1017, 7),
    Position(1021, 1021, 7),
    Position(1031, 1013, 7)}
}

local config = {
    teleportItemId = 1387,
    createMessage = "createMessage",
    removeMessage = "removeMessage",
    minutesToRemoveTps = 3 * 1000 -- 3 seconds
}

local lms = TalkAction("/lms3")

function lms.onSay(player, words, param, type)
    -- Create Teleports
    for _, createPos in pairs(createTpPos) do
        local tile = createPos:getTile()
        if tile then
            local teleport = Game.createItem(config.teleportItemId, 1, createPos)
            if teleport then
                local arena = arenas[math.random(1, #arenas)]
                teleport:setDestination(arena[math.random(1, #arena)])
            end
        end
    end

    -- Show Create Message
    Game.broadcastMessage(config.createMessage)

    -- Add Event Remove Teleports
    addEvent(function ()
        for _, createPos in pairs(createTpPos) do
            local tile = createPos:getTile()
            if tile then
                local teleport = tile:getItemById(config.teleportItemId)
                    if teleport then
                    pos:sendMagicEffect(CONST_ME_POFF)
                    teleport:remove()
                end
            end
        end

        Game.broadcastMessage(config.removeMessage)
    end, config.minutesToRemoveTps)
    return false
end

lms:separator(" ")
lms:register()
Thank you, managed to solve it in a different way yesterday. Forgot to check by to update.

Your thread is not helping much if we don't know what's the issue. You're telling us that you're stuck but for me, I have no idea what's the exact problem. Please try to explain it a little bit better for us.

“What did you want to happen?” ✔️
“Paste the shortest block of code that reproduces the problem.” ✔️
“What actually happened? (Include any error details)” ❌
“Describe what you’ve tried so far” ❌
Here's an explanation:
I wanted to randomize an arena from arena 1 to 3. Make the teleports created at TPS location. Then automatically close them down after time has passed which in this case is 10*60*1000 (10 minutes)
Can you explain how this is supposed to work better?
I have no clue what you want to actually happen.
Sorry for being unclear
 
Top