A stage event class that spawns an "evil chest" enemy. On Start it notifies local chat, picks a random player, computes a nearby spawn position with random offset and rotation, spawns the enemy on the host, then removes the event.
using System;
using System.Drawing;
using System.Reflection;
using Sandbox;
public class StageEventEvilChest : StageEvent
{
public override void Start( int randSeed )
{
base.Start( randSeed );
Manager.Instance.Chat.AddLocalChatMessage( "An evil chest has spawned!", from: "" );
if ( Networking.IsHost )
{
var player = Manager.Instance.Players[Game.Random.Int( 0, Manager.Instance.Players.Count - 1 )];
var evilChestPos = player.Position2D + Utils.GetRandomVector() * Game.Random.Float( 100f, 500f );
Manager.Instance.SpawnEnemy( EnemyType.ChestEvil, evilChestPos, rotAngle: -90f + Game.Random.Float( -30f, 30f ) );
}
Manager.Instance.RemoveEvent( EventType );
}
}