stageEvents/StageEventMushrooms.cs

A StageEvent subclass that runs a "mushrooms" event. On Start it plays a UI sound, posts a local chat message, sets a 10s lifetime and begins spawning Mushroom enemies periodically while the event is active. Spawning only runs on the network host.

Networking
using System;
using System.Reflection;
using Sandbox;

public class StageEventMushrooms : StageEvent
{
	private TimeSince _timeSinceMushroom;

	public override void Start( int randSeed )
	{
		base.Start( randSeed );

		Manager.Instance.PlaySfxUIRpc( "mushrooms", pitch: Game.Random.Float( 0.95f, 1.05f ), volume: 0.75f );

		Manager.Instance.Chat.AddLocalChatMessage( "Strange mushrooms are growing...", from: "" );

		Lifetime = 10f;

		_timeSinceMushroom = 0f;
	}

	public override void Update()
	{
		base.Update();

		if( TimeSinceStart > Lifetime )
		{
			Manager.Instance.RemoveEvent( EventType );
		}

		if ( !Networking.IsHost )
			return;

		if ( _timeSinceMushroom > 0.25f )
		{
			Manager.Instance.SpawnEnemy( EnemyType.Mushroom, Manager.Instance.GetRandomSpawnPos( buffer: 5f ) );

			_timeSinceMushroom = 0f;
		}
	}

	public override void Remove()
	{
		base.Remove();

	}
}