From 8e7a2a29232ef1fa351e41dbdb31663295af157b Mon Sep 17 00:00:00 2001 From: daffyyyy Date: Tue, 28 Nov 2023 23:44:28 +0100 Subject: [PATCH] fixxx --- Events.cs | 25 ++++++++++++------------- Utility.cs | 1 - WeaponAction.cs | 44 ++++++++++++++++++++++++++++---------------- WeaponInfo.cs | 8 +------- WeaponPaints.cs | 5 +---- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/Events.cs b/Events.cs index ebc145b6..9efda73c 100644 --- a/Events.cs +++ b/Events.cs @@ -1,14 +1,5 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Modules.Entities; -using CounterStrikeSharp.API.Core.Attributes; -using CounterStrikeSharp.API.Core.Attributes.Registration; -using CounterStrikeSharp.API.Modules.Utils; -using CounterStrikeSharp.API.Modules.Admin; -using CounterStrikeSharp.API.Modules.Commands; -using CounterStrikeSharp.API.Modules.Cvars; -using CounterStrikeSharp.API.Modules.Memory; -using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; namespace WeaponPaints { @@ -25,7 +16,6 @@ namespace WeaponPaints RegisterEventHandler(OnRoundStart, HookMode.Pre); RegisterEventHandler(OnEventItemPurchasePost); RegisterEventHandler(OnItemPickup); - } private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info) @@ -59,8 +49,10 @@ namespace WeaponPaints { NativeAPI.IssueServerCommand("mp_t_default_melee \"\""); NativeAPI.IssueServerCommand("mp_ct_default_melee \"\""); + NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0"); }); } + /* private void OnClientAuthorized(int playerSlot, SteamID steamID) { int playerIndex = playerSlot + 1; @@ -72,6 +64,7 @@ namespace WeaponPaints await weaponSync.GetKnifeFromDatabase(playerIndex); }); } + */ private void OnClientDisconnect(int playerSlot) { CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot); @@ -110,6 +103,7 @@ namespace WeaponPaints { NativeAPI.IssueServerCommand("mp_t_default_melee \"\""); NativeAPI.IssueServerCommand("mp_ct_default_melee \"\""); + NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0"); return HookResult.Continue; } @@ -118,22 +112,27 @@ namespace WeaponPaints if (@event.Defindex == 42 || @event.Defindex == 59) { CCSPlayerController? player = @event.Userid; - if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.EntityIndex!.Value.Value] >= 1) return HookResult.Continue; + if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.EntityIndex!.Value.Value] >= 2) return HookResult.Continue; if (g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value) && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife") { g_knifePickupCount[(int)player.EntityIndex!.Value.Value]++; - RefreshPlayerKnife(player); + + RemovePlayerKnife(player, true); + AddTimer(0.3f, ()=> GiveKnifeToPlayer(player)); + + //RefreshPlayerKnife(player); /* if (!PlayerHasKnife(player)) GiveKnifeToPlayer(player); - */ + if (Config.Additional.SkinVisibilityFix) { AddTimer(0.25f, () => RefreshSkins(player)); } + */ } } return HookResult.Continue; diff --git a/Utility.cs b/Utility.cs index a847ca0c..3a824140 100644 --- a/Utility.cs +++ b/Utility.cs @@ -1,5 +1,4 @@ using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Utils; using Dapper; using MySqlConnector; diff --git a/WeaponAction.cs b/WeaponAction.cs index ffefd9ef..c004152c 100644 --- a/WeaponAction.cs +++ b/WeaponAction.cs @@ -75,7 +75,7 @@ namespace WeaponPaints player.GiveNamedItem(defaultKnife); } } - internal void RemovePlayerKnife(CCSPlayerController? player) + internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false) { if (player == null || !player.IsValid || !player.PawnIsAlive) return; if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return; @@ -93,19 +93,26 @@ namespace WeaponPaints //if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59) if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet")) { - if (!weapon.Value.EntityIndex.HasValue) return; - int weaponEntityIndex = (int)weapon.Value.EntityIndex!.Value.Value; - NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"); - AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value)); - - AddTimer(1.0f, () => + if (!force) { - CEntityInstance? knife = Utilities.GetEntityFromIndex(weaponEntityIndex); - if (knife != null && knife.IsValid) + if (!weapon.Value.EntityIndex.HasValue) return; + int weaponEntityIndex = (int)weapon.Value.EntityIndex!.Value.Value; + NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"); + AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value)); + + AddTimer(1.0f, () => { - knife.Remove(); - } - }); + CEntityInstance? knife = Utilities.GetEntityFromIndex(weaponEntityIndex); + if (knife != null && knife.IsValid) + { + knife.Remove(); + } + }); + } + else + { + weapon.Value.Remove(); + } break; } @@ -151,13 +158,18 @@ namespace WeaponPaints } }); - AddTimer(2.5f, () => + Task.Delay(TimeSpan.FromSeconds(3.5)).ContinueWith(_ => { - CEntityInstance? knife = Utilities.GetEntityFromIndex(weaponEntityIndex); - if (knife != null && knife.IsValid && knife.EntityIndex.HasValue) + try { - knife.Remove(); + CEntityInstance? knife = Utilities.GetEntityFromIndex(weaponEntityIndex); + + if (knife != null && knife.IsValid && knife.Handle != -1 && knife.EntityIndex.HasValue) + { + knife.Remove(); + } } + catch (Exception) { } }); break; diff --git a/WeaponInfo.cs b/WeaponInfo.cs index 310c6e87..770ac38e 100644 --- a/WeaponInfo.cs +++ b/WeaponInfo.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WeaponPaints +namespace WeaponPaints { public class WeaponInfo { diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 82605b14..0417d2c3 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -1,14 +1,11 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; -using CounterStrikeSharp.API.Modules.Memory; -using CounterStrikeSharp.API.Modules.Utils; using CounterStrikeSharp.API.Modules.Cvars; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace WeaponPaints; -[MinimumApiVersion(61)] +[MinimumApiVersion(71)] public partial class WeaponPaints : BasePlugin, IPluginConfig { public override string ModuleName => "WeaponPaints";