First Gamemode

The Absolute Minimum

These are the absolute minimum files you will need to start a gamemode. This does not have any weapon or even a crosshair. It's a clean slate.

You can download this zip if you don't want to do bellow steps yourself.

gamemode.zip1.9KB

Steps

  • Create a folderwith the name of your gamemode in C:\Program Files (x86)\Steam\steamapps\common\sbox\addons
  • In your gamemode folder create a new folder code. This will be used to place all your game logic.
  • Create a .addonfile in your gamemode folder and put following code in it:
{
  "sharedassets": "*.*"
}
  • Create a Game.csfile in the code folder and add:
using Sandbox;

namespace GamemodeName
{
	public partial class GamemodeName: Sandbox.Game
	{
	  public override void ClientJoined( Client client )
	  {
	    base.ClientJoined( client );
	
	    var player = new MyPlayer();
	    client.Pawn = player;
	
	    player.Respawn();
	  }
	}
}
  • Create a Player.csfile in the code folder and add:
using Sandbox;

namespace GamemodeName
{
	partial class MyPlayer : Player
	{
		public override void Respawn()
		{
			SetModel( "models/citizen/citizen.vmdl" );
	
			Controller = new WalkController();
	
			Animator = new StandardPlayerAnimator();
	
			Camera = new FirstPersonCamera();
      // Camera = new ThirdPersonCamera();
	
			EnableAllCollisions = true;
			EnableDrawing = true;
			EnableHideInFirstPerson = true;
			EnableShadowInFirstPerson = true;
	
			base.Respawn();
		}
	}
}

Extra's

Here are some extra things you can add to your gamemode.

Crosshair

Hud.cs

using Sandbox.UI;

namespace GamemodeName
{
  public partial class Hud : Sandbox.HudEntity<RootPanel>
  {
    public Hud()
    {
      if ( IsClient )
      {
        RootPanel.SetTemplate( "Hud.html" );
      }
    }
  }
}

Hud.html

<div>
	<div style="position: absolute; left: 50%; top: 50%; background-color: white; border-radius: 10px; width: 4px; height: 4px; transform: translate( -50% -50% );"></div>
</div>

Chat
<chatbox></chatbox>