Component for SCP-173 primary attack. On local update when left mouse pressed it traces a box forward from the component position using the scene camera direction, plays a crack sound and invokes Now() on a Death component of the hit GameObject.
using Sandbox;
public class SCP_173_Primary_Attack : Component
{
GameObject c;
protected override void OnStart()
{if (IsProxy) return;
c = Scene.Camera.GameObject;}
public bool Disabled {get;set;}
[Property] public GameObject Spectator {get;set;}
protected override void OnUpdate()
{ if (IsProxy || Disabled || !Input.Pressed("lmb")) return;
var From = WorldPosition + new Vector3(0, 0, 100);
var To = From + c.WorldRotation * new Vector3(64, 0, 0);
SceneTraceResult Box = Scene.Trace
.Box(BBox.FromPositionAndSize(0, 16), From, To)
.WithTag("human").Run();
if (Box.Hit)
{Sound.Play("crack", Box.GameObject.WorldPosition);
Box.GameObject.GetComponent<Death>().Now();}
}
}