SpawnOnDespawnSystem.cs 766 B

12345678910111213141516171819202122232425262728
  1. using Content.Server.Spawners.Components;
  2. using Robust.Shared.Prototypes;
  3. using Robust.Shared.Spawners;
  4. namespace Content.Server.Spawners.EntitySystems;
  5. public sealed class SpawnOnDespawnSystem : EntitySystem
  6. {
  7. public override void Initialize()
  8. {
  9. base.Initialize();
  10. SubscribeLocalEvent<SpawnOnDespawnComponent, TimedDespawnEvent>(OnDespawn);
  11. }
  12. private void OnDespawn(EntityUid uid, SpawnOnDespawnComponent comp, ref TimedDespawnEvent args)
  13. {
  14. if (!TryComp(uid, out TransformComponent? xform))
  15. return;
  16. Spawn(comp.Prototype, xform.Coordinates);
  17. }
  18. public void SetPrototype(Entity<SpawnOnDespawnComponent> entity, EntProtoId prototype)
  19. {
  20. entity.Comp.Prototype = prototype;
  21. }
  22. }