Maybe something like this may be helpful
In a script_entity named "spawners" put the following
Code: Select all
===== data ==========================
globalSpawners = {}
spawnerId = 0
-- ================= utilities =====================
function sumLevels()
local sumLevels = 0
for i=1,4 do
sumLevels = sumLevels + party:getChampion(i):getLevel()
end
return sumLevels
end
-- ================= functions =====================
function addSpawner(sid,creature,level,px,py,facing,coolDown,maxSpawn,levs,levmods)
if (sid == nil) then
spawnerId = spawnerId + 1
sid = "spawner_" .. spawnerId
end
local spawner = {
sid = sid,
creature = creature,
level = level,
px = px,
py = py,
facing = facing,
coolDown = coolDown,
maxSpawn = maxSpawn,
toSpawn = maxSpawn,
levs = levs,
levmods = levmods,
activated = false,
}
globalSpawners[sid] = spawner
return sid
end
function doSpawner(sid)
local spawner
if (type(sid) == "string") then
spawner = globalSpawners[sid]
else
spawner = globalSpawners[sid.id]
end
if (findEntity(spawner.sid) ~= nil) then
findEntity(spawner.sid):destroy()
end
if (spawner ~= nil) and (spawner.activated) then
spawner.activated = true
if (spawner.toSpawn > 0) then
local sumLevels = sumLevels()
local addstring = ""
if (spawner.levs) then
for i=1,(#spawner.levmods)/2 do
if (sumLevels >= spawner.levmods[2*i-1]) then
addstring = spawner.levmods[2*i]
end
end
end
spawn(spawner.creature .. addstring,spawner.level,spawner.px,spawner.py,spawner.facing)
local timer = spawn("timer",spawner.level,0,0,1,spawner.sid):
setTimerInterval(spawner.coolDown):
addConnector("activate","spawners","doSpawner"):
addConnector("activate",spawner.sid,"activate"):
activate()
end
spawner.toSpawn = math.max(spawner.toSpawn - 1,0)
else
print("spawner does not exist!")
end
end
function startSpawner(sid)
if (globalSpawners[sid] ~= nil) then
globalSpawners[sid].activated = true
doSpawner(sid)
end
end
function stopSpawner(sid)
if (globalSpawners[sid] ~= nil) then
globalSpawners[sid].activated = false
end
end
function resetSpawner(sid)
if (globalSpawners[sid] ~= nil) then
globalSpawners[sid].toSpawn = globalSpawners[sid].maxSpawn
end
end
Then, in whatever script you like, you can call
Code: Select all
local sid = spawners.addSpawner("sp_1","scavenger",1,6,7,2,5,3,true,{20,"_hard",40,"_veryhard"})
spawners.startSpawner(sid)
to create a spawner; in this example, a spawner called "sp_1", which spawns a scavenger, at level = 1, at x=6 and y=7, facing south; the coolDown is 5 seconds, and it spawns 3 creatures before stopping; since the 'levels' parameter is true, the function calculates the sum of the levels of the champions; if it is >= 20, it spawns "scavenger_hard" monsters (to be defined), and if it is >= 40, then... it is going to be tough!
If the first parameter of addSpawner is left to nil, then an id of the type "spawner_xx" will be assigned.
Additional functions: stopSpawner(sid) (sid is the spawner identity), resetSpawner(sid) (which resets the total number of monsters to be spawn).
Hope it helps
alois
*edit for typos*