Weapons/GlockWeapon.cs

A Glock pistol weapon class that derives from IronSightsWeapon. It exposes a PrimaryFireRate property, checks player input for primary attack, fires bullets using ShootBullet, and draws a simple two-ring crosshair that changes color when out of ammo, reloading, or still on cooldown.

using Sandbox.Rendering;

public sealed class GlockWeapon : IronSightsWeapon
{
	[Property] public float PrimaryFireRate { get; set; } = 0.15f;

	protected override float GetPrimaryFireRate() => PrimaryFireRate;

	protected override bool WantsPrimaryAttack()
	{
		return Input.Pressed( "attack1" );
	}

	public override void PrimaryAttack()
	{
		ShootBullet( PrimaryFireRate, GetBullet() );
	}

	public override void DrawCrosshair( HudPainter hud, Vector2 center )
	{
		var color = !HasAmmo() || IsReloading() || TimeUntilNextShotAllowed > 0 ? CrosshairNoShoot : CrosshairCanShoot;

		hud.SetBlendMode( BlendMode.Normal );
		hud.DrawCircle( center, 5, Color.Black );
		hud.DrawCircle( center, 3, color );
	}
}