Skip to content

Commit

Permalink
Add entity glow
Browse files Browse the repository at this point in the history
  • Loading branch information
ntm5 committed Dec 14, 2024
1 parent fec26c9 commit e2141e4
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
92 changes: 92 additions & 0 deletions mod/TTT.Roles/EntityGlowManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Drawing;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;

namespace TTT.Roles;

public class EntityGlowManager
{
private List<CBaseModelEntity> _glowingEntities = new();
private List<CCSPlayerController> _traitors = new();

public EntityGlowManager(BasePlugin plugin)
{
plugin.RegisterListener<Listeners.CheckTransmit>(RemoveGlow);
}

public void SetTraitors(List<CCSPlayerController> 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<CBaseModelEntity> 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<CBaseModelEntity>("prop_dynamic");
CBaseModelEntity? modelRelay = Utilities.CreateEntityByName<CBaseModelEntity>("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);
}
}
4 changes: 4 additions & 0 deletions mod/TTT.Roles/RoleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -171,6 +173,7 @@ private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)

Server.NextFrame(Clear);
_muteManager.UnMuteAll();
_entityGlowManager.Dispose();
return HookResult.Continue;
}

Expand Down Expand Up @@ -217,6 +220,7 @@ public void AddRoles()
}

AddInnocents(eligible);
_entityGlowManager.SetTraitors(GetTraitors().ToList());
}

public ISet<CCSPlayerController> GetTraitors()
Expand Down
2 changes: 1 addition & 1 deletion public/TTT.Public/TTT.Public.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.281" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.291" />
<PackageReference Include="MySqlConnector" Version="2.3.6" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit e2141e4

Please sign in to comment.