Files
OldThink/Content.Client/Commands/ToggleHealthBarsCommand.cs

45 lines
1.5 KiB
C#
Raw Normal View History

2023-04-27 23:54:17 +06:00
using Robust.Client.Player;
using Robust.Shared.Console;
using Content.Shared._White.EntityHealthBar;
2023-04-27 23:54:17 +06:00
namespace Content.Client.Commands
{
public sealed class ToggleHealthBarsCommand : IConsoleCommand
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public string Command => "togglehealthbars";
public string Description => "Toggles a health bar above mobs.";
public string Help => $"Usage: {Command}";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = _playerManager.LocalPlayer;
if (player == null)
{
shell.WriteLine("You aren't a player.");
return;
}
var playerEntity = player?.ControlledEntity;
if (playerEntity == null)
{
shell.WriteLine("You do not have an attached entity.");
return;
}
2023-05-05 11:00:15 +03:00
if (!_entityManager.TryGetComponent<ShowWhiteHealthBarsComponent>(playerEntity, out var glassComp))
2023-04-27 23:54:17 +06:00
{
2023-05-05 11:00:15 +03:00
_entityManager.AddComponent<ShowWhiteHealthBarsComponent>((EntityUid) playerEntity);
2023-04-27 23:54:17 +06:00
shell.WriteLine("Enabled health overlay.");
return;
}
2023-05-05 11:00:15 +03:00
_entityManager.RemoveComponent<ShowWhiteHealthBarsComponent>((EntityUid) playerEntity);
2023-04-27 23:54:17 +06:00
shell.WriteLine("Disabled health overlay.");
return;
}
}
}