diff --git a/source/Deathmatch/Deathmatch.cs b/source/Deathmatch/Deathmatch.cs index 5530415..f3d809b 100644 --- a/source/Deathmatch/Deathmatch.cs +++ b/source/Deathmatch/Deathmatch.cs @@ -20,7 +20,7 @@ public partial class Deathmatch : BasePlugin, IPluginConfig { public override string ModuleName => "Deathmatch Core"; public override string ModuleAuthor => "Nocky"; - public override string ModuleVersion => "1.2.0"; + public override string ModuleVersion => "1.2.1"; public void OnConfigParsed(DeathmatchConfig config) { diff --git a/source/Deathmatch/Events.cs b/source/Deathmatch/Events.cs index bcef345..f96e82c 100644 --- a/source/Deathmatch/Events.cs +++ b/source/Deathmatch/Events.cs @@ -546,7 +546,7 @@ private HookResult OnWeaponCanAcquire(DynamicHook hook) if (IsPrimary) { - if (vdata.Name == playerData[player].PrimaryWeapon[ActiveCustomMode]) + if (playerData[player].PrimaryWeapon.TryGetValue(ActiveCustomMode, out var primaryWeapon) && vdata.Name == primaryWeapon) { player.PrintToChat($"{Localizer["Chat.Prefix"]} {Localizer["Chat.WeaponsIsAlreadySet", localizerWeaponName]}"); hook.SetReturn(AcquireResult.AlreadyOwned); @@ -564,7 +564,7 @@ private HookResult OnWeaponCanAcquire(DynamicHook hook) } else { - if (vdata.Name == playerData[player].SecondaryWeapon[ActiveCustomMode]) + if (playerData[player].SecondaryWeapon.TryGetValue(ActiveCustomMode, out var secondaryWeapon) && vdata.Name == secondaryWeapon) { player.PrintToChat($"{Localizer["Chat.Prefix"]} {Localizer["Chat.WeaponsIsAlreadySet", localizerWeaponName]}"); hook.SetReturn(AcquireResult.AlreadyOwned); diff --git a/source/Deathmatch/Functions/Players.cs b/source/Deathmatch/Functions/Players.cs index 4d9f933..101a031 100644 --- a/source/Deathmatch/Functions/Players.cs +++ b/source/Deathmatch/Functions/Players.cs @@ -95,7 +95,7 @@ public void SetupPlayerWeapons(CCSPlayerController player, string weaponName, Co if (ActiveMode.PrimaryWeapons.Contains(weaponName)) { string localizerWeaponName = Localizer[weaponName]; - if (weaponName == playerData[player].PrimaryWeapon[ActiveCustomMode]) + if (playerData[player].PrimaryWeapon.TryGetValue(ActiveCustomMode, out var weapon) && weaponName == weapon) { if (!string.IsNullOrEmpty(Config.SoundSettings.CantEquipSound)) player.ExecuteClientCommand("play " + Config.SoundSettings.CantEquipSound); @@ -143,7 +143,7 @@ public void SetupPlayerWeapons(CCSPlayerController player, string weaponName, Co else if (ActiveMode.SecondaryWeapons.Contains(weaponName)) { string localizerWeaponName = Localizer[weaponName]; - if (weaponName == playerData[player].SecondaryWeapon[ActiveCustomMode]) + if (playerData[player].SecondaryWeapon.TryGetValue(ActiveCustomMode, out var weapon) && weaponName == weapon) { if (!string.IsNullOrEmpty(Config.SoundSettings.CantEquipSound)) player.ExecuteClientCommand("play " + Config.SoundSettings.CantEquipSound); @@ -243,28 +243,32 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode, bool gi if (ActiveMode.PrimaryWeapons.Count != 0) { - var PrimaryWeapon = playerData[player].PrimaryWeapon[ActiveCustomMode]; if (ActiveMode.RandomWeapons) { - PrimaryWeapon = GetRandomWeaponFromList(ActiveMode.PrimaryWeapons, ActiveMode, IsVIP, player.Team, true); - playerData[player].LastPrimaryWeapon = PrimaryWeapon; + var weapon = GetRandomWeaponFromList(ActiveMode.PrimaryWeapons, ActiveMode, IsVIP, player.Team, true); + playerData[player].LastPrimaryWeapon = weapon; + if (!string.IsNullOrEmpty(weapon)) + player.GiveNamedItem(weapon); + } + else if (playerData[player].PrimaryWeapon.TryGetValue(ActiveCustomMode, out var weapon) && !string.IsNullOrEmpty(weapon)) + { + player.GiveNamedItem(weapon); } - - if (!string.IsNullOrEmpty(PrimaryWeapon)) - player.GiveNamedItem(PrimaryWeapon); } if (ActiveMode.SecondaryWeapons.Count != 0) { - var SecondaryWeapon = playerData[player].SecondaryWeapon[ActiveCustomMode]; if (ActiveMode.RandomWeapons) { - SecondaryWeapon = GetRandomWeaponFromList(ActiveMode.SecondaryWeapons, ActiveMode, IsVIP, player.Team, false); - playerData[player].LastSecondaryWeapon = SecondaryWeapon; + var weapon = GetRandomWeaponFromList(ActiveMode.SecondaryWeapons, ActiveMode, IsVIP, player.Team, true); + playerData[player].LastPrimaryWeapon = weapon; + if (!string.IsNullOrEmpty(weapon)) + player.GiveNamedItem(weapon); + } + else if (playerData[player].SecondaryWeapon.TryGetValue(ActiveCustomMode, out var weapon) && !string.IsNullOrEmpty(weapon)) + { + player.GiveNamedItem(weapon); } - - if (!string.IsNullOrEmpty(SecondaryWeapon)) - player.GiveNamedItem(SecondaryWeapon); } if (giveKnife) diff --git a/source/Deathmatch/Functions/Weapons.cs b/source/Deathmatch/Functions/Weapons.cs index 49e0e0d..e995617 100644 --- a/source/Deathmatch/Functions/Weapons.cs +++ b/source/Deathmatch/Functions/Weapons.cs @@ -28,7 +28,7 @@ public bool CheckIsWeaponRestricted(string weaponName, bool isVIP, CsTeam team, return true; var playersList = Config.WeaponsRestrict.Global ? players : players.Where(p => p.Team == team).ToList(); - int matchingCount = playersList.Count(p => (bPrimary && playerData[p].PrimaryWeapon[ActiveCustomMode] == weaponName) || (!bPrimary && playerData[p].SecondaryWeapon[ActiveCustomMode] == weaponName)); + int matchingCount = playersList.Count(p => (bPrimary && playerData[p].PrimaryWeapon.TryGetValue(ActiveCustomMode, out var primary) && primary == weaponName) || (!bPrimary && playerData[p].SecondaryWeapon.TryGetValue(ActiveCustomMode, out var secondary) && secondary == weaponName)); return matchingCount >= restrictValue; }