I'm trying to make this script work, I need it to only summon the amount defined in maxMonster, but it summons the monsters infinitely, could anyone help me? And I also need you to summon 2 different monsters, you can use Demon as an example
Lua:
local function getRandomPosition(minPosition, maxPosition)
local randomX = math.random(minPosition.x, maxPosition.x)
local randomY = math.random(minPosition.y, maxPosition.y)
local randomZ = math.random(minPosition.z, maxPosition.z)
return Position(randomX, randomY, randomZ)
end
local function summon()
local boss = false
local bossId
local count = 0
local positionCenter = Position(33710, 31634, 14)
local spectators = Game.getSpectators(positionCenter, false, false, 10, 10, 10, 10)
local maxMonster = 3
for _, creature in pairs(spectators) do
if creature:isMonster() then
if creature:getName():lower() == "goshnar's megalomania" then
boss = true
bossId = creature:getId()
elseif creature:getName():lower() == "Greater Splinter of Madness" then
count = count + 1
end
end
end
if boss and count < maxMonster then
local minPosition = Position(33703, 31628, 14)
local maxPosition = Position(33717, 31640, 14)
local randomPosition = getRandomPosition(minPosition, maxPosition)
Game.createMonster("Greater Splinter of Madness", randomPosition):registerEvent("fieryHearts")
end
if boss and count < maxMonster then
local randomDelay = math.random(40, 60) * 1000
addEvent(summon, randomDelay)
end
end