• 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 randomly spawn monsters on area

firefox125

New Member
Joined
Apr 8, 2023
Messages
21
Reaction score
1
this is what i have by now it does spawn monsters basicly one by one to be precise hehe, it is for a private hunting area for donor players, i need to make this a bit more compact i was trying but just making the script stop working. i would appreciate if anyone could help me if not with shortening the code also i want to clean already created monsters so if a player tries to summon more than 1 wave just remove previous monsters and spawn new ones(im trying to adapt creating a spawn so the monsters respawn after killed just like normal ones), this is for a multi lvl area so 1 item summons x monsters and the other one summons x different monsters by level.

i know this sounds hard but few hours ago i had nothing xD, will continue trying and going to post the final script here so anyone can use, been looking for a script like this but none work also tried modular map one but as im using OTBR it does not function properly(doesnt create or remove anything also tried to fix it but got frustated thats why im creating atleast the random monster spawn)


Lua:
local topL = Position(1500, 300, 7)
local botR = Position(1650, 420, 7)

local kb = Action()
  local cTime = os.time()
function kb.onUse(player, item, position, creature)
     if Game.getStorageValue(1235) > cTime then
                 player:sendTextMessage(MESSAGE_STATUS_WARNING, 'wait a while to continue next wave.'
                 else
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                Game.createMonster("Dragon Lord", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                                Game.createMonster("Demon", Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))


            end
                    Game.setStorageValue(1235, os.time() + 1)
    return true
end


kb:uid(14785)
kb:register()

also i have to change storage everytime to test if the script works as it is not actually working it just propmts that i have to wait, and i have done so hahaha
 
Lua:
local topL = Position(1500, 300, 7)
local botR = Position(1650, 420, 7)

local monsters = {
    {name = "Dragon", amount = 35},
    {name = "Dragon Lord", amount = 34},
    {name = "Demon", amount = 35},
}

local kb = Action()

function kb.onUse(player, item, position, creature)

    local cTime = os.time()
    if Game.getStorageValue(1235) > cTime then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "wait a while to continue next wave.")
        return true
    end
    
    for i = 1, #monsters do
        for n = 1, #monsters[i].amount do
            Game.createMonster(monsters[i].name, Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
        end
    end
    
    Game.setStorageValue(1235, os.time() + 1)
    return true
end

kb:uid(14785)
kb:register()
 
Lua:
local topL = Position(1500, 300, 7)
local botR = Position(1650, 420, 7)

local monsters = {
    {name = "Dragon", amount = 35},
    {name = "Dragon Lord", amount = 34},
    {name = "Demon", amount = 35},
}

local kb = Action()

function kb.onUse(player, item, position, creature)

    local cTime = os.time()
    if Game.getStorageValue(1235) > cTime then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "wait a while to continue next wave.")
        return true
    end
 
    for i = 1, #monsters do
        for n = 1, #monsters[i].amount do
            Game.createMonster(monsters[i].name, Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
        end
    end
 
    Game.setStorageValue(1235, os.time() + 1)
    return true
end

kb:uid(14785)
kb:register()
thank you very much, that was a basic problem but im still learing my ways around scripting nowdays.

is there a way to make them respawn when they are killed? not instantly but like normal respawns or to clean the room and appear them again x amount of time ?

edit..
already tried it but promts this error fixed it adding "" to numers on amount = "#"
after that it does summon the monsters great :D only problem is that it only summons 3 monsters of any even if i change ammount to 500 only 3 appear, also the storage still is not working i can want from 1 min to 10 and it makes no difference still makes me wait more hahaha
Lua:
Lua script error: \data\scripts\MDR\Privatehunt.lua:callback
[2023-17-05 11:32:23.646] [error] ...bal\data\scripts\MDR\Privatehunt.lua:59: attempt to get length of field 'amount' (a number value)
stack traceback:
        [C]: in function '__len'
        ...bal \MDR\Privatehunt.lua:59: in function <...bal\data\scripts\MDR\Privatehunt.lua:50>
 
Last edited:
thank you very much, that was a basic problem but im still learing my ways around scripting nowdays.

is there a way to make them respawn when they are killed? not instantly but like normal respawns or to clean the room and appear them again x amount of time ?

edit..
already tried it but promts this error fixed it adding "" to numers on amount = "#"
after that it does summon the monsters great :D only problem is that it only summons 3 monsters of any even if i change ammount to 500 only 3 appear, also the storage still is not working i can want from 1 min to 10 and it makes no difference still makes me wait more hahaha
Lua:
Lua script error: \data\scripts\MDR\Privatehunt.lua:callback
[2023-17-05 11:32:23.646] [error] ...bal\data\scripts\MDR\Privatehunt.lua:59: attempt to get length of field 'amount' (a number value)
stack traceback:
        [C]: in function '__len'
        ...bal \MDR\Privatehunt.lua:59: in function <...bal\data\scripts\MDR\Privatehunt.lua:50>
you'd have to show your current code

-- edit

Sorry I see the issue

change
Lua:
for n = 1, #monsters[i].amount do
for
Lua:
for n = 1, monsters[i].amount do
 
you'd have to show your current code

-- edit

Sorry I see the issue

change
Lua:
for n = 1, #monsters[i].amount do
for
Lua:
for n = 1, monsters[i].amount do
removed the # on monsters and got this error

Lua:
2023-17-05 12:00:42.871] [error] ...bal\data\scripts\MDR\Privatehunt.lua:58: 'for' limit must be a number
stack traceback:
        [C]: at 0x7ff62391d530
        ...bal\data\scripts\MDR\Privatehunt.lua:58: in function <...bal\data\scripts\MDR\Privatehunt.lua:50>

using

Code:
local topL = Position(1500, 300, 7)
local botR = Position(1650, 420, 7)

local monsters = {
    {name = "prueba", amount = "5"},
    {name = "morgaroth", amount = "6"},
    {name = "orshabaal", amount = "2"}
}

local kb = Action()

function kb.onUse(player, item, position, creature)

    local cTime = os.time()
    if Game.getStorageValue(1236) > cTime then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "wait a while to continue next wave.")
        return true
    end
    
    for i = 1, monsters do
        for n = 1, monsters[i].amount do
            Game.createMonster(monsters[i].name, Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
        end
    end
    
    Game.setStorageValue(1235, os.time() + 1)
    return true
end

kb:uid(14785)
kb:register()

same problem appears if we remove "" to leave at it was at the beginning

Code:
local monsters = {
    {name = "prueba", amount = 5},
    {name = "morgaroth", amount = 6},
    {name = "orshabaal", amount = 2}
}
 
removed the # on monsters and got this error

Lua:
2023-17-05 12:00:42.871] [error] ...bal\data\scripts\MDR\Privatehunt.lua:58: 'for' limit must be a number
stack traceback:
        [C]: at 0x7ff62391d530
        ...bal\data\scripts\MDR\Privatehunt.lua:58: in function <...bal\data\scripts\MDR\Privatehunt.lua:50>

using

Code:
local topL = Position(1500, 300, 7)
local botR = Position(1650, 420, 7)

local monsters = {
    {name = "prueba", amount = "5"},
    {name = "morgaroth", amount = "6"},
    {name = "orshabaal", amount = "2"}
}

local kb = Action()

function kb.onUse(player, item, position, creature)

    local cTime = os.time()
    if Game.getStorageValue(1236) > cTime then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "wait a while to continue next wave.")
        return true
    end
    
    for i = 1, monsters do
        for n = 1, monsters[i].amount do
            Game.createMonster(monsters[i].name, Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
        end
    end
    
    Game.setStorageValue(1235, os.time() + 1)
    return true
end

kb:uid(14785)
kb:register()

same problem appears if we remove "" to leave at it was at the beginning

Code:
local monsters = {
    {name = "prueba", amount = 5},
    {name = "morgaroth", amount = 6},
    {name = "orshabaal", amount = 2}
}
you removed if off of both the lines.

Only the 2nd one needs it removed.

Lua:
    for i = 1, #monsters do -- #monsters is counting the amount of stuff in the table
        for n = 1, monsters[i].amount do -- this one is grabbing a direct number from the table
 
you removed if off of both the lines.

Only the 2nd one needs it removed.

Lua:
    for i = 1, #monsters do -- #monsters is counting the amount of stuff in the table
        for n = 1, monsters[i].amount do -- this one is grabbing a direct number from the table
done that way, now it summons but a random ammount from 1 to 5 set the ammount to 10 to make tests and it is only appearing from 1 to 5 monsters of the same kind
 
done that way, now it summons but a random ammount from 1 to 5 set the ammount to 10 to make tests and it is only appearing from 1 to 5 monsters of the same kind
Check dm's when you get a chance. haha

My guess is that your top left and bottom right positions is a huge area, with impossible to spawn locations within.
So, we'll add an additional while loop to ensure the creatures are definitely spawning.

Lua:
local topL = Position(1500, 300, 7)
local botR = Position(1650, 420, 7)
local storage = 1235

local monsters = {
    {name = "Dragon", amount = 35},
    {name = "Dragon Lord", amount = 34},
    {name = "Demon", amount = 35},
}

local kb = Action()

function kb.onUse(player, item, position, creature)

    local cTime = os.time()
    if Game.getStorageValue(storage) > cTime then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "wait a while to continue next wave.")
        return true
    end
  
    for i = 1, #monsters do
        for n = 1, monsters[i].amount do
            local spawnedSuccessfully = false
            local attempts = 0
            while attempts < 100 and spawnedSuccessfully == false do
                local monster = Game.createMonster(monsters[i].name, Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                if monster and monster:isCreature() then
                    spawnedSuccessfully = true
                end
                attempts = attempts + 1
            end
        end
    end
  
    Game.setStorageValue(storage, cTime + 1)
    return true
end

kb:uid(14785)
kb:register()
 
Last edited:
for the update, right now the script is like this thanks to @Xikini

you can choose the amount of monsters to appear as for any amount of different monsters also if you use the item or lever depending on what you use it for
next to be addeed(different rooms to spawn different monsters as staged by lvl)

Lua:
local topL = Position(1500, 300, 5)
local botR = Position(1650, 420, 5)
local storage = 1235
local timeBetweenUses = 1 -- seconds

local monsters = {
    {name = "Dwarf", amount = 80},
    {name = "Cyclops", amount = 30},
    {name = "orge brute", amount = 50},
        {name = "Ogre Ruffian", amount = 50},
}

local spawnedCreatures = {}

local kb = Action()

            for _, spectator in pairs(getSpectators()) do
                if spectator:isPlayer() then
                    spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                    spectator:teleportTo(config.teleportToPosition, false)
                    config.teleportToPosition:sendMagicEffect(CONST_ME_TELEPORT)
                end
            end

function kb.onUse(player, item, position, creature)

    local cTime = os.time()
    if Game.getStorageValue(storage) > cTime then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "wait a while to continue next wave.")
        return true
    end
    
    for i = 1, #spawnedCreatures do
        local creature = Creature(spawnedCreatures[i].monsterId)
        if creature then
            creature:remove()
        end
    end
    spawnedCreatures = {}
    
    for i = 1, #monsters do
        for n = 1, monsters[i].amount do
            local spawnedSuccessfully = false
            local attempts = 0
            while attempts < 100 and spawnedSuccessfully == false do
                local monster = Game.createMonster(monsters[i].name, Position(math.random(topL.x, botR.x), math.random(topL.y, botR.y), topL.z))
                if monster and monster:isCreature() then
                    spawnedSuccessfully = true
                    spawnedCreatures[#spawnedCreatures + 1] = {monsterId = monster:getId()}
                end
                attempts = attempts + 1
            end
        end
    end
    
    Game.setStorageValue(storage, cTime + timeBetweenUses)
    return true
end

kb:aid(2301)
kb:register()
 
Back
Top