From 5d5e0f2bd1fa4130e35ca68ffd91c0a7563a7ac3 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:03:48 +0100 Subject: [PATCH] 1.8d - Small changes - Fixed gloves command --- Commands.cs | 7 +- Events.cs | 12 +-- VERSION | 2 +- WeaponAction.cs | 165 ++++++++++++++++++++------------------- WeaponPaints.cs | 2 +- WeaponSynchronization.cs | 2 +- 6 files changed, 98 insertions(+), 92 deletions(-) diff --git a/Commands.cs b/Commands.cs index a1169de6..b29b1368 100644 --- a/Commands.cs +++ b/Commands.cs @@ -150,11 +150,12 @@ namespace WeaponPaints g_playersKnife[(int)player!.Index] = knifeKey; - if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE) - AddTimer(0.1f, () => RefreshWeapons(player), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); if (weaponSync != null) Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey)); + + if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE) + AddTimer(0.2f, () => RefreshWeapons(player), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); } }; foreach (var knifePair in knivesOnly) @@ -266,7 +267,7 @@ namespace WeaponPaints }; if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE) - AddTimer(0.15f, () => RefreshWeapons(p), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + AddTimer(0.2f, () => RefreshWeapons(p), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); } }; diff --git a/Events.cs b/Events.cs index debf73ad..30b3b0a1 100644 --- a/Events.cs +++ b/Events.cs @@ -202,17 +202,17 @@ namespace WeaponPaints return HookResult.Continue; } - private void OnTick() { - foreach (var player in Utilities.GetPlayers()) + foreach (var player in Utilities.GetPlayers().Where(p => + p is not null && p.IsValid && + (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE && p.SteamID.ToString().Length == 17 + && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected && p.Team != CounterStrikeSharp.API.Modules.Utils.CsTeam.None + ) + ) { try { - if (player is null || !player.IsValid || !player.PawnIsAlive || player.SteamID.ToString().Length != 17 - || player.IsBot || player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected) - continue; - if (Config.Additional.ShowSkinImage && PlayerWeaponImage.ContainsKey(player.Slot) && !string.IsNullOrEmpty(PlayerWeaponImage[player.Slot])) { player.PrintToCenterHtml("".Replace("{PATH}", PlayerWeaponImage[player.Slot])); diff --git a/VERSION b/VERSION index fb557404..4295436d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.8c \ No newline at end of file +1.8d \ No newline at end of file diff --git a/WeaponAction.cs b/WeaponAction.cs index 1f5c84dd..7c1a3df3 100644 --- a/WeaponAction.cs +++ b/WeaponAction.cs @@ -202,117 +202,122 @@ namespace WeaponPaints { if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE) return; - if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return; var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons; + if (weapons == null || weapons.Count == 0) return; + if (player.Team == CsTeam.None || player.Team == CsTeam.Spectator) + return; - if (weapons != null && weapons.Count > 0) + //Dictionary weaponsWithAmmo = new Dictionary(); + Dictionary> weaponsWithAmmo = new Dictionary>(); + bool bomb = false; + bool defuser = player.PawnHasDefuser; + bool healthshot = false; + + // Iterate through each weapon + foreach (var weapon in weapons) { - //Dictionary weaponsWithAmmo = new Dictionary(); - Dictionary> weaponsWithAmmo = new Dictionary>(); - bool bomb = false; - bool defuser = player.PawnHasDefuser; - bool healthshot = false; + if (weapon == null || !weapon.IsValid || weapon.Value == null || + !weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_")) + continue; - // Iterate through each weapon - foreach (var weapon in weapons) + try { - if (weapon == null || !weapon.IsValid || weapon.Value == null || - !weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_")) - continue; + string? weaponByDefindex = null; - try + CCSWeaponBaseVData? weaponData = weapon.Value.As().VData; + + if (weaponData != null) { - string? weaponByDefindex = null; + if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_C4) + bomb = true; - CCSWeaponBaseVData? weaponData = weapon.Value.As().VData; + if (weaponData.Name.Equals("weapon_healtshot")) + healthshot = true; - if (weaponData != null) - { - if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_C4) - bomb = true; - - if (weaponData.Name.Equals("weapon_healtshot")) - healthshot = true; - - if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_GRENADES || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_UTILITY || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_BOOSTS) - { - int clip1 = weapon.Value.Clip1; - int reservedAmmo = weapon.Value.ReserveAmmo[0]; - - weaponsWithAmmo.Add(weapon.Value.DesignerName, new List<(int, int)>() { (clip1, reservedAmmo) }); - } - } - - if (!weapon.Value.DesignerName.Contains("knife") && WeaponDefindex.TryGetValue(weapon.Value.AttributeManager.Item.ItemDefinitionIndex, out weaponByDefindex) && weaponByDefindex != null) + if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_GRENADES || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_UTILITY || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_BOOSTS) { int clip1 = weapon.Value.Clip1; int reservedAmmo = weapon.Value.ReserveAmmo[0]; - if (!weaponsWithAmmo.ContainsKey(weaponByDefindex)) - { - weaponsWithAmmo.Add(weaponByDefindex, new List<(int, int)>()); - } - - weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo)); + weaponsWithAmmo.Add(weapon.Value.DesignerName, new List<(int, int)>() { (clip1, reservedAmmo) }); } } - catch (Exception ex) + + if (!weapon.Value.DesignerName.Contains("knife") + && + !weapon.Value.DesignerName.Contains("bayonet") + && + !weapon.Value.DesignerName.Contains("kukri") + && + WeaponDefindex.TryGetValue(weapon.Value.AttributeManager.Item.ItemDefinitionIndex, out weaponByDefindex) && weaponByDefindex != null) { - Logger.LogWarning(ex.Message); - continue; + int clip1 = weapon.Value.Clip1; + int reservedAmmo = weapon.Value.ReserveAmmo[0]; + + if (!weaponsWithAmmo.ContainsKey(weaponByDefindex)) + { + weaponsWithAmmo.Add(weaponByDefindex, new List<(int, int)>()); + } + + weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo)); + } + } + catch (Exception ex) + { + Logger.LogWarning(ex.Message); + continue; + } + } + + player.RemoveWeapons(); + AddTimer(0.3f, () => + { + GiveKnifeToPlayer(player); + + if (bomb) + player.GiveNamedItem("weapon_c4"); + + if (defuser) + { + var itemServ = player.PlayerPawn?.Value?.ItemServices; + if (itemServ != null) + { + var items = new CCSPlayer_ItemServices(itemServ.Handle); + items.HasDefuser = true; } } - player.RemoveWeapons(); - AddTimer(0.1f, () => + if (healthshot) + player.GiveNamedItem("weapon_healtshot"); + + foreach (var entry in weaponsWithAmmo) { - GiveKnifeToPlayer(player); - - if (bomb) - player.GiveNamedItem("weapon_c4"); - - if (defuser) + foreach (var ammo in entry.Value) { - var itemServ = player.PlayerPawn?.Value?.ItemServices; - if (itemServ != null) + var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(entry.Key)); + Server.NextFrame(() => { - var items = new CCSPlayer_ItemServices(itemServ.Handle); - items.HasDefuser = true; - } - } - - if (healthshot) - player.GiveNamedItem("weapon_healtshot"); - - foreach (var entry in weaponsWithAmmo) - { - foreach (var ammo in entry.Value) - { - var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(entry.Key)); - Server.NextFrame(() => + try { - try + if (newWeapon != null) { - if (newWeapon != null) - { - newWeapon.Clip1 = ammo.Item1; - newWeapon.ReserveAmmo[0] = ammo.Item2; - } + newWeapon.Clip1 = ammo.Item1; + newWeapon.ReserveAmmo[0] = ammo.Item2; } - catch (Exception ex) - { - Logger.LogWarning("Error setting weapon properties: " + ex.Message); - } - }); - } + } + catch (Exception ex) + { + Logger.LogWarning("Error setting weapon properties: " + ex.Message); + } + }); } - }, TimerFlags.STOP_ON_MAPCHANGE); - } + } + }, TimerFlags.STOP_ON_MAPCHANGE); } internal void RefreshKnife(CCSPlayerController? player) diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 01b871e0..31043403 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -158,7 +158,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig "Nereziel & daffyy"; public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based"; public override string ModuleName => "WeaponPaints"; - public override string ModuleVersion => "1.8c"; + public override string ModuleVersion => "1.8d"; public static WeaponPaintsConfig GetWeaponPaintsConfig() { diff --git a/WeaponSynchronization.cs b/WeaponSynchronization.cs index 13048b71..65c43bee 100644 --- a/WeaponSynchronization.cs +++ b/WeaponSynchronization.cs @@ -219,7 +219,7 @@ namespace WeaponPaints try { await using var connection = await _database.GetConnectionAsync(); - string query = "INSERT INTO `wp_player_gloves` (`steamid`, `weapon_defindex`) VALUES(@steamid, @weapon_defindex, @paint) ON DUPLICATE KEY UPDATE `weapon_defindex` = @weapon_defindex"; + string query = "INSERT INTO `wp_player_gloves` (`steamid`, `weapon_defindex`) VALUES(@steamid, @weapon_defindex) ON DUPLICATE KEY UPDATE `weapon_defindex` = @weapon_defindex"; await connection.ExecuteAsync(query, new { steamid = player.SteamId, weapon_defindex = defindex }); } catch (Exception e)