using Sandbox; using System; using System.Linq; // // You don't need to put things in a namespace, but it doesn't hurt. // namespace MyGame; /// /// This is your game class. This is an entity that is created serverside when /// the game starts, and is replicated to the client. /// /// You can use this to create things like HUDs and declare which player class /// to use for spawned players. /// public partial class MyGame : Sandbox.GameManager { /// /// Called when the game is created (on both the server and client) /// public MyGame() { if ( Game.IsClient ) { Game.RootPanel = new Hud(); } } /// /// A client has joined the server. Make them a pawn to play with /// public override void ClientJoined( IClient client ) { base.ClientJoined( client ); // Create a pawn for this client to play with var pawn = new Pawn(); client.Pawn = pawn; pawn.Respawn(); pawn.DressFromClient( client ); // Get all of the spawnpoints var spawnpoints = Entity.All.OfType(); // chose a random one var randomSpawnPoint = spawnpoints.OrderBy( x => Guid.NewGuid() ).FirstOrDefault(); // if it exists, place the pawn there if ( randomSpawnPoint != null ) { var tx = randomSpawnPoint.Transform; tx.Position = tx.Position + Vector3.Up * 50.0f; // raise it up pawn.Transform = tx; } } }