Player/PlayerPawn.Commands.cs

A partial PlayerPawn class file adding a console command "kill". The ConKill console command looks up the local player's pawn and, if valid and alive, creates a large FDamageRequest targeting the pawn's DamageComponent and dispatches a DamageRequestEvent to the active game scene, then logs "kill".

Networking
using KOTH.UI;
using Sandbox.Events;

namespace KOTH;

public partial class PlayerPawn
{
	[ConCmd("kill")]
	private static void ConKill()
	{
		var LocalPlayerPawn = PlayerState.Local?.PlayerPawn;

		if (LocalPlayerPawn == null)
		{
			return;
		}

		if (LocalPlayerPawn.IsValid() && LocalPlayerPawn.IsAlive)
		{
			FDamageRequest DamageRequest = new()
			{
				TargetDamageComponent = LocalPlayerPawn.DamageComponent,
				BaseDamage = 9999,
			};
			Game.ActiveScene.Dispatch(new DamageRequestEvent(DamageRequest));
			Log.Info("kill");
		}
	}
}