• 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 Spawn item at multiples random pos.

Kuantikum

Member
Joined
Jul 3, 2015
Messages
219
Solutions
1
Reaction score
20
Hello guys,

Currently what this script does when the server starts is to create an item in a random position. Is it possible to create the same item in more random positions?


Lua:
local STARTUP = {}

STARTUP[#STARTUP + 1] = { -- Quest Stuff

action = function()
local fromPos = {x=3376, y=776, z=6}
local toPos = {x=3390, y=786, z=6}
local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
addEvent(function()doCreateItem(25457, 1, pos)end, 1000)
     
    end
}

function onStartup()
    for _, cmd in pairs(STARTUP) do
        if (cmd.msg) then
            --print(">> " .. cmd.msg)
            local x = os.clock()
            cmd.action()
            --print(string.format("> Done in %.2f seconds", os.clock() - x))
        else
            cmd.action()
        end
    end

    table.clear(STARTUP)
    STARTUP = nil

    --print(">> All done on ".. os.date("%a %b %d %X %Y", os.time()))
    return true
end

PS: I tryied to set something like add more lines this:
addEvent(function()doCreateItem(25457, 1, pos)end, 1000)

But the script takes the same random pos to all items:

1611191296290.png

Thx you!
 
Last edited:
Solution
Edit itemsQUANT, it ill create 1000 items
Lua:
local itemsQUANT = 1000
local STARTUP = {}

STARTUP[#STARTUP + 1] = { -- Quest Stuff

action = function()
local fromPos = {x=3376, y=776, z=6}
local toPos = {x=3390, y=786, z=6}
for i = 1, itemsQUANT do
    local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
    addEvent(function()doCreateItem(25457, 1, pos)end, 1000)
end 
    end
}

function onStartup()
    for _, cmd in pairs(STARTUP) do
        if (cmd.msg) then
            --print(">> " .. cmd.msg)
            local x = os.clock()
            cmd.action()
            --print(string.format("> Done in %.2f seconds", os.clock() - x))
        else
            cmd.action()...
Edit itemsQUANT, it ill create 1000 items
Lua:
local itemsQUANT = 1000
local STARTUP = {}

STARTUP[#STARTUP + 1] = { -- Quest Stuff

action = function()
local fromPos = {x=3376, y=776, z=6}
local toPos = {x=3390, y=786, z=6}
for i = 1, itemsQUANT do
    local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
    addEvent(function()doCreateItem(25457, 1, pos)end, 1000)
end 
    end
}

function onStartup()
    for _, cmd in pairs(STARTUP) do
        if (cmd.msg) then
            --print(">> " .. cmd.msg)
            local x = os.clock()
            cmd.action()
            --print(string.format("> Done in %.2f seconds", os.clock() - x))
        else
            cmd.action()
        end
    end

    table.clear(STARTUP)
    STARTUP = nil

    --print(">> All done on ".. os.date("%a %b %d %X %Y", os.time()))
    return true
end
 
Solution
Edit itemsQUANT, it ill create 1000 items
Lua:
local itemsQUANT = 1000
local STARTUP = {}

STARTUP[#STARTUP + 1] = { -- Quest Stuff

action = function()
local fromPos = {x=3376, y=776, z=6}
local toPos = {x=3390, y=786, z=6}
for i = 1, itemsQUANT do
    local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
    addEvent(function()doCreateItem(25457, 1, pos)end, 1000)
end
    end
}

function onStartup()
    for _, cmd in pairs(STARTUP) do
        if (cmd.msg) then
            --print(">> " .. cmd.msg)
            local x = os.clock()
            cmd.action()
            --print(string.format("> Done in %.2f seconds", os.clock() - x))
        else
            cmd.action()
        end
    end

    table.clear(STARTUP)
    STARTUP = nil

    --print(">> All done on ".. os.date("%a %b %d %X %Y", os.time()))
    return true
end


Thx you very much!
 
Back
Top