From e2141e4876a94cc02f4e7d5f0bdc86cce0f655ee Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 14 Dec 2024 16:37:12 +0100 Subject: [PATCH] Add entity glow --- mod/TTT.Roles/EntityGlowManager.cs | 92 +++++++++++++++++++++++++++++ mod/TTT.Roles/RoleManager.cs | 4 ++ public/TTT.Public/TTT.Public.csproj | 2 +- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 mod/TTT.Roles/EntityGlowManager.cs diff --git a/mod/TTT.Roles/EntityGlowManager.cs b/mod/TTT.Roles/EntityGlowManager.cs new file mode 100644 index 0000000..ea5924b --- /dev/null +++ b/mod/TTT.Roles/EntityGlowManager.cs @@ -0,0 +1,92 @@ +using System.Drawing; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; + +namespace TTT.Roles; + +public class EntityGlowManager +{ + private List _glowingEntities = new(); + private List _traitors = new(); + + public EntityGlowManager(BasePlugin plugin) + { + plugin.RegisterListener(RemoveGlow); + } + + public void SetTraitors(List traitors) + { + _traitors = traitors; + foreach (var traitor in traitors) + { + SetGlowing(traitor.PlayerPawn.Value!); + } + } + + private void RemoveGlow(CCheckTransmitInfoList infoList) + { + foreach (var (info, player) in infoList) + { + if (player == null) + continue; + + if (_traitors.Contains(player)) + continue; + + foreach (var model in _glowingEntities) + { + info.TransmitEntities.Remove(model); + } + } + } + + public void Dispose() + { + List entities = _glowingEntities; + + _glowingEntities.Clear(); + + Server.RunOnTick(5, () => + { + foreach (var entity in _glowingEntities) + { + entity.Remove(); + } + }); + + entities.Clear(); + } + + private void SetGlowing(CCSPlayerPawn pawn) + { + CBaseModelEntity? modelGlow = Utilities.CreateEntityByName("prop_dynamic"); + CBaseModelEntity? modelRelay = Utilities.CreateEntityByName("prop_dynamic"); + if (modelGlow == null || modelRelay == null) + { + return; + } + + string modelName = pawn.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.ModelName; + + modelRelay.SetModel(modelName); + modelRelay.Spawnflags = 256u; + modelRelay.RenderMode = RenderMode_t.kRenderNone; + modelRelay.DispatchSpawn(); + + modelGlow.SetModel(modelName); + modelGlow.Spawnflags = 256u; + modelGlow.DispatchSpawn(); + + modelGlow.Glow.GlowColorOverride = Color.Red; + modelGlow.Glow.GlowRange = 5000; + modelGlow.Glow.GlowTeam = -1; + modelGlow.Glow.GlowType = 3; + modelGlow.Glow.GlowRangeMin = 100; + + modelRelay.AcceptInput("FollowEntity", pawn, modelRelay, "!activator"); + modelGlow.AcceptInput("FollowEntity", modelRelay, modelGlow, "!activator"); + + _glowingEntities.Add(modelGlow); + _glowingEntities.Add(modelRelay); + } +} \ No newline at end of file diff --git a/mod/TTT.Roles/RoleManager.cs b/mod/TTT.Roles/RoleManager.cs index 4d88498..1d907e3 100644 --- a/mod/TTT.Roles/RoleManager.cs +++ b/mod/TTT.Roles/RoleManager.cs @@ -29,12 +29,14 @@ public class RoleManager : PlayerHandler, IRoleService, IPluginBehavior private int _traitorsLeft; private InfoManager _infoManager; private MuteManager _muteManager; + private EntityGlowManager _entityGlowManager; public void Start(BasePlugin parent) { _roundService = new RoundManager(this, parent); _infoManager = new InfoManager(this, _roundService, parent); _muteManager = new MuteManager(parent); + _entityGlowManager = new EntityGlowManager(parent); ModelHandler.RegisterListener(parent); //ShopManager.Register(parent, this); //disabled until items are implemented. //CreditManager.Register(parent, this); @@ -171,6 +173,7 @@ private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) Server.NextFrame(Clear); _muteManager.UnMuteAll(); + _entityGlowManager.Dispose(); return HookResult.Continue; } @@ -217,6 +220,7 @@ public void AddRoles() } AddInnocents(eligible); + _entityGlowManager.SetTraitors(GetTraitors().ToList()); } public ISet GetTraitors() diff --git a/public/TTT.Public/TTT.Public.csproj b/public/TTT.Public/TTT.Public.csproj index 7d965c2..f6853f2 100644 --- a/public/TTT.Public/TTT.Public.csproj +++ b/public/TTT.Public/TTT.Public.csproj @@ -5,7 +5,7 @@ enable - +