Skip to content

Commit

Permalink
Add glow from CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
ntm5 committed Nov 11, 2024
1 parent fec26c9 commit 66e2c4c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
6 changes: 6 additions & 0 deletions mod/TTT.Roles/Helper/ColorManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TTT.Roles;

public class ColorManager
{

}
67 changes: 66 additions & 1 deletion mod/TTT.Roles/RoleManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Drawing;
using System.Collections;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text.Json.Serialization;
using CounterStrikeSharp.API;
Expand Down Expand Up @@ -29,6 +30,8 @@ public class RoleManager : PlayerHandler, IRoleService, IPluginBehavior
private int _traitorsLeft;
private InfoManager _infoManager;
private MuteManager _muteManager;

private List<CBaseModelEntity> _glowingEntities = [];

public void Start(BasePlugin parent)
{
Expand All @@ -46,6 +49,8 @@ public void Start(BasePlugin parent)
parent.RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath, HookMode.Pre);
parent.RegisterEventHandler<EventGameStart>(OnMapStart);
parent.RegisterEventHandler<EventPlayerSpawn>(Event_PlayerSpawn, HookMode.Post);

parent.RegisterListener<Listeners.CheckTransmit>(RegisterSetColor);

VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(hook =>
{
Expand Down Expand Up @@ -171,6 +176,7 @@ private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)

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

Expand Down Expand Up @@ -240,6 +246,32 @@ public Role GetRole(CCSPlayerController player)
return GetPlayer(player).PlayerRole();
}

private void RemoveGlow()
{
foreach (var glowEnt in _glowingEntities)
{
glowEnt.Remove();
}
_glowingEntities.Clear();
}

private void RegisterSetColor(CCheckTransmitInfoList infoList)
{
foreach (var (info, player) in infoList)
{
if (player == null)
continue;

if (IsTraitor(player))
continue;

foreach (var model in _glowingEntities)
{
info.TransmitEntities.Remove(model);
}
}
}

public void AddTraitor(CCSPlayerController player)
{
GetPlayer(player).SetPlayerRole(Role.Traitor);
Expand Down Expand Up @@ -465,6 +497,39 @@ private void PlayerSpawnNextFrame(CCSPlayerController player, CHandle<CCSPlayerP
// any further validity is up to the caller
return player_pawn.OriginalController.Value;
}

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);
}
}


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.286" />
<PackageReference Include="MySqlConnector" Version="2.3.6" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 66e2c4c

Please sign in to comment.