Refactor command system and add static skill support
This commit is contained in:
parent
e33975fe8b
commit
c73473f0ed
22 changed files with 509 additions and 156 deletions
|
|
@ -11,7 +11,7 @@ namespace jRandomSkills
|
|||
public class Aimbot : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.Aimbot;
|
||||
private static Dictionary<nint, int> hitGroups = new Dictionary<nint, int>();
|
||||
private static readonly Dictionary<nint, int> hitGroups = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
|
|
@ -27,8 +27,8 @@ namespace jRandomSkills
|
|||
if (param == null || param.Entity == null || param2 == null || param2.Attacker == null || param2.Attacker.Value == null)
|
||||
return HookResult.Continue;
|
||||
|
||||
CCSPlayerPawn attackerPawn = new CCSPlayerPawn(param2.Attacker.Value.Handle);
|
||||
CCSPlayerPawn victimPawn = new CCSPlayerPawn(param.Handle);
|
||||
CCSPlayerPawn attackerPawn = new(param2.Attacker.Value.Handle);
|
||||
CCSPlayerPawn victimPawn = new(param.Handle);
|
||||
|
||||
if (attackerPawn.DesignerName != "player" || victimPawn.DesignerName != "player")
|
||||
return HookResult.Continue;
|
||||
|
|
@ -64,11 +64,8 @@ namespace jRandomSkills
|
|||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
public class SkillConfig : Config.DefaultSkillInfo
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#ff0000", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#ff0000", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : base(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,9 +10,9 @@ namespace jRandomSkills
|
|||
public class BunnyHop : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.BunnyHop;
|
||||
private static float maxSpeed = Config.GetValue<float>(skillName, "maxSpeed");
|
||||
private static float bunnyHopVelocity = Config.GetValue<float>(skillName, "jumpVelocity");
|
||||
private static float jumpBoost = Config.GetValue<float>(skillName, "jumpBoost");
|
||||
private static readonly float maxSpeed = Config.GetValue<float>(skillName, "maxSpeed");
|
||||
private static readonly float bunnyHopVelocity = Config.GetValue<float>(skillName, "jumpVelocity");
|
||||
private static readonly float jumpBoost = Config.GetValue<float>(skillName, "jumpBoost");
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
|
|
@ -60,17 +60,11 @@ namespace jRandomSkills
|
|||
}
|
||||
}
|
||||
|
||||
public class SkillConfig : Config.DefaultSkillInfo
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#d1430a", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float maxSpeed = 500f, float jumpVelocity = 300f, float jumpBoost = 2f) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
public float MaxSpeed { get; set; }
|
||||
public float JumpVelocity { get; set; }
|
||||
public float JumpBoost { get; set; }
|
||||
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#d1430a", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float maxSpeed = 500f, float jumpVelocity = 300f, float jumpBoost = 2f) : base(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
MaxSpeed = maxSpeed;
|
||||
JumpVelocity = jumpVelocity;
|
||||
JumpBoost = jumpBoost;
|
||||
}
|
||||
public float MaxSpeed { get; set; } = maxSpeed;
|
||||
public float JumpVelocity { get; set; } = jumpVelocity;
|
||||
public float JumpBoost { get; set; } = jumpBoost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
using System.Drawing;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using jRandomSkills.src.player;
|
||||
using static CounterStrikeSharp.API.Core.Listeners;
|
||||
using static jRandomSkills.jRandomSkills;
|
||||
|
||||
namespace jRandomSkills
|
||||
|
|
@ -10,6 +12,8 @@ namespace jRandomSkills
|
|||
public class C4Camouflage : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.C4Camouflage;
|
||||
private static bool exists = false;
|
||||
private static readonly Dictionary<ulong, List<uint>> invisibleEntities = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
|
|
@ -77,10 +81,40 @@ namespace jRandomSkills
|
|||
}
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
Instance.RegisterEventHandler<EventRoundEnd>((@event, info) =>
|
||||
{
|
||||
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)
|
||||
DisableSkill(player);
|
||||
}
|
||||
Instance.RemoveListener<CheckTransmit>(CheckTransmit);
|
||||
exists = false;
|
||||
return HookResult.Continue;
|
||||
});
|
||||
}
|
||||
|
||||
public static void CheckTransmit([CastFrom(typeof(nint))] CCheckTransmitInfoList infoList)
|
||||
{
|
||||
foreach (var (info, player) in infoList)
|
||||
{
|
||||
if (player == null) continue;
|
||||
foreach ((var playerId, var itemList) in invisibleEntities)
|
||||
if (player.SteamID != playerId)
|
||||
foreach (var item in itemList)
|
||||
info.TransmitEntities.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
if (!exists)
|
||||
Instance.RegisterListener<CheckTransmit>(CheckTransmit);
|
||||
exists = true;
|
||||
|
||||
if (player == null || !player.IsValid) return;
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
|
||||
|
|
@ -100,6 +134,7 @@ namespace jRandomSkills
|
|||
{
|
||||
SetPlayerVisibility(player, true);
|
||||
SetWeaponVisibility(player, true);
|
||||
invisibleEntities.Remove(player.SteamID);
|
||||
}
|
||||
|
||||
private static void SetPlayerVisibility(CCSPlayerController player, bool enabled)
|
||||
|
|
@ -113,23 +148,32 @@ namespace jRandomSkills
|
|||
}
|
||||
}
|
||||
|
||||
private static void SetWeaponVisibility(CCSPlayerController player, bool enabled)
|
||||
private static void SetWeaponVisibility(CCSPlayerController player, bool visible)
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
if (playerPawn == null || !playerPawn.IsValid) return;
|
||||
var weaponServices = playerPawn.WeaponServices;
|
||||
if (weaponServices == null) return;
|
||||
var playerPawn = player.PlayerPawn.Value!;
|
||||
if (playerPawn.WeaponServices == null) return;
|
||||
|
||||
var color = Color.FromArgb(enabled ? 255 : 0, 255, 255, 255);
|
||||
foreach (var weapon in weaponServices.MyWeapons)
|
||||
invisibleEntities.Remove(player.SteamID);
|
||||
foreach (var weapon in playerPawn.WeaponServices.MyWeapons)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
{
|
||||
weapon.Value.Render = color;
|
||||
Utilities.SetStateChanged(weapon.Value, "CBaseModelEntity", "m_clrRender");
|
||||
if (!visible)
|
||||
{
|
||||
if (invisibleEntities.TryGetValue(player.SteamID, out var items))
|
||||
{
|
||||
if (!items.Contains(weapon.Index))
|
||||
items.Add(weapon.Index);
|
||||
}
|
||||
else
|
||||
invisibleEntities.Add(player.SteamID, [weapon.Index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (visible)
|
||||
invisibleEntities.Remove(player.SteamID);
|
||||
}
|
||||
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#00911f", CsTeam onlyTeam = CsTeam.Terrorist, bool needsTeammates = false) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using jRandomSkills.src.player;
|
|||
using static CounterStrikeSharp.API.Core.Listeners;
|
||||
using static jRandomSkills.jRandomSkills;
|
||||
using jRandomSkills.src.utils;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
|
||||
namespace jRandomSkills
|
||||
{
|
||||
|
|
@ -13,6 +14,7 @@ namespace jRandomSkills
|
|||
{
|
||||
private const Skills skillName = Skills.Chicken;
|
||||
private static bool roundEnd = false;
|
||||
private static bool exists = false;
|
||||
private static readonly string[] disabledWeapons =
|
||||
[
|
||||
"weapon_ak47", "weapon_m4a4", "weapon_m4a1", "weapon_m4a1_silencer",
|
||||
|
|
@ -57,6 +59,8 @@ namespace jRandomSkills
|
|||
DisableSkill(player);
|
||||
}
|
||||
roundEnd = true;
|
||||
Instance.RemoveListener<CheckTransmit>(CheckTransmit);
|
||||
exists = false;
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
|
|
@ -92,11 +96,26 @@ namespace jRandomSkills
|
|||
Instance.RegisterListener<OnTick>(OnTick);
|
||||
}
|
||||
|
||||
public static void CheckTransmit([CastFrom(typeof(nint))] CCheckTransmitInfoList infoList)
|
||||
{
|
||||
foreach (var (info, player) in infoList)
|
||||
{
|
||||
if (player == null) continue;
|
||||
if (chickens.TryGetValue(player, out var chicken))
|
||||
if (chicken != null && chicken.IsValid)
|
||||
info.TransmitEntities.Remove(chicken.Index);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
var playerPawn = player.PlayerPawn?.Value;
|
||||
if (playerPawn != null && playerPawn.IsValid)
|
||||
{
|
||||
if (!exists)
|
||||
Instance.RegisterListener<CheckTransmit>(CheckTransmit);
|
||||
exists = true;
|
||||
|
||||
playerPawn.VelocityModifier = 1.1f;
|
||||
|
||||
playerPawn.Health = 50;
|
||||
|
|
@ -136,11 +155,11 @@ namespace jRandomSkills
|
|||
SetWeaponAttack(player, false);
|
||||
}
|
||||
|
||||
foreach (var chicken in chickens)
|
||||
if (chickens.TryGetValue(player, out var chicken))
|
||||
{
|
||||
if (chicken.Value != null && chicken.Value.IsValid)
|
||||
chicken.Value.Remove();
|
||||
chickens.Remove(chicken.Key);
|
||||
if (chicken != null && chicken.IsValid)
|
||||
chicken.Remove();
|
||||
chickens.Remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace jRandomSkills
|
|||
{
|
||||
private const Skills skillName = Skills.Ghost;
|
||||
private static bool roundEnd = false;
|
||||
private static bool exists = false;
|
||||
private static readonly string[] disabledWeapons =
|
||||
[
|
||||
"weapon_deagle", "weapon_revolver", "weapon_glock", "weapon_usp_silencer",
|
||||
|
|
@ -27,7 +28,7 @@ namespace jRandomSkills
|
|||
"weapon_g3sg1", "weapon_nova", "weapon_xm1014", "weapon_mag7",
|
||||
"weapon_sawedoff", "weapon_m249", "weapon_negev"
|
||||
];
|
||||
private static readonly HashSet<uint> invisibleEntities = [];
|
||||
private static readonly Dictionary<ulong, List<uint>> invisibleEntities = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
|
|
@ -63,6 +64,8 @@ namespace jRandomSkills
|
|||
DisableSkill(player);
|
||||
}
|
||||
roundEnd = true;
|
||||
Instance.RemoveListener<CheckTransmit>(CheckTransmit);
|
||||
exists = false;
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
|
|
@ -86,7 +89,18 @@ namespace jRandomSkills
|
|||
|
||||
if (playerInfo?.Skill != skillName) return HookResult.Continue;
|
||||
SetWeaponVisibility(player!, false);
|
||||
SetWearablesVisibility(player!, false);
|
||||
SetWeaponAttack(player!, true);
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
Instance.RegisterEventHandler<EventItemEquip>((@event, info) =>
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (!Instance.IsPlayerValid(player)) return HookResult.Continue;
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player?.SteamID);
|
||||
|
||||
if (playerInfo?.Skill != skillName) return HookResult.Continue;
|
||||
SetWeaponVisibility(player!, false);
|
||||
SetWeaponAttack(player!, true);
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
|
@ -99,7 +113,6 @@ namespace jRandomSkills
|
|||
});
|
||||
|
||||
Instance.RegisterListener<OnTick>(OnTick);
|
||||
Instance.RegisterListener<CheckTransmit>(CheckTransmit);
|
||||
}
|
||||
|
||||
public static void CheckTransmit([CastFrom(typeof(nint))] CCheckTransmitInfoList infoList)
|
||||
|
|
@ -107,16 +120,21 @@ namespace jRandomSkills
|
|||
foreach (var (info, player) in infoList)
|
||||
{
|
||||
if (player == null) continue;
|
||||
foreach (var entity in invisibleEntities)
|
||||
info.TransmitEntities.Remove((int)entity);
|
||||
foreach ((var playerId, var itemList) in invisibleEntities)
|
||||
if (player.SteamID != playerId)
|
||||
foreach (var item in itemList)
|
||||
info.TransmitEntities.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
if (!exists)
|
||||
Instance.RegisterListener<CheckTransmit>(CheckTransmit);
|
||||
exists = true;
|
||||
|
||||
SetPlayerVisibility(player, false);
|
||||
SetWeaponVisibility(player, false);
|
||||
SetWearablesVisibility(player, false);
|
||||
SetWeaponAttack(player, true);
|
||||
}
|
||||
|
||||
|
|
@ -124,8 +142,8 @@ namespace jRandomSkills
|
|||
{
|
||||
SetPlayerVisibility(player, true);
|
||||
SetWeaponVisibility(player, true);
|
||||
SetWearablesVisibility(player, true);
|
||||
SetWeaponAttack(player, false);
|
||||
invisibleEntities.Remove(player.SteamID);
|
||||
}
|
||||
|
||||
private static void OnTick()
|
||||
|
|
@ -152,44 +170,39 @@ namespace jRandomSkills
|
|||
}
|
||||
}
|
||||
|
||||
private static void SetWearablesVisibility(CCSPlayerController player, bool visible)
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
var playerPawn = player.PlayerPawn.Value!;
|
||||
|
||||
var color = visible ? Color.FromArgb(255, 255, 255, 255) : Color.FromArgb(0, 255, 255, 255);
|
||||
var shadowStrength = visible ? 1.0f : 0.0f;
|
||||
|
||||
foreach (var item in playerPawn.MyWearables)
|
||||
{
|
||||
if (item != null && item.IsValid && item.Value != null && item.Value.IsValid)
|
||||
{
|
||||
Server.PrintToChatAll($"NAME: {item.Value.DesignerName}");
|
||||
item.Value.Render = color;
|
||||
item.Value.ShadowStrength = shadowStrength;
|
||||
Utilities.SetStateChanged(item.Value, "CBaseModelEntity", "m_clrRender");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetWeaponVisibility(CCSPlayerController player, bool visible)
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
var playerPawn = player.PlayerPawn.Value!;
|
||||
if (playerPawn.WeaponServices == null) return;
|
||||
|
||||
var color = visible ? Color.FromArgb(255, 255, 255, 255) : Color.FromArgb(0, 255, 255, 255);
|
||||
var shadowStrength = visible ? 1.0f : 0.0f;
|
||||
// var color = visible ? Color.FromArgb(255, 255, 255, 255) : Color.FromArgb(0, 255, 255, 255);
|
||||
// var shadowStrength = visible ? 1.0f : 0.0f;
|
||||
|
||||
invisibleEntities.Remove(player.SteamID);
|
||||
foreach (var weapon in playerPawn.WeaponServices.MyWeapons)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
{
|
||||
if (!visible)
|
||||
{
|
||||
if (invisibleEntities.TryGetValue(player.SteamID, out var items))
|
||||
{
|
||||
if (!items.Contains(weapon.Index))
|
||||
items.Add(weapon.Index);
|
||||
}
|
||||
else
|
||||
invisibleEntities.Add(player.SteamID, [weapon.Index]);
|
||||
}
|
||||
/*
|
||||
weapon.Value.Render = color;
|
||||
weapon.Value.ShadowStrength = shadowStrength;
|
||||
Utilities.SetStateChanged(weapon.Value, "CBaseModelEntity", "m_clrRender");
|
||||
Utilities.SetStateChanged(weapon.Value, "CBaseModelEntity", "m_clrRender");*/
|
||||
}
|
||||
}
|
||||
|
||||
if (visible)
|
||||
invisibleEntities.Remove(player.SteamID);
|
||||
}
|
||||
|
||||
private static void SetWeaponAttack(CCSPlayerController player, bool disableWeapon)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace jRandomSkills
|
|||
{
|
||||
private const Skills skillName = Skills.Glaz;
|
||||
private static bool exists = false;
|
||||
private static List<int> smokes = new List<int>();
|
||||
private readonly static List<int> smokes = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
|
|
@ -80,11 +80,8 @@ namespace jRandomSkills
|
|||
SkillUtils.TryGiveWeapon(player, CsItem.SmokeGrenade);
|
||||
}
|
||||
|
||||
public class SkillConfig : Config.DefaultSkillInfo
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#5d00ff", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#5d00ff", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false) : base(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -73,8 +73,9 @@ namespace jRandomSkills
|
|||
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE) continue;
|
||||
|
||||
var beams = step.Value;
|
||||
if (beams.Count == 0 || pawn.AbsOrigin == null) continue;
|
||||
Vector lastBeamVector = beams.LastOrDefault()?.EndPos ?? pawn.AbsOrigin;
|
||||
if (pawn.AbsOrigin == null) continue;
|
||||
Vector lastBeamVector = beams.Count > 0
|
||||
? beams.LastOrDefault()!.EndPos : pawn.AbsOrigin;
|
||||
|
||||
var newBeam = CreateBeamStep(step.Key.Team, lastBeamVector, pawn.AbsOrigin);
|
||||
if (newBeam != null)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Drawing;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using jRandomSkills.src.player;
|
||||
using static CounterStrikeSharp.API.Core.Listeners;
|
||||
|
|
@ -11,15 +12,36 @@ namespace jRandomSkills
|
|||
public class Ninja : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.Ninja;
|
||||
private static bool exists = false;
|
||||
private static readonly float idlePercentInvisibility = Config.GetValue<float>(skillName, "idlePercentInvisibility");
|
||||
private static readonly float duckPercentInvisibility = Config.GetValue<float>(skillName, "duckPercentInvisibility");
|
||||
private static readonly float knifePercentInvisibility = Config.GetValue<float>(skillName, "knifePercentInvisibility");
|
||||
private static readonly Dictionary<nint, float> invisibilityChanged = [];
|
||||
private static readonly Dictionary<ulong, List<uint>> invisibleEntities = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"));
|
||||
|
||||
Instance.RegisterEventHandler<EventRoundFreezeEnd>((@event, info) =>
|
||||
{
|
||||
Instance.AddTimer(0.1f, () =>
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
DisableSkill(player);
|
||||
if (!Instance.IsPlayerValid(player)) continue;
|
||||
var playerPawn = player.PlayerPawn?.Value;
|
||||
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (playerInfo?.Skill != skillName) continue;
|
||||
EnableSkill(player);
|
||||
}
|
||||
});
|
||||
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
Instance.RegisterEventHandler<EventRoundStart>((@event, info) =>
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
|
|
@ -51,9 +73,46 @@ namespace jRandomSkills
|
|||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
Instance.RegisterEventHandler<EventItemEquip>((@event, info) =>
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (!Instance.IsPlayerValid(player)) return HookResult.Continue;
|
||||
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player?.SteamID);
|
||||
|
||||
if (playerInfo?.Skill != skillName) return HookResult.Continue;
|
||||
UpdateNinja(player);
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
Instance.RegisterEventHandler<EventRoundEnd>((@event, info) =>
|
||||
{
|
||||
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)
|
||||
DisableSkill(player);
|
||||
}
|
||||
Instance.RemoveListener<CheckTransmit>(CheckTransmit);
|
||||
exists = false;
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
Instance.RegisterListener<OnTick>(OnTick);
|
||||
}
|
||||
|
||||
public static void CheckTransmit([CastFrom(typeof(nint))] CCheckTransmitInfoList infoList)
|
||||
{
|
||||
foreach (var (info, player) in infoList)
|
||||
{
|
||||
if (player == null) continue;
|
||||
foreach ((var playerId, var itemList) in invisibleEntities)
|
||||
if (player.SteamID != playerId)
|
||||
foreach (var item in itemList)
|
||||
info.TransmitEntities.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnTick()
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
|
|
@ -64,10 +123,18 @@ namespace jRandomSkills
|
|||
}
|
||||
}
|
||||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
if (!exists)
|
||||
Instance.RegisterListener<CheckTransmit>(CheckTransmit);
|
||||
exists = true;
|
||||
}
|
||||
|
||||
public static void DisableSkill(CCSPlayerController player)
|
||||
{
|
||||
SetPlayerVisibility(player, 0);
|
||||
SetWeaponVisibility(player, 0);
|
||||
invisibleEntities.Remove(player.SteamID);
|
||||
}
|
||||
|
||||
private static void UpdateNinja(CCSPlayerController? player)
|
||||
|
|
@ -92,13 +159,13 @@ namespace jRandomSkills
|
|||
if (!buttons.HasFlag(PlayerButtons.Moveleft) && !buttons.HasFlag(PlayerButtons.Moveright) && !buttons.HasFlag(PlayerButtons.Forward) && !buttons.HasFlag(PlayerButtons.Back) && flags.HasFlag(PlayerFlags.FL_ONGROUND))
|
||||
percentInvisibility += idlePercentInvisibility;
|
||||
|
||||
SetWeaponVisibility(player, percentInvisibility);
|
||||
if (invisibilityChanged.TryGetValue(player.Handle, out float oldInvisibility))
|
||||
if (percentInvisibility == oldInvisibility)
|
||||
return;
|
||||
|
||||
invisibilityChanged[player.Handle] = percentInvisibility;
|
||||
SetPlayerVisibility(player, percentInvisibility);
|
||||
SetWeaponVisibility(player, percentInvisibility);
|
||||
}
|
||||
|
||||
private static void SetPlayerVisibility(CCSPlayerController player, float percentInvisibility)
|
||||
|
|
@ -115,17 +182,25 @@ namespace jRandomSkills
|
|||
private static void SetWeaponVisibility(CCSPlayerController player, float percentInvisibility)
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
if (playerPawn == null || !playerPawn.IsValid || playerPawn.WeaponServices == null) return;
|
||||
var playerPawn = player.PlayerPawn.Value!;
|
||||
if (playerPawn.WeaponServices == null) return;
|
||||
|
||||
var color = Color.FromArgb(Math.Max(255 - (int)(255 * percentInvisibility * 2), 0), 255, 255, 255);
|
||||
|
||||
invisibleEntities.Remove(player.SteamID);
|
||||
if (color.A != 0) return;
|
||||
|
||||
foreach (var weapon in playerPawn.WeaponServices.MyWeapons)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
{
|
||||
weapon.Value.Render = color;
|
||||
Utilities.SetStateChanged(weapon.Value, "CBaseModelEntity", "m_clrRender");
|
||||
if (invisibleEntities.TryGetValue(player.SteamID, out var items))
|
||||
{
|
||||
if (!items.Contains(weapon.Index))
|
||||
items.Add(weapon.Index);
|
||||
}
|
||||
else
|
||||
invisibleEntities.Add(player.SteamID, [weapon.Index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace jRandomSkills
|
|||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"));
|
||||
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"), false);
|
||||
|
||||
Instance.RegisterListener<OnTick>(() =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue