Spawn with Random Offset component (#10969)
Adds SpawnRandomOffsetComponent, which can be used to randomly move a component on map init Co-authored-by: wrexbe <wrexbe@protonmail.com>
This commit is contained in:
committed by
GitHub
parent
f0fa24916c
commit
3d693c20c8
8
Content.Server/Coordinates/SpawnRandomOffsetComponent.cs
Normal file
8
Content.Server/Coordinates/SpawnRandomOffsetComponent.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Content.Server.Coordinates;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class SpawnRandomOffsetComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("offset")] public float Offset = 0.5f;
|
||||
}
|
||||
20
Content.Server/Coordinates/SpawnRandomOffsetSystem.cs
Normal file
20
Content.Server/Coordinates/SpawnRandomOffsetSystem.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Content.Shared.Random.Helpers;
|
||||
|
||||
namespace Content.Server.Coordinates;
|
||||
|
||||
public sealed class SpawnRandomOffsetSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SpawnRandomOffsetComponent, MapInitEvent>(OnMapInit);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, SpawnRandomOffsetComponent component, MapInitEvent args)
|
||||
{
|
||||
// TODO: Kill this extension with fire, thanks
|
||||
uid.RandomOffset(component.Offset);
|
||||
EntityManager.RemoveComponentDeferred(uid, component);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user