Skip to content

Coordinated Spawns

Metious edited this page Jun 28, 2022 · 3 revisions

Coordinated Spawns system allows you to spawn entities via world positions and rotations instead of the traditional LootDistribution system the game uses.

SMLHelper introduces a new handler named CoordinatedSpawnsHandler under the SMLHelper.V2.Handlers namespace, which registers spawns to the system.

Methods

RegisterCoordinatedSpawn(SpawnInfo spawnInfo)
RegisterCoordinatedSpawns(List<SpawnInfo> spawnInfos)
RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSpawn, List<Vector3> coordinatesToSpawnTo)
RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSpawn, Dictionary<Vector3, Vector3> coordinatesAndRotationsToSpawnTo)

Data Types

SpawnInfo

RegisterCoordinatedSpawn(SpawnInfo spawnInfo)

Registers a Coordinated Spawn.

Parameters

  • SpawnInfo spawnInfo
    Information about where and what entity should spawn.

RegisterCoordinatedSpawns(List<SpawnInfo> spawnInfos)

Registers multiple Coordinated Spawns.

Parameters

RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSpawn, List<Vector3> coordinatesToSpawnTo)

Registers multiple Coordinated Spawns for one single passed TechType.

Parameters

  • TechType techTypeToSpawn
    TechType entity to spawn.
  • List<Vector3> coordinatesToSpawnTo
    World positions to spawn to.

RegisterCoordinatedSpawnsForOneTechType(TechType techTypeToSpawn, Dictionary<Vector3, Vector3> coordinatesAndRotationsToSpawnTo)

[Deprecated]
Registers multiple Coordinated Spawns with rotations for one single passed TechType.

Parameters

  • TechType techTypeToSpawn
    TechType entity to spawn.
  • Dictionary<Vector3, Vector3> coordinatesAndRotationsToSpawnTo
    The world positions (key) and rotations (value) the entity should spawn to.

Remarks

This method existed prior to Spawnable.SpawnLocation and was only used in the Spawnable class.
Usage of this method is ill-advised as the SpawnInfo already covers all use-cases.

Examples

The following examples demonstrate the usage of CoordinatedSpawnsHandler methods.

using SMLHelper.V2.Handlers;
using UnityEngine;

[QModCore]
public static class MyMainClass
{
	[QModPatch]
	public static void MyPatch()
	{
		SpawnInfo reaperInfo = new SpawnInfo(TechType.ReaperLeviathan, new Vector3(280f, -1400f, 47f)); // Lava Lakes
		CoordinatedSpawnsHandler.RegisterCoordinatedSpawn(reaperInfo);
		
		var spawnInfos = new List<SpawnInfo>() 
		{
			new SpawnInfo(TechType.Seamoth, Vector3.zero),
			new SpawnInfo(TechType.SandShark, new Vector3(10, -4, 5), Vector3.up * 90f) // rotate its Y axis 90 degrees
		}
		CoordinatedSpawnsHandler.RegisterCoordinatedSpawns(spawnInfos);
		
		// Spawns a batch of titaniums around 10, -3, 15 world position
		var randomPositions = RandomPositions(new vector3(10f, -3f, 15f));
		CoordinatedSpawnsHandler.RegisterCoordinatedSpawnsForOneTechType(
			TechType.Titanium, randomPositions);
	}
	
	// Gets 5 random positions around the passed location.
	private static List<Vector3> RandomPositions(Vector3 centerPosition)
	{
		var result = new List<Vector3>();
		for (int i = 0; i < 5; i++)
		{
			result.Add(centerPosition + (Random.insideUnitSphere * i));
		}
		return result;
	}
}

SpawnInfo Class

Provides sufficient information for the Coordinated Spawns system to function.

public struct SpawnInfo : IEquatable<SpawnInfo>

Constructors

SpawnInfo(TechType techType, Vector3 spawnPosition)
SpawnInfo(string classId, Vector3 spawnPosition)
SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation)
SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation)
SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation)
SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation)

Please note that some pages are under construction and the links to them will be enabled as they are completed

Home
Quick Start Guide

[Adding]

[Editing]

[General Utilities]

[Language]

Clone this wiki locally