From a5787d95e03bd9d960d8660ddd80c000588f0c49 Mon Sep 17 00:00:00 2001 From: daffyyyy Date: Wed, 29 Nov 2023 11:56:07 +0100 Subject: [PATCH] improved refreshing skins --- Commands.cs | 2 ++ WeaponAction.cs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/Commands.cs b/Commands.cs index 524a3ca6..6db1c65e 100644 --- a/Commands.cs +++ b/Commands.cs @@ -248,6 +248,8 @@ namespace WeaponPaints RemoveKnifeFromPlayer(player); AddTimer(0.2f, () => GiveKnifeToPlayer(player)); */ + + RefreshWeapons(player); } if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand)) { diff --git a/WeaponAction.cs b/WeaponAction.cs index e003ca1c..4b9acba6 100644 --- a/WeaponAction.cs +++ b/WeaponAction.cs @@ -187,6 +187,52 @@ namespace WeaponPaints AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2")); AddTimer(0.38f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1")); } + + internal void RefreshWeapons(CCSPlayerController? player) + { + if (player == null || !player.IsValid || !player.PawnIsAlive) 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) + { + CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle); + //var dropWeapon = VirtualFunction.CreateVoid(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon")); + + foreach (var weapon in weapons) + { + if (weapon != null && weapon.IsValid && weapon.Value.IsValid) + { + if (!weapon.Value.EntityIndex.HasValue || !weapon.Value.DesignerName.Contains("weapon_")) continue; + //if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59) + if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet")) + { + weapon.Value.Remove(); + GiveKnifeToPlayer(player); + } + else + { + int clip1, reservedAmmo; + + clip1 = weapon.Value.Clip1; + reservedAmmo = weapon.Value.ReserveAmmo[0]; + + weapon.Value.Remove(); + CBasePlayerWeapon newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(weapon.Value.DesignerName)); + + Server.NextFrame(() => + { + newWeapon.Clip1 = clip1; + newWeapon.ReserveAmmo[0] = reservedAmmo; + }); + + } + } + } + RefreshSkins(player); + } + } + internal static bool PlayerHasKnife(CCSPlayerController? player) { if (!_config.Additional.KnifeEnabled) return false;