diff --git a/Commands.cs b/Commands.cs index d1b3f033..78158223 100644 --- a/Commands.cs +++ b/Commands.cs @@ -22,9 +22,12 @@ namespace WeaponPaints IpAddress = player?.IpAddress?.Split(":")[0] }; - if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds)) + if (player == null || player.UserId == null) return; + + if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) || + DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow)) { - commandCooldown[playerIndex] = DateTime.UtcNow; + commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds); if (weaponSync != null) Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo)); if (Config.Additional.KnifeEnabled) @@ -145,11 +148,13 @@ namespace WeaponPaints AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) => { if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return; - int playerIndex = (int)player!.Index; - if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds)) + if (player == null || player.UserId == null) return; + + if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) || + DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow)) { - commandCooldown[playerIndex] = DateTime.UtcNow; + commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds); ChatMenus.OpenMenu(player, giveItemMenu); return; } @@ -271,11 +276,13 @@ namespace WeaponPaints AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) => { if (!Utility.IsPlayerValid(player)) return; - int playerIndex = (int)player!.Index; - if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length) + if (player == null || player.UserId == null) return; + + if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) || + DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow)) { - commandCooldown[playerIndex] = DateTime.UtcNow; + commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds); ChatMenus.OpenMenu(player, weaponSelectionMenu); return; } diff --git a/Events.cs b/Events.cs index c6707ec9..20b0a701 100644 --- a/Events.cs +++ b/Events.cs @@ -37,12 +37,16 @@ namespace WeaponPaints { CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot); - if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.UserId == null) return; if (Config.Additional.KnifeEnabled) g_playersKnife.Remove((int)player.Index); if (Config.Additional.SkinEnabled) gPlayerWeaponsInfo.Remove((int)player.Index); + if (commandsCooldown.ContainsKey((int)player.UserId)) + { + commandsCooldown.Remove((int)player.UserId); + } } private void OnEntityCreated(CEntityInstance entity) @@ -91,28 +95,22 @@ namespace WeaponPaints return HookResult.Continue; } + /* private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info) { if (@event.Defindex == 42 || @event.Defindex == 59) { - Server.PrintToChatAll("test1"); - CCSPlayerController? player = @event.Userid; if (player == null || !player.IsValid || !g_knifePickupCount.ContainsKey((int)player.Index) || player.IsBot || !g_playersKnife.ContainsKey((int)player.Index)) return HookResult.Continue; - Server.PrintToChatAll("test2"); - if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue; - Server.PrintToChatAll("test3"); - if (g_playersKnife.ContainsKey((int)player.Index) && g_playersKnife[(int)player.Index] != "weapon_knife") { - Server.PrintToChatAll("usuwam noz"); g_knifePickupCount[(int)player.Index]++; RemovePlayerKnife(player, true); @@ -123,6 +121,7 @@ namespace WeaponPaints } return HookResult.Continue; } + */ public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay) { @@ -145,15 +144,14 @@ namespace WeaponPaints if (g_playersKnife[(int)player.Index] != "weapon_knife") { g_knifePickupCount[(int)player.Index]++; - weapon.Remove(); - if (!PlayerHasKnife(player) && Config.Additional.GiveKnifeAfterRemove) + player.RemoveItemByDesignerName(weapon.DesignerName); + if (Config.Additional.GiveKnifeAfterRemove) AddTimer(0.2f, () => GiveKnifeToPlayer(player)); } return HookResult.Continue; } - private void OnMapStart(string mapName) { if (!Config.Additional.KnifeEnabled) return; @@ -236,7 +234,7 @@ namespace WeaponPaints return HookResult.Continue; } - if (Config.Additional.KnifeEnabled) + if (Config.Additional.KnifeEnabled && !PlayerHasKnife(player)) { g_knifePickupCount[(int)player.Index] = 0; AddTimer(0.1f, () => GiveKnifeToPlayer(player)); diff --git a/PlayerExtensions.cs b/PlayerExtensions.cs index 9fa41d0c..0e8198b7 100644 --- a/PlayerExtensions.cs +++ b/PlayerExtensions.cs @@ -7,6 +7,7 @@ public static class PlayerExtensions { public static void Print(this CCSPlayerController controller, string message) { + if (WeaponPaints._localizer == null) return; StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]); _message.Append(message); controller.PrintToChat(_message.ToString()); diff --git a/VERSION b/VERSION index c95270d1..98c19152 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3f \ No newline at end of file +1.3h \ No newline at end of file diff --git a/WeaponAction.cs b/WeaponAction.cs index 0ed06d9c..cbda2888 100644 --- a/WeaponAction.cs +++ b/WeaponAction.cs @@ -197,7 +197,7 @@ namespace WeaponPaints { if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet")) { - weapon.Value.Remove(); + player.RemoveItemByDesignerName(weapon.Value.DesignerName, true); GiveKnifeToPlayer(player); } else @@ -208,8 +208,8 @@ namespace WeaponPaints clip1 = weapon.Value.Clip1; reservedAmmo = weapon.Value.ReserveAmmo[0]; - weapon.Value.Remove(); string weaponByDefindex = weaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex]; + player.RemoveItemByDesignerName(weapon.Value.DesignerName, true); CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weaponByDefindex)); Server.NextFrame(() => diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 9eebcf74..debf64c4 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -81,7 +81,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig commandsCooldown = new Dictionary(); private string DatabaseConnectionString = string.Empty; private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null; public static Dictionary weaponDefindex { get; } = new Dictionary @@ -145,7 +145,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig "Nereziel & daffyy"; public override string ModuleDescription => "Skin and knife selector, standalone and web-based"; public override string ModuleName => "WeaponPaints"; - public override string ModuleVersion => "1.3g"; + public override string ModuleVersion => "1.3h"; public static WeaponPaintsConfig GetWeaponPaintsConfig() { diff --git a/WeaponPaints.csproj b/WeaponPaints.csproj index b7fd0686..b8fa2437 100644 --- a/WeaponPaints.csproj +++ b/WeaponPaints.csproj @@ -9,9 +9,9 @@ - + - +