Refactored command handling to improve player and skill lookup logic, replaced some list operations with direct queries, and updated method signatures for clarity and null safety. The vote system was reworked to support more robust vote tracking, cooldowns, and localized chat messages. Language files were updated to add new vote-related translations. Various code style and nullability improvements were made throughout the plugin.
112 lines
No EOL
4.7 KiB
C#
112 lines
No EOL
4.7 KiB
C#
using CounterStrikeSharp.API;
|
||
using CounterStrikeSharp.API.Core;
|
||
using CounterStrikeSharp.API.Modules.Utils;
|
||
using jRandomSkills.src.player;
|
||
using jRandomSkills.src.utils;
|
||
using static jRandomSkills.jRandomSkills;
|
||
|
||
namespace jRandomSkills
|
||
{
|
||
public class Jammer : ISkill
|
||
{
|
||
private const Skills skillName = Skills.Jammer;
|
||
private static readonly HashSet<CCSPlayerController> jammedPlayers = [];
|
||
|
||
public static void LoadSkill()
|
||
{
|
||
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"), false);
|
||
|
||
Instance.RegisterEventHandler<EventRoundFreezeEnd>((@event, info) =>
|
||
{
|
||
Instance.AddTimer(0.1f, () =>
|
||
{
|
||
foreach (var player in Utilities.GetPlayers())
|
||
{
|
||
if (!Instance.IsPlayerValid(player)) continue;
|
||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||
if (playerInfo?.Skill != skillName) continue;
|
||
EnableSkill(player);
|
||
}
|
||
});
|
||
|
||
return HookResult.Continue;
|
||
});
|
||
|
||
Instance.RegisterEventHandler<EventRoundEnd>((@event, info) =>
|
||
{
|
||
foreach (var player in jammedPlayers)
|
||
SetCrosshair(player, true);
|
||
jammedPlayers.Clear();
|
||
return HookResult.Continue;
|
||
});
|
||
}
|
||
|
||
public static void TypeSkill(CCSPlayerController player, string[] commands)
|
||
{
|
||
if (player == null || !player.IsValid || !player.PawnIsAlive) return;
|
||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||
if (playerInfo?.Skill != skillName) return;
|
||
|
||
if (playerInfo.SkillChance == 1)
|
||
{
|
||
player.PrintToChat($" {ChatColors.Red}{Localization.GetTranslation("areareaper_used_info")}");
|
||
return;
|
||
}
|
||
|
||
string enemyId = commands[0];
|
||
var enemy = Utilities.GetPlayers().FirstOrDefault(p => p.Team != player.Team && p.Index.ToString() == enemyId);
|
||
|
||
if (enemy == null)
|
||
{
|
||
player.PrintToChat($" {ChatColors.Red}" + Localization.GetTranslation("selectplayerskill_incorrect_enemy_index"));
|
||
return;
|
||
}
|
||
|
||
jammedPlayers.Add(enemy);
|
||
SetCrosshair(enemy, false);
|
||
playerInfo.SkillChance = 1;
|
||
player.PrintToChat($" {ChatColors.Green}" + Localization.GetTranslation("jammer_player_info", enemy.PlayerName));
|
||
enemy.PrintToChat($" {ChatColors.Red}" + Localization.GetTranslation("jammer_enemy_info"));
|
||
}
|
||
|
||
private static void SetCrosshair(CCSPlayerController player, bool enabled)
|
||
{
|
||
var pawn = player.PlayerPawn.Value;
|
||
if (pawn == null || !pawn.IsValid) return;
|
||
pawn.HideHUD = (uint)(enabled
|
||
? (pawn.HideHUD & ~(1 << 8))
|
||
: (pawn.HideHUD | (1 << 8)));
|
||
Utilities.SetStateChanged(pawn, "CBasePlayerPawn", "m_iHideHUD");
|
||
}
|
||
|
||
public static void EnableSkill(CCSPlayerController player)
|
||
{
|
||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||
if (playerInfo == null) return;
|
||
playerInfo.SkillChance = 0;
|
||
|
||
SkillUtils.PrintToChat(player, Localization.GetTranslation("jammer") + ":", false);
|
||
|
||
player.PrintToChat($" {ChatColors.Green}{Localization.GetTranslation("jammer_select_info")}");
|
||
var enemies = Utilities.GetPlayers().Where(p => p.Team != player.Team && p.IsValid && !p.IsBot).ToArray();
|
||
if (enemies.Length > 0)
|
||
{
|
||
foreach (var enemy in enemies)
|
||
player.PrintToChat($" {ChatColors.Green}⠀⠀⠀[{ChatColors.Red}{enemy.Index}{ChatColors.Green}] {enemy.PlayerName}");
|
||
}
|
||
else
|
||
player.PrintToChat($" {ChatColors.Red}⠀⠀⠀{Localization.GetTranslation("selectplayerskill_incorrect_enemy_index")}");
|
||
player.PrintToChat($" {ChatColors.Green}{Localization.GetTranslation("selectplayerskill_command")} {ChatColors.Red}index");
|
||
}
|
||
|
||
public static void DisableSkill(CCSPlayerController player)
|
||
{
|
||
SetCrosshair(player, true);
|
||
jammedPlayers.Remove(player);
|
||
}
|
||
|
||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#42f5a7", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||
{
|
||
}
|
||
}
|
||
} |