-- |============================================================================== -- | User Variables maxSpawnAmount = 6 spawnHeightOffset = 1 spawnEveryMilliseconds = 1000 numSpawnVariations = 6 -- for 6 zombie types presetSpawns = {}; presetSpawns[1] = "SpawnedCharacter_Temp"; presetSpawns[2] = "SpawnedCharacter_Temp"; presetSpawns[3] = "SpawnedCharacter_Temp"; presetSpawns[4] = "SpawnedCharacter_Temp"; presetSpawns[5] = "SpawnedCharacter_Temp"; presetSpawns[6] = "SpawnedCharacter_Temp"; -- keep adding more or remove for that amount you want -- |============================================================================== -- | Private system variables obj = 0; numSpawns = 0; spawnCounter = 0; activeSpawns = {} function onInit(objID) obj = objID; time.startMultiTimer(1,obj,spawnEveryMilliseconds); time.startMultiTimer(2,obj,300); numSpawns = 0; math.randomseed(os.time()) end function onMultiTimer(timerID) -- timer 1 = spawn entity if(timerID==1)then if( numSpawns < maxSpawnAmount)then -- get the position of the spawn point x,y,z = entity.getPosition(obj); -- Spawn the preset you want in the scene. variation = math.random(1, numSpawnVariations); spawnID = -1; if(variation == 1 )then spawnID = entity.spawnPreset( presetSpawns[variation], x, y + spawnHeightOffset, z ); elseif(variation == 2 )then spawnID = entity.spawnPreset( presetSpawns[variation], x, y + spawnHeightOffset, z ); elseif(variation == 3 )then spawnID = entity.spawnPreset( presetSpawns[variation], x, y + spawnHeightOffset, z ); elseif(variation == 4 )then spawnID = entity.spawnPreset( presetSpawns[variation], x, y + spawnHeightOffset, z ); elseif(variation == 5 )then spawnID = entity.spawnPreset( presetSpawns[variation], x, y + spawnHeightOffset, z ); elseif(variation == 6 )then spawnID = entity.spawnPreset( presetSpawns[variation], x, y + spawnHeightOffset, z ); end -- then add it too its own manager numSpawns = numSpawns +1; activeSpawns[spawnCounter] = spawnID; spawnCounter = spawnCounter + 1; end end -- timer 2 = check number of active spawns and remove if deleted / destroyed if(timerID==2)then for key,value in pairs(activeSpawns) do local eID = value; if(entity.exist(eID) == 0)then activeSpawns[key] = nil numSpawns = numSpawns -1; end end end end -- Function you can call from another script to reduce the spawned amount to spawn more. function reduceSpawnAmount() numSpawns = numSpawns - 1; end