Improve skill cooldowns and weapon handling logic

This commit is contained in:
Juzlus 2025-08-30 03:24:02 +02:00
parent 28a7d0048c
commit 1d9e70aeda
9 changed files with 38 additions and 14 deletions

View file

@ -9,7 +9,7 @@ namespace jRandomSkills
public class BladeMaster : ISkill
{
private const Skills skillName = Skills.BladeMaster;
private static string[] noReflectionWeapon = { "inferno", "flashbang", "smokegrenade", "decoy", "hegrenade", "knife" };
private static string[] noReflectionWeapon = { "inferno", "flashbang", "smokegrenade", "decoy", "hegrenade", "knife", "taser" };
private static float torseReflectionChance = Config.GetValue<float>(skillName, "torseReflectionChance") * 100;
private static float legReflectionChance = Config.GetValue<float>(skillName, "legReflectionChance") * 100;

View file

@ -12,6 +12,7 @@ namespace jRandomSkills
public class Chicken : ISkill
{
private const Skills skillName = Skills.Chicken;
private static bool roundEnd = false;
private static string[] disabledWeapons =
{
"weapon_ak47",
@ -48,12 +49,12 @@ namespace jRandomSkills
Instance.RegisterEventHandler<EventRoundFreezeEnd>((@event, info) =>
{
roundEnd = false;
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);
@ -73,7 +74,7 @@ namespace jRandomSkills
if (playerInfo?.Skill != skillName) continue;
DisableSkill(player);
}
roundEnd = true;
return HookResult.Continue;
});
@ -160,6 +161,7 @@ namespace jRandomSkills
private static void SetWeaponAttack(CCSPlayerController player, bool disableWeapon)
{
if (roundEnd) return;
foreach (var weapon in player.Pawn.Value.WeaponServices?.MyWeapons)
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
if (disabledWeapons.Contains(weapon?.Value?.DesignerName))

View file

@ -12,6 +12,7 @@ namespace jRandomSkills
public class Ghost : ISkill
{
private const Skills skillName = Skills.Ghost;
private static bool roundEnd = false;
private static string[] disabledWeapons =
{
"weapon_deagle",
@ -60,12 +61,12 @@ namespace jRandomSkills
Instance.RegisterEventHandler<EventRoundFreezeEnd>((@event, info) =>
{
roundEnd = false;
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)
EnableSkill(player);
@ -84,6 +85,7 @@ namespace jRandomSkills
if (playerInfo?.Skill == skillName)
DisableSkill(player);
}
roundEnd = true;
return HookResult.Continue;
});
@ -180,6 +182,7 @@ namespace jRandomSkills
private static void SetWeaponAttack(CCSPlayerController player, bool disableWeapon)
{
if (roundEnd) return;
foreach (var weapon in player.Pawn.Value.WeaponServices?.MyWeapons)
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
if (disabledWeapons.Contains(weapon?.Value?.DesignerName))

View file

@ -10,7 +10,7 @@ namespace jRandomSkills
public class Poison : ISkill
{
private const Skills skillName = Skills.Poison;
private static int cooldown = Config.GetValue<int>(skillName, "Cooldown");
private static float cooldown = Config.GetValue<float>(skillName, "Cooldown");
private static int healthToDamage = Config.GetValue<int>(skillName, "Damage");
private static HashSet<CCSPlayerController> poisonedPlayers = new HashSet<CCSPlayerController>();
@ -46,7 +46,7 @@ namespace jRandomSkills
private static void OnTick()
{
if (Server.TickCount % (64 * cooldown) != 0) return;
if (Server.TickCount % (int)(64 * cooldown) != 0) return;
foreach (var player in poisonedPlayers)
{
var pawn = player.PlayerPawn.Value;
@ -109,8 +109,8 @@ namespace jRandomSkills
public class SkillConfig : Config.DefaultSkillInfo
{
public int Damage { get; set; }
public int Cooldown { get; set; }
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#902eff", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, int cooldown = 2, int damage = 1) : base(skill, active, color, onlyTeam, needsTeammates)
public float Cooldown { get; set; }
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#902eff", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float cooldown = 1, int damage = 1) : base(skill, active, color, onlyTeam, needsTeammates)
{
Damage = damage;
Cooldown = cooldown;

View file

@ -51,10 +51,11 @@ namespace jRandomSkills
Instance.AddTimer(.2f, () => {
player.Respawn();
zombies.Add(player);
player.ExecuteClientCommand("slot3");
SetPlayerColor(pawn, false);
SkillUtils.AddHealth(pawn, zombieHealth - 100, zombieHealth);
pawn.Teleport(deadPosition, deadRotation);
player.ExecuteClientCommand("slot3");
Instance.AddTimer(1, () => player.ExecuteClientCommand("slot3"));
});
return HookResult.Continue;

View file

@ -9,7 +9,7 @@ namespace jRandomSkills
public class Regeneration : ISkill
{
private const Skills skillName = Skills.Regeneration;
private static int cooldown = Config.GetValue<int>(skillName, "cooldown");
private static float cooldown = Config.GetValue<float>(skillName, "cooldown");
private static int healthToAdd = Config.GetValue<int>(skillName, "healthToAdd");
public static void LoadSkill()
@ -20,7 +20,7 @@ namespace jRandomSkills
private static void OnTick()
{
if (Server.TickCount % (64 * cooldown) != 0) return;
if (Server.TickCount % (int)(64 * cooldown) != 0) return;
foreach (var player in Utilities.GetPlayers())
{
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
@ -35,8 +35,8 @@ namespace jRandomSkills
public class SkillConfig : Config.DefaultSkillInfo
{
public int HealthToAdd { get; set; }
public int Cooldown { get; set; }
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#ff462e", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, int healthToAdd = 1, int cooldown = 1) : base(skill, active, color, onlyTeam, needsTeammates)
public float Cooldown { get; set; }
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#ff462e", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, int healthToAdd = 1, float cooldown = .25f) : base(skill, active, color, onlyTeam, needsTeammates)
{
HealthToAdd = healthToAdd;
Cooldown = cooldown;

View file

@ -173,7 +173,8 @@ namespace jRandomSkills
{
List<string> playerWeapons = new List<string>();
foreach (var weapon in player.PlayerPawn.Value.WeaponServices.MyWeapons)
playerWeapons.Add(weapon?.Value?.DesignerName);
if (weapon.Value != null && weapon.Value.IsValid)
playerWeapons.Add(SkillUtils.GetDesignerName(weapon.Value));
return playerWeapons.Count == 0 ? null : playerWeapons.ToArray();
}

View file

@ -91,6 +91,23 @@ namespace jRandomSkills
Utilities.SetStateChanged(pawn, "CBaseEntity", "m_iMaxHealth");
}
public static string GetDesignerName(CBasePlayerWeapon weapon)
{
string designerName = weapon.DesignerName;
ushort index = weapon.AttributeManager.Item.ItemDefinitionIndex;
designerName = (designerName, index) switch
{
var (name, _) when name.Contains("bayonet") => "weapon_knife",
("weapon_m4a1", 60) => "weapon_m4a1_silencer",
("weapon_hkp2000", 61) => "weapon_usp_silencer",
("weapon_deagle", 64) => "weapon_revolver",
_ => designerName
};
return designerName;
}
public static void SetTeamScores(short ctScore, short tScore, RoundEndReason roundEndReason)
{
UpdateServerTeamScores(ctScore, tScore);