Changing respawn settings
These two calls change whether a spawner respawns and how long it waits.
Spawners respawn on or off, and the wait
SetRespawn turns respawning on or off and sets its chance, and SetRespawnTiming sets how long a spawner waits.
public static class Spawners
{
public static bool SetRespawn(string id, bool enabled, float chance);
public static bool SetRespawnTiming(string id, RespawnTime time, bool useCustomSpawnTime, int minSeconds, int maxSeconds);
}
| Method | Returns | What it does |
|---|---|---|
SetRespawn(id, enabled, chance) | bool | Turns respawning on or off and sets the chance. true when written. |
SetRespawnTiming(id, time, useCustomSpawnTime, minSeconds, maxSeconds) | bool | Sets the wait. true when written. |
Things to know
SetRespawnsets the chance of a spawn. The chance is limited to 0 through 1. (it setsspawnSettings.respawnEnabledandspawnSettings.spawnChance.)SetRespawnTimingsets how long a spawner waits. The two seconds values are game seconds, and they only count whenuseCustomSpawnTimeistrue. (it setsspawnSettings.spawnTime,useCustomSpawnTime,minRespawnTimeandmaxRespawnTime.)- A new wait only applies from the next spawn, not to the countdown already running. The game picks the next countdown once and keeps it until that spawn happens.
SecondsToSpawnis that countdown, and your mod can’t change it. (the countdown is drawn inSetSpawnTime, which returns early while a countdown is running.SecondsToSpawnistimetospawn, and the framework does not write it.) - Changes last for the scene session. The game does not save these settings, so loading the scene again brings back the values the map was built with. The game does save the countdown. (
respawnEnabled,spawnChance,spawnTime,useCustomSpawnTime,minRespawnTimeandmaxRespawnTimeare markedfsIgnoreinSpawnSettings, so the save does not store them.timetospawnis notfsIgnore, so the save keeps the timer.)
Limits
SetRespawnreturnsfalsefor an unknown id, or while a save is loading or being written.- Turning respawn on may not start the timer. The game only starts the respawn timer when a spawner starts with respawn already on. A spawner that started with respawn off gets the new setting, but its timer does not run until its scene loads again.
SetRespawnTimingreturnsfalsefor an unknown id, atimethat is not inRespawnTime,minSecondsbelow 0,maxSecondsbelowminSeconds, or while a save is loading or being written.