Component attached to game objects that triggers a death sequence. It holds a Spectator prefab, a synced Should flag, and on update (server-side) calls Die when Should is true. Die clones the Spectator at the object's position, network-spawns it to the owner, and destroys the original object. It also exposes an Rpc.Broadcast Now method that sets Should to true.
using Sandbox;
public class Death : Component
{
[Property] public GameObject Spectator {get;set;}
[Sync] public bool Should {get;set;}
protected override void OnUpdate()
{
if (IsProxy) return;
if (Should) Die();
}
void Die()
{
var spectator = Spectator.Clone(WorldPosition);
spectator.NetworkSpawn(Network.Owner); DestroyGameObject();
}
[Rpc.Broadcast]
public void Now()
{Should = true;}
}