Fix suicide exception when entity has no hands.

Can be the case with ghost roles, etc.
This commit is contained in:
Vera Aguilera Puerto
2022-03-05 11:37:41 +01:00
parent cba573616b
commit ab1b90c6b8

View File

@@ -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<HandsComponent>(owner);
var itemComponent = handsComponent.GetActiveHandItem;
if (itemComponent != null)
if (_entities.TryGetComponent(owner, out HandsComponent handsComponent)
&& handsComponent.GetActiveHandItem is {} itemComponent)
{
var suicide = _entities.GetComponents<ISuicideAct>(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<EntityLookupSystem>().GetEntitiesInRange(owner, 1, LookupFlags.Approximate | LookupFlags.IncludeAnchored).ToArray();