From ca2c3eb212b0e57ba8435101965d5be6d3c5be7e Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Wed, 15 Nov 2023 22:35:19 +0100 Subject: [PATCH 1/3] Update WeaponPaints.cs --- WeaponPaints.cs | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 5b2eda63..23f61431 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -74,7 +74,8 @@ public class WeaponPaints : BasePlugin, IPluginConfig RegisterListener(OnMapStart); RegisterEventHandler(OnPlayerSpawn); //RegisterEventHandler(OnRoundPreStart); - SetupMenus(); + if (Config.Additional.KnifeEnabled) + SetupMenus(); } public void OnConfigParsed(WeaponPaintsConfig config) { @@ -112,6 +113,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig } private void OnMapStart(string mapName) { + if (!Config.Additional.KnifeEnabled) return; // TODO // needed for now base.AddTimer(2.0f, () => { @@ -124,15 +126,17 @@ public class WeaponPaints : BasePlugin, IPluginConfig { int playerIndex = playerSlot + 1; Task.Run(async () => - { - await GetKnifeFromDatabase(playerIndex); + { + if (Config.Additional.KnifeEnabled) + await GetKnifeFromDatabase(playerIndex); await GetWeaponPaintsFromDatabase(playerIndex); }); } private void OnClientDisconnect(int playerSlot) { // TODO: Clean up after player - g_playersKnife.Remove(playerSlot+1); + if (Config.Additional.KnifeEnabled) + g_playersKnife.Remove(playerSlot+1); } private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) @@ -143,17 +147,22 @@ public class WeaponPaints : BasePlugin, IPluginConfig return HookResult.Continue; } - GiveKnifeToPlayer(player); + if (Config.Additional.KnifeEnabled) + GiveKnifeToPlayer(player); - // Check the best slot and set it. Weird solution but works xD - AddTimer(0.1f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3")); - AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2")); - AddTimer(0.35f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1")); + if (Config.Additional.SkinVisibilityFix) + { + // Check the best slot and set it. Weird solution but works xD + AddTimer(0.1f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3")); + AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2")); + AddTimer(0.35f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1")); + } return HookResult.Continue; } private void OnEntitySpawned(CEntityInstance entity) { + if (!Config.Additional.SkinEnabled) return; var designerName = entity.DesignerName; if (!weaponList.Contains(designerName)) return; bool isKnife = false; @@ -199,6 +208,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig } public void GiveKnifeToPlayer(CCSPlayerController player) { + if (!Config.Additional.KnifeEnabled) return; if (player.IsBot) { player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife"); @@ -219,6 +229,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig } public void RemoveKnifeFromPlayer(CCSPlayerController player) { + if (!Config.Additional.KnifeEnabled) return; if (!g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)) return; var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons; foreach (var weapon in weapons) @@ -234,8 +245,9 @@ public class WeaponPaints : BasePlugin, IPluginConfig } } } - public static bool PlayerHasKnife(CCSPlayerController player) + public bool PlayerHasKnife(CCSPlayerController player) { + if (!Config.Additional.KnifeEnabled) return true; var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons; foreach (var weapon in weapons) { @@ -251,6 +263,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig } private void SetupMenus() { + if (!Config.Additional.KnifeEnabled) return; var giveItemMenu = new ChatMenu(ReplaceTags(Config.Messages.KnifeMenuTitle)); var handleGive = (CCSPlayerController player, ChatMenuOption option) => { @@ -275,6 +288,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig [ConsoleCommand("css_wp", "refreshskins")] public void OnCommandRefresh(CCSPlayerController? player, CommandInfo command) { + if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return; if (player == null) return; string temp = ""; int playerIndex = (int)player.EntityIndex!.Value.Value; @@ -296,6 +310,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig [ConsoleCommand("css_ws", "weaponskins")] public void OnCommandWS(CCSPlayerController? player, CommandInfo command) { + if (!Config.Additional.SkinEnabled) return; if (player == null) return; string temp = ""; @@ -308,6 +323,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig temp = $"{Config.Prefix} {Config.Messages.SynchronizeMessageCommand}"; player.PrintToChat(ReplaceTags(temp)); } + if (!Config.Additional.KnifeEnabled) return; if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand)) { temp = $"{Config.Prefix} {Config.Messages.KnifeMessageCommand}"; player.PrintToChat(ReplaceTags(temp)); @@ -320,6 +336,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig } private async Task GetWeaponPaintsFromDatabase(int playerIndex) { + if (!Config.Additional.SkinEnabled) return; try { CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex); @@ -364,6 +381,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig } private async Task GetKnifeFromDatabase(int playerIndex) { + if (!Config.Additional.KnifeEnabled) return; try { CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex); @@ -395,6 +413,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig } private async Task SyncKnifeToDatabase(int playerIndex, string knife) { + if (!Config.Additional.KnifeEnabled) return; try { CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex); From 99fde6ec52cd601fd67fd6f71c77a569c6e6a4ff Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Wed, 15 Nov 2023 22:35:57 +0100 Subject: [PATCH 2/3] Update Config.cs --- Config.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Config.cs b/Config.cs index d190834d..5c146d0c 100644 --- a/Config.cs +++ b/Config.cs @@ -21,9 +21,24 @@ namespace WeaponPaints public string KnifeMenuTitle { get; set; } = "Knife Menu."; } + public class Additional + { + [JsonPropertyName("SkinVisibilityFix")] + public bool SkinVisibilityFix { get; set; } = true; + + [JsonPropertyName("KnifeEnabled")] + public bool KnifeEnabled { get; set; } = true; + + [JsonPropertyName("SkinEnabled")] + public bool SkinEnabled { get; set; } = true; + + [JsonPropertyName("CommandWpEnabled")] + public bool CommandWpEnabled { get; set; } = true; + } + public class WeaponPaintsConfig : BasePluginConfig { - public override int Version { get; set; } = 2; + public override int Version { get; set; } = 3; [JsonPropertyName("DatabaseHost")] public string DatabaseHost { get; set; } = ""; @@ -51,6 +66,9 @@ namespace WeaponPaints [JsonPropertyName("Messages")] public Messages Messages { get; set; } = new Messages(); + + [JsonPropertyName("Additional")] + public Additional Additional { get; set; } = new Additional(); } } From c4ad17a7edaf26e06dba8ebd9487a643a93a2c60 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Wed, 15 Nov 2023 22:46:42 +0100 Subject: [PATCH 3/3] MinimumApiVersion --- WeaponPaints.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 23f61431..38ce1768 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -1,5 +1,6 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes; using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Entities; @@ -13,6 +14,7 @@ using System.Reflection; namespace WeaponPaints; +[MinimumApiVersion(52)] public class WeaponPaints : BasePlugin, IPluginConfig { public override string ModuleName => "WeaponPaints";