-- |============================================================================== -- | User Variables maxSpawnAmount = 6 spawnHeightOffset = 1 spawnPresetName = "SpawnedCharacter_Temp" spawnEveryMilliseconds = 1000 -- |============================================================================== -- | 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; 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. spawnID = entity.spawnPreset( spawnPresetName, x, y + spawnHeightOffset, z ); -- 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