A game Component attached to a gib (TravisGib) object. On awake it randomly destroys about one third of child entities and starts a lifetime timer, then destroys the parent GameObject after 6 seconds.
using Sandbox;
namespace KOTH;
public sealed class TravisGib : Component
{
TimeSince AliveTime = new();
protected override void OnAwake()
{
base.OnAwake();
foreach (var Child in GameObject.Children)
{
if (Random.Shared.Next() % 3 == 0)
{
Child.Destroy();
}
}
AliveTime = 0;
}
protected override void OnUpdate()
{
if (AliveTime > 6f)
{
GameObject.Destroy();
}
}
}