From ab1b90c6b86cf330d6c15d78e5beb59b2edce8ad Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Sat, 5 Mar 2022 11:37:41 +0100 Subject: [PATCH] Fix suicide exception when entity has no hands. Can be the case with ghost roles, etc. --- Content.Server/Chat/Commands/SuicideCommand.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Content.Server/Chat/Commands/SuicideCommand.cs b/Content.Server/Chat/Commands/SuicideCommand.cs index a7df9d709d..1f1564f379 100644 --- a/Content.Server/Chat/Commands/SuicideCommand.cs +++ b/Content.Server/Chat/Commands/SuicideCommand.cs @@ -88,9 +88,8 @@ namespace Content.Server.Chat.Commands $"{_entities.ToPrettyString(player.AttachedEntity.Value):player} is committing suicide"); // Held item suicide - var handsComponent = _entities.GetComponent(owner); - var itemComponent = handsComponent.GetActiveHandItem; - if (itemComponent != null) + if (_entities.TryGetComponent(owner, out HandsComponent handsComponent) + && handsComponent.GetActiveHandItem is {} itemComponent) { var suicide = _entities.GetComponents(itemComponent.Owner).FirstOrDefault(); @@ -100,6 +99,7 @@ namespace Content.Server.Chat.Commands return; } } + // Get all entities in range of the suicider var entities = EntitySystem.Get().GetEntitiesInRange(owner, 1, LookupFlags.Approximate | LookupFlags.IncludeAnchored).ToArray();