Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Glow & Server Shop #7

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 74 additions & 16 deletions mod/TTT.Detective/DetectiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using TTT.Player;
using TTT.Public.Action;
using TTT.Public.Behaviors;
using TTT.Public.Extensions;
using TTT.Public.Formatting;
Expand All @@ -29,27 +31,49 @@ public void Start(BasePlugin parent)
.Where(player => (player.Buttons & PlayerButtons.Use) != 0)) OnPlayerUse(player);
});


/**
VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(hook =>
{
var info = hook.GetParam<CTakeDamageInfo>(1);
if (info.Attacker.Value == null || !info.Attacker.Value.IsValid) return HookResult.Continue;
var attacker = info.Attacker.Value.As<CCSPlayerController>();
if (attacker == hook.GetParam<CBaseEntity>(0)) return HookResult.Continue;
if (info.AmmoType is not TaserAmmoType) return HookResult.Continue;
VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(OnZeus, HookMode.Pre);

info.Damage = 1f;
}

if (!attacker.IsReal()) return HookResult.Continue;

var ammoType = info.AmmoType;
private HookResult OnZeus(DynamicHook hook)
{
var ent = hook.GetParam<CBaseEntity>(0);

return HookResult.Changed;
}, HookMode.Pre);
*/
}
var playerWhoWasDamaged = player(ent);

if (playerWhoWasDamaged == null) return HookResult.Continue;

var info = hook.GetParam<CTakeDamageInfo>(1);

CCSPlayerController? attacker = null;

if (info.Attacker.Value != null)
{
var playerWhoAttacked = info.Attacker.Value.As<CCSPlayerPawn>();

attacker = playerWhoAttacked.Controller.Value.As<CCSPlayerController>();

}

if (info.BitsDamageType != DamageTypes_t.DMG_SHOCK) return HookResult.Continue;
if (attacker == null) return HookResult.Continue;

info.Damage = 0;

var targetRole = _roleService.GetPlayer(playerWhoWasDamaged);

Server.NextFrame(() =>
{
attacker.PrintToChat(
StringUtils.FormatTTT(
$"You tased player {playerWhoWasDamaged.PlayerName} they are a {targetRole.PlayerRole().FormatRoleFull()}"));
});

//_roundService.GetLogsService().AddLog(new MiscAction("tased player " + targetRole.PlayerRole().FormatStringFullAfter(playerWhoWasDamaged.PlayerName), attacker));

return HookResult.Stop;
}

private void OnPlayerUse(CCSPlayerController player)
{
Expand Down Expand Up @@ -92,4 +116,38 @@ private void IdentifyBody(CCSPlayerController caller)

Server.NextFrame(() => { Server.PrintToChatAll(message); });
}

private static CCSPlayerController? player(CEntityInstance? instance)
{
if (instance == null)
{
return null;
}

if (instance.DesignerName != "player")
{
return null;
}

// grab the pawn index
int player_index = (int)instance.Index;

// grab player controller from pawn
CCSPlayerPawn player_pawn = Utilities.GetEntityFromIndex<CCSPlayerPawn>(player_index);

// pawn valid
if (player_pawn == null || !player_pawn.IsValid)
{
return null;
}

// controller valid
if (player_pawn.OriginalController == null || !player_pawn.OriginalController.IsValid)
{
return null;
}

// any further validity is up to the caller
return player_pawn.OriginalController.Value;
}
}
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);
}
}
84 changes: 0 additions & 84 deletions mod/TTT.Roles/Helper/InfoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public InfoManager(RoleManager roleService, IRoundService manager, BasePlugin pl
{
_roleService = roleService;
_manager = manager;
plugin.RegisterListener<Listeners.OnTick>(OnTick);
plugin.AddTimer(0.3f, OnTickAll, TimerFlags.REPEAT);
plugin.AddTimer(0.1f, OnTickScoreboard, TimerFlags.REPEAT);

plugin.RegisterEventHandler<EventSpecTargetUpdated>(OnPlayerSpectateChange);
Expand Down Expand Up @@ -60,88 +58,6 @@ public void OnTickScoreboard()
}


public void OnTick()
{
foreach (var gamePlayer in _roleService.Players())
{
if (_manager.GetRoundStatus() != RoundStatus.Started) return;

var player = gamePlayer.Player();

if (player == null) continue;
if (!player.IsReal()) continue;

var playerRole = gamePlayer.PlayerRole();

if (playerRole == Role.Unassigned) continue;
if (gamePlayer.ShopOpen()) continue;

if (!player.PawnIsAlive && AdminManager.PlayerHasPermissions(player, "@css/kick"))
{
if (player.ObserverPawn.Value == null || !player.ObserverPawn.Value.IsValid) continue;
if (player.ObserverPawn.Value.ObserverServices?.ObserverTarget.Value is null) continue;
var target = player.ObserverPawn.Value.ObserverServices.ObserverTarget.Value?.As<CCSPlayerController>();
if (target == null)
{
Server.NextFrame(() =>
player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()}"));
}
else
{
Server.NextFrame(() => player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()} <br>"
+ $"<font class='fontsize=m' color='yellow'>{target.PlayerName}'s Role: {_roleService.GetRole(target).GetCenterRole()}"));
}

continue;
}

if (!_playerLookAtRole.TryGetValue(player, out var value))
{
Server.NextFrame(() =>
player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()}"));
continue;
}

if (!value.Item1.IsReal()) continue;

if (value.Item2 == playerRole || playerRole == Role.Traitor || value.Item2 == Role.Detective)
{
Server.NextFrame(() => player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()} <br>"
+ $"<font class='fontsize=m' color='yellow'>{value.Item1.PlayerName}'s Role: {value.Item2.GetCenterRole()}"));
}


if (playerRole != Role.Innocent && (value.Item2 != Role.Traitor || playerRole != Role.Detective)) continue;

Server.NextFrame(() => player.PrintToCenterHtml(
$"<font class='fontsize=m' color='yellow'>Your Role: {playerRole.GetCenterRole()} <br>"
+ $"<font class='fontsize=m' color='yellow'>{value.Item1.PlayerName}'s Role: {Role.Unassigned.GetCenterRole()}"));
}
}

public void OnTickAll()
{
var players = _roleService.GetPlayers().Keys;

_playerLookAtRole.Clear();

foreach (var player in players)
{
if (!player.IsReal()) continue;

var target = player.GetClientPlayerAimTarget();

if (target == null) continue;
if (!target.IsReal()) continue;

RegisterLookAtRole(player, new Tuple<CCSPlayerController, Role>(target, _roleService.GetRole(target)));
}
}

[GameEventHandler]
private HookResult OnPlayerSpectateChange(EventSpecTargetUpdated @event, GameEventInfo info)
{
Expand Down
Loading
Loading