Skip to content

Commit

Permalink
Update v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NockyCZ committed Sep 25, 2024
1 parent 1229fa3 commit e38e18e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion source/Deathmatch/Deathmatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class Deathmatch : BasePlugin, IPluginConfig<DeathmatchConfig>
{
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)
{
Expand Down
4 changes: 2 additions & 2 deletions source/Deathmatch/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
32 changes: 18 additions & 14 deletions source/Deathmatch/Functions/Players.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion source/Deathmatch/Functions/Weapons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e38e18e

Please sign in to comment.