From 16b80b1bb0bfb1b65d212fa2dac3cda903024ea2 Mon Sep 17 00:00:00 2001 From: NockyCZ <63038995+NockyCZ@users.noreply.github.com> Date: Wed, 1 May 2024 21:39:42 +0200 Subject: [PATCH] v1.1.3 --- source/Common/Globals.cs | 10 ++++--- source/Configs.cs | 11 ++++--- source/Deathmatch.cs | 57 ++++++++++++++++++++++++------------ source/Deathmatch.csproj | 2 +- source/Events.cs | 51 +++++++++++++++++++++----------- source/Functions/Commands.cs | 12 ++++---- source/Functions/Players.cs | 33 +++++++++++++++------ source/Functions/Spawns.cs | 4 +-- source/Functions/Weapons.cs | 10 ++++++- 9 files changed, 127 insertions(+), 63 deletions(-) diff --git a/source/Common/Globals.cs b/source/Common/Globals.cs index 1b2a17e..8f114c9 100644 --- a/source/Common/Globals.cs +++ b/source/Common/Globals.cs @@ -7,12 +7,14 @@ namespace Deathmatch public partial class Deathmatch { public DeathmatchConfig Config { get; set; } = null!; + public static int NextMode; + public static string ModeCenterMessage = ""; public static int ActiveCustomMode = 0; - public static int g_iModeTimer = 0; - public static int g_iRemainingTime = 500; - public static bool g_bIsActiveEditor = false; - public static bool g_bDefaultMapSpawnDisabled = false; + public static int ModeTimer = 0; + public static int RemainingTime = 500; + public static bool IsActiveEditor = false; public static bool IsCasualGamemode; + public static bool DefaultMapSpawnDisabled = false; public ModeData? ActiveMode; public MemoryFunctionWithReturn? CCSPlayer_CanAcquireFunc; public MemoryFunctionWithReturn? GetCSWeaponDataFromKeyFunc; diff --git a/source/Configs.cs b/source/Configs.cs index 17853ee..cbc989a 100644 --- a/source/Configs.cs +++ b/source/Configs.cs @@ -33,14 +33,17 @@ public class Gameplay [JsonPropertyName("Check Enemies Distance")] public bool CheckDistance { get; set; } = true; [JsonPropertyName("Distance From Enemies for Respawn")] public int DistanceRespawn { get; set; } = 500; [JsonPropertyName("Default Weapons")] public int DefaultModeWeapons { get; set; } = 2; + [JsonPropertyName("Contains Restricted Weapons As Default Weapons")] public bool RemoveRestrictedWeapons { get; set; } = true; [JsonPropertyName("Switch Weapons")] public bool SwitchWeapons { get; set; } = true; [JsonPropertyName("Allow Buymenu")] public bool AllowBuyMenu { get; set; } = true; [JsonPropertyName("Use Default Spawns")] public bool DefaultSpawns { get; set; } = false; [JsonPropertyName("Respawn Players After New Mode")] public bool RespawnPlayersAtNewMode { get; set; } = false; + [JsonPropertyName("Spawn Protection Color")] public string SpawnProtectionColor { get; set; } = "#000000"; } public class General { [JsonPropertyName("Hide Round Seconds")] public bool HideRoundSeconds { get; set; } = true; + [JsonPropertyName("Hide New Mode Countdown")] public bool HideModeRemainingTime { get; set; } = false; [JsonPropertyName("Block Radio Messages")] public bool BlockRadioMessage { get; set; } = true; [JsonPropertyName("Remove Breakable Entities")] public bool RemoveBreakableEntities { get; set; } = true; [JsonPropertyName("Remove Decals After Death")] public bool RemoveDecals { get; set; } = true; @@ -174,7 +177,7 @@ public class CustomModes OnlyHS = true, KnifeDamage = false, RandomWeapons = false, - CenterMessageText = "Only Headshot", + CenterMessageText = "Only Headshot
Next Mode: {NEXTMODE} in {REMAININGTIME}
", PrimaryWeapons = new List { "weapon_aug", "weapon_sg556", "weapon_xm1014", "weapon_ak47", "weapon_famas", "weapon_galilar", @@ -198,7 +201,7 @@ public class CustomModes OnlyHS = false, KnifeDamage = true, RandomWeapons = false, - CenterMessageText = "Only Deagle", + CenterMessageText = "Only Deagle
Next Mode: {NEXTMODE} in {REMAININGTIME}
", PrimaryWeapons = new List(), SecondaryWeapons = new List { "weapon_deagle" @@ -218,7 +221,7 @@ public class CustomModes OnlyHS = false, KnifeDamage = true, RandomWeapons = false, - CenterMessageText = "Only Pistols", + CenterMessageText = "Only Pistols
Next Mode: {NEXTMODE} in {REMAININGTIME}
", PrimaryWeapons = new List(), SecondaryWeapons = new List { "weapon_usp_silencer", "weapon_p250", "weapon_glock", @@ -238,7 +241,7 @@ public class CustomModes OnlyHS = false, KnifeDamage = true, RandomWeapons = true, - CenterMessageText = "Only SMG (Random Weapons)", + CenterMessageText = "Only SMG (Random Weapons)
Next Mode: {NEXTMODE} in {REMAININGTIME}
", PrimaryWeapons = new List { "weapon_p90", "weapon_bizon", "weapon_mp5sd", "weapon_mp7", "weapon_mp9", "weapon_mac10", diff --git a/source/Deathmatch.cs b/source/Deathmatch.cs index 99f93b7..48dee82 100644 --- a/source/Deathmatch.cs +++ b/source/Deathmatch.cs @@ -16,7 +16,7 @@ public partial class Deathmatch : BasePlugin, IPluginConfig { public override string ModuleName => "Deathmatch Core"; public override string ModuleAuthor => "Nocky"; - public override string ModuleVersion => "1.1.2"; + public override string ModuleVersion => "1.1.3"; public void OnConfigParsed(DeathmatchConfig config) { @@ -53,7 +53,7 @@ public override void Load(bool hotReload) RegisterListener(mapName => { - g_bDefaultMapSpawnDisabled = false; + DefaultMapSpawnDisabled = false; Server.NextFrame(() => { SetupCustomMode(Config.Gameplay.MapStartMode.ToString()); @@ -69,13 +69,22 @@ public override void Load(bool hotReload) { if (!GameRules().WarmupPeriod && ActiveMode != null) { - g_iModeTimer++; - g_iRemainingTime = ActiveMode.Interval - g_iModeTimer; - if (g_iRemainingTime == 0) + ModeTimer++; + RemainingTime = ActiveMode.Interval - ModeTimer; + + if (RemainingTime == 0) { - SetupCustomMode(GetModeType().ToString()); + SetupCustomMode(NextMode.ToString()); } + if (!string.IsNullOrEmpty(ActiveMode.CenterMessageText) && CustomModes.ContainsKey(NextMode.ToString())) + { + var time = TimeSpan.FromSeconds(RemainingTime); + var formattedTime = RemainingTime > 60 ? $"{time.Minutes}:{time.Seconds:D2}" : $"{time.Seconds}"; + var NextModeData = CustomModes[NextMode.ToString()]; + ModeCenterMessage = ActiveMode.CenterMessageText.Replace("{REMAININGTIME}", formattedTime); + ModeCenterMessage = ModeCenterMessage.Replace("{NEXTMODE}", NextModeData.Name); + } } }, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE); } @@ -100,7 +109,7 @@ public override void Load(bool hotReload) }); RegisterListener(() => { - if (g_bIsActiveEditor) + if (IsActiveEditor) { foreach (var p in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot && !p.IsHLTV && AdminManager.PlayerHasPermissions(p, "@css/root"))) { @@ -113,33 +122,32 @@ public override void Load(bool hotReload) { foreach (var p in Utilities.GetPlayers().Where(p => playerData.ContainsPlayer(p) && playerData[p].HudMessages)) { - if (ActiveMode != null && !string.IsNullOrEmpty(ActiveMode.CenterMessageText) && MenuManager.GetActiveMenu(p) == null) + if (ActiveMode != null && !string.IsNullOrEmpty(ModeCenterMessage) && MenuManager.GetActiveMenu(p) == null) { - p.PrintToCenterHtml($"{ActiveMode.CenterMessageText}"); + p.PrintToCenterHtml(ModeCenterMessage); } - if (g_iRemainingTime <= Config.Gameplay.NewModeCountdown && Config.Gameplay.NewModeCountdown > 0) + if (Config.General.HideModeRemainingTime && RemainingTime <= Config.Gameplay.NewModeCountdown && Config.Gameplay.NewModeCountdown > 0) { - if (g_iRemainingTime == 0) + if (RemainingTime == 0) { p.PrintToCenter($"{Localizer["Hud.NewModeStarted"]}"); } else { - p.PrintToCenter($"{Localizer["Hud.NewModeStarting", g_iRemainingTime]}"); + p.PrintToCenter($"{Localizer["Hud.NewModeStarting", RemainingTime]}"); } } } } }); } + public override void Unload(bool hotReload) { VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Unhook(OnTakeDamage, HookMode.Pre); CCSPlayer_CanAcquireFunc?.Unhook(OnWeaponCanAcquire, HookMode.Pre); - playerData.Clear(); - AllowedPrimaryWeaponsList.Clear(); - AllowedSecondaryWeaponsList.Clear(); } + public void SetupCustomMode(string modeId) { ActiveMode = CustomModes[modeId]; @@ -159,24 +167,32 @@ public void SetupCustomMode(string modeId) bNewmode = false; ActiveCustomMode = int.Parse(modeId); + NextMode = GetModeType(); + + if (CustomModes.ContainsKey(NextMode.ToString()) && !string.IsNullOrEmpty(ActiveMode.CenterMessageText)) + { + var NextModeData = CustomModes[NextMode.ToString()]; + ModeCenterMessage = ActiveMode.CenterMessageText.Replace("{NEXTMODE}", NextModeData.Name); + ModeCenterMessage = ModeCenterMessage.Replace("{REMAININGTIME}", RemainingTime.ToString()); + } SetupDeathmatchConfiguration(ActiveMode, bNewmode); } public void SetupDeathmatchConfiguration(ModeData mode, bool isNewMode) { - g_iModeTimer = 0; + ModeTimer = 0; if (isNewMode) Server.PrintToChatAll($"{Localizer["Chat.Prefix"]} {Localizer["Chat.NewModeStarted", mode.Name]}"); Server.ExecuteCommand($"mp_free_armor {mode.Armor};mp_damage_headshot_only {mode.OnlyHS};mp_ct_default_primary \"\";mp_t_default_primary \"\";mp_ct_default_secondary \"\";mp_t_default_secondary \"\""); - + if (mode.ExecuteCommands != null && mode.ExecuteCommands.Count > 0) { foreach (var cmd in mode.ExecuteCommands) Server.ExecuteCommand(cmd); } - + foreach (var p in Utilities.GetPlayers().Where(p => p != null && p.IsValid && p.PawnIsAlive)) { p.RemoveWeapons(); @@ -206,6 +222,7 @@ public void LoadCustomConfigFile() { var content = @" // Things you can customize and add your own cvars +sv_cheats 1 mp_timelimit 30 mp_maxrounds 0 sv_disable_radar 1 @@ -218,6 +235,7 @@ mp_death_drop_healthshot 0 mp_drop_grenade_enable 0 mp_death_drop_c4 0 mp_death_drop_taser 0 +sv_infinite_ammo 0 mp_defuser_allocation 0 mp_solid_teammates 1 mp_give_player_c4 0 @@ -226,13 +244,14 @@ mp_teamcashawards 0 cash_team_bonus_shorthanded 0 mp_autokick 0 mp_match_restart_delay 10 +mp_weapons_allow_zeus 1 //Do not change or delete!! mp_max_armor 0 mp_weapons_allow_typecount -1 mp_hostages_max 0 -mp_weapons_allow_zeus 0 mp_buy_allow_grenades 0 +sv_cheats 0 "; using (StreamWriter writer = new StreamWriter(path + "deathmatch.cfg")) diff --git a/source/Deathmatch.csproj b/source/Deathmatch.csproj index 0dd16a4..31d3afc 100644 --- a/source/Deathmatch.csproj +++ b/source/Deathmatch.csproj @@ -7,7 +7,7 @@ - + diff --git a/source/Events.cs b/source/Events.cs index 60b90e3..c472309 100644 --- a/source/Events.cs +++ b/source/Events.cs @@ -13,8 +13,8 @@ public partial class Deathmatch [GameEventHandler] public HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info) { - CCSPlayerController player = @event.Userid; - if (IsPlayerValid(player) && !playerData.ContainsPlayer(player)) + var player = @event.Userid; + if (IsPlayerValid(player!) && !playerData.ContainsPlayer(player!)) { bool IsVIP = AdminManager.PlayerHasPermissions(player, Config.PlayersSettings.VIPFlag); DeathmatchPlayerData setupPlayerData = new DeathmatchPlayerData @@ -32,7 +32,7 @@ public HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventIn OpenedMenu = 0, LastSpawn = null! }; - playerData[player] = setupPlayerData; + playerData[player!] = setupPlayerData; } return HookResult.Continue; } @@ -40,7 +40,7 @@ public HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventIn [GameEventHandler(HookMode.Post)] public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) { - CCSPlayerController player = @event.Userid; + var player = @event.Userid; if (player != null && player.IsValid) GivePlayerWeapons(player, false); @@ -52,9 +52,9 @@ public HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) if (@event.Userid == null || !@event.Userid.IsValid) return HookResult.Continue; - CCSPlayerController attacker = @event.Attacker; - CCSPlayerController player = @event.Userid; - if (ActiveMode != null && playerData.ContainsPlayer(attacker)) + var attacker = @event.Attacker; + var player = @event.Userid; + if (ActiveMode != null && attacker != null && playerData.ContainsPlayer(attacker)) { if (ActiveMode.OnlyHS) { @@ -80,8 +80,8 @@ public HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) [GameEventHandler(HookMode.Pre)] public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) { - CCSPlayerController player = @event.Userid; - CCSPlayerController attacker = @event.Attacker; + var player = @event.Userid; + var attacker = @event.Attacker; info.DontBroadcast = true; if (player == null || !player.IsValid) @@ -107,6 +107,9 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) PerformRespawn(player, player.Team, IsBot); }, TimerFlags.STOP_ON_MAPCHANGE); + if (attacker == null || !attacker.IsValid) + return HookResult.Continue; + if (attacker != player && playerData.ContainsPlayer(attacker) && attacker.PlayerPawn.Value != null) { playerData[attacker].KillStreak++; @@ -145,7 +148,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) attacker.PlayerPawn.Value.Health += giveHP; Utilities.SetStateChanged(attacker.PlayerPawn.Value, "CBaseEntity", "m_iHealth"); } - + if (ActiveMode != null && ActiveMode.Armor != 0) { string armor = ActiveMode.Armor == 1 ? "item_kevlar" : "item_assaultsuit"; @@ -168,7 +171,7 @@ public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) [GameEventHandler] public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) { - g_bIsActiveEditor = false; + IsActiveEditor = false; return HookResult.Continue; } private HookResult OnPlayerRadioMessage(CCSPlayerController? player, CommandInfo info) @@ -187,8 +190,15 @@ private HookResult OnTakeDamage(DynamicHook hook) { var damageInfo = hook.GetParam(1); - var player = new CCSPlayerController(new CCSPlayerPawn(hook.GetParam(0).Handle).Controller.Value!.Handle); - var attacker = new CCSPlayerController(new CCSPlayerPawn(damageInfo.Attacker.Value!.Handle).Controller.Value!.Handle); + var playerPawn = hook.GetParam(0); + CCSPlayerController? player = null; + if (playerPawn.Controller.Value != null) + player = playerPawn.Controller.Value.As(); + + var attackerHandle = damageInfo.Attacker; + CCSPlayerController? attacker = null; + if (attackerHandle.Value != null) + attacker = attackerHandle.Value.As(); if (player == null || !player.IsValid || attacker == null || !attacker.IsValid || ActiveMode == null) return HookResult.Continue; @@ -198,7 +208,7 @@ private HookResult OnTakeDamage(DynamicHook hook) damageInfo.Damage = 0; return HookResult.Continue; } - if (!ActiveMode.KnifeDamage && damageInfo.Ability.IsValid && (damageInfo.Ability.Value!.DesignerName.Contains("knife") || damageInfo.Ability.Value!.DesignerName.Contains("bayonet"))) + if (!ActiveMode.KnifeDamage && damageInfo.Ability.Value != null && damageInfo.Ability.IsValid && (damageInfo.Ability.Value.DesignerName.Contains("knife") || damageInfo.Ability.Value.DesignerName.Contains("bayonet"))) { attacker.PrintToCenter(Localizer["Hud.KnifeDamageIsDisabled"]); damageInfo.Damage = 0; @@ -208,14 +218,21 @@ private HookResult OnTakeDamage(DynamicHook hook) private HookResult OnWeaponCanAcquire(DynamicHook hook) { var vdata = GetCSWeaponDataFromKeyFunc?.Invoke(-1, hook.GetParam(1).ItemDefinitionIndex.ToString()); - var player = hook.GetParam(0).Pawn.Value!.Controller.Value!.As(); + var controller = hook.GetParam(0).Pawn.Value.Controller.Value; + + if (vdata == null) + return HookResult.Continue; + + CCSPlayerController? player = null; + if (controller != null) + player = controller.As(); if (player == null || !player.IsValid || !player.PawnIsAlive) return HookResult.Continue; if (hook.GetParam(2) == AcquireMethod.PickUp) { - if (!AllowedPrimaryWeaponsList.Contains(vdata!.Name!) && !AllowedSecondaryWeaponsList.Contains(vdata.Name)) + if (!AllowedPrimaryWeaponsList.Contains(vdata.Name) && !AllowedSecondaryWeaponsList.Contains(vdata.Name)) { if (vdata.Name.Contains("knife") || vdata.Name.Contains("bayonet")) return HookResult.Continue; @@ -241,7 +258,7 @@ private HookResult OnWeaponCanAcquire(DynamicHook hook) return HookResult.Stop; } - if (!AllowedPrimaryWeaponsList.Contains(vdata!.Name!) && !AllowedSecondaryWeaponsList.Contains(vdata.Name)) + if (!AllowedPrimaryWeaponsList.Contains(vdata.Name) && !AllowedSecondaryWeaponsList.Contains(vdata.Name)) { if (!player.IsBot) { diff --git a/source/Functions/Commands.cs b/source/Functions/Commands.cs index 11a36a5..6ac9b17 100644 --- a/source/Functions/Commands.cs +++ b/source/Functions/Commands.cs @@ -152,9 +152,9 @@ public void OnEditor_CMD(CCSPlayerController player, CommandInfo info) info.ReplyToCommand($"{Localizer["Chat.Prefix"]} The Spawn Editor cannot be used if you are using the default spawns!"); return; } - g_bIsActiveEditor = !g_bIsActiveEditor; - info.ReplyToCommand($"{Localizer["Chat.Prefix"]} Spawn Editor has been {ChatColors.Green}{(g_bIsActiveEditor ? "Enabled" : "Disabled")}"); - if (g_bIsActiveEditor) + IsActiveEditor = !IsActiveEditor; + info.ReplyToCommand($"{Localizer["Chat.Prefix"]} Spawn Editor has been {ChatColors.Green}{(IsActiveEditor ? "Enabled" : "Disabled")}"); + if (IsActiveEditor) { ShowAllSpawnPoints(); } @@ -170,7 +170,7 @@ public void OnEditor_CMD(CCSPlayerController player, CommandInfo info) [RequiresPermissions("@css/root")] public void OnAddSpawnCT_CMD(CCSPlayerController player, CommandInfo info) { - if (!g_bIsActiveEditor) + if (!IsActiveEditor) { info.ReplyToCommand($"{Localizer["Chat.Prefix"]} Spawn Editor is disabled!"); return; @@ -191,7 +191,7 @@ public void OnAddSpawnCT_CMD(CCSPlayerController player, CommandInfo info) [RequiresPermissions("@css/root")] public void OnAddSpawnT_CMD(CCSPlayerController player, CommandInfo info) { - if (!g_bIsActiveEditor) + if (!IsActiveEditor) { info.ReplyToCommand($"{Localizer["Chat.Prefix"]} Spawn Editor is disabled!"); return; @@ -212,7 +212,7 @@ public void OnAddSpawnT_CMD(CCSPlayerController player, CommandInfo info) [RequiresPermissions("@css/root")] public void OnRemoveSpawn_CMD(CCSPlayerController player, CommandInfo info) { - if (!g_bIsActiveEditor) + if (!IsActiveEditor) { info.ReplyToCommand($"{Localizer["Chat.Prefix"]} Spawn Editor is disabled!"); return; diff --git a/source/Functions/Players.cs b/source/Functions/Players.cs index 3636483..3e6ffe5 100644 --- a/source/Functions/Players.cs +++ b/source/Functions/Players.cs @@ -3,6 +3,8 @@ using CounterStrikeSharp.API.Modules.Timers; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Utils; +using System.Drawing; +using CounterStrikeSharp.API; namespace Deathmatch { @@ -182,7 +184,7 @@ public void SetupPlayerWeapons(CCSPlayerController player, string weaponName, Co } public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) { - if (playerData.ContainsPlayer(player)) + if (playerData.ContainsPlayer(player) && player.PlayerPawn.Value != null) { player.InGameMoneyServices!.Account = Config.Gameplay.AllowBuyMenu ? 16000 : 0; if (!bNewMode) @@ -190,10 +192,21 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) var timer = AdminManager.PlayerHasPermissions(player, Config.PlayersSettings.VIPFlag) ? Config.PlayersSettings.ProtectionTimeVIP : Config.PlayersSettings.ProtectionTime; if (timer > 0.1) { + if (string.IsNullOrEmpty(Config.Gameplay.SpawnProtectionColor)) + { + Color transparentColor = ColorTranslator.FromHtml(Config.Gameplay.SpawnProtectionColor); + player.PlayerPawn.Value.Render = transparentColor; + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseModelEntity", "m_clrRender"); + } playerData[player].SpawnProtection = true; AddTimer(timer, () => { playerData[player].SpawnProtection = false; + if (string.IsNullOrEmpty(Config.Gameplay.SpawnProtectionColor)) + { + player.PlayerPawn.Value.Render = Color.White; + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseModelEntity", "m_clrRender"); + } }, TimerFlags.STOP_ON_MAPCHANGE); } @@ -214,7 +227,7 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) string PrimaryWeapon = playerData[player].PrimaryWeapon; if (ActiveMode.RandomWeapons) { - PrimaryWeapon = GetRandomWeaponFromList(AllowedPrimaryWeaponsList); + PrimaryWeapon = GetRandomWeaponFromList(AllowedPrimaryWeaponsList, IsVIP, player.Team); } else if (string.IsNullOrEmpty(PrimaryWeapon) || !AllowedPrimaryWeaponsList.Contains(PrimaryWeapon)) { @@ -223,7 +236,7 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) 1 => AllowedPrimaryWeaponsList[0], _ => Config.Gameplay.DefaultModeWeapons switch { - 2 => GetRandomWeaponFromList(AllowedPrimaryWeaponsList), + 2 => GetRandomWeaponFromList(AllowedPrimaryWeaponsList, IsVIP, player.Team), 1 => AllowedPrimaryWeaponsList[0], _ => "" } @@ -240,7 +253,7 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) PrimaryWeapon = Config.Gameplay.DefaultModeWeapons switch { - 2 => GetRandomWeaponFromList(AllowedPrimaryWeaponsList), + 2 => GetRandomWeaponFromList(AllowedPrimaryWeaponsList, IsVIP, player.Team), 1 => AllowedPrimaryWeaponsList[0], _ => "" }; @@ -262,7 +275,7 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) string SecondaryWeapon = playerData[player].SecondaryWeapon; if (ActiveMode.RandomWeapons) { - SecondaryWeapon = GetRandomWeaponFromList(AllowedSecondaryWeaponsList); + SecondaryWeapon = GetRandomWeaponFromList(AllowedSecondaryWeaponsList, IsVIP, player.Team); } else if (string.IsNullOrEmpty(SecondaryWeapon) || !AllowedSecondaryWeaponsList.Contains(SecondaryWeapon)) { @@ -271,7 +284,7 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) 1 => AllowedSecondaryWeaponsList[0], _ => Config.Gameplay.DefaultModeWeapons switch { - 2 => GetRandomWeaponFromList(AllowedSecondaryWeaponsList), + 2 => GetRandomWeaponFromList(AllowedSecondaryWeaponsList, IsVIP, player.Team), 1 => AllowedSecondaryWeaponsList[0], _ => "" } @@ -289,7 +302,7 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) SecondaryWeapon = Config.Gameplay.DefaultModeWeapons switch { - 2 => GetRandomWeaponFromList(AllowedSecondaryWeaponsList), + 2 => GetRandomWeaponFromList(AllowedSecondaryWeaponsList, IsVIP, player.Team), 1 => AllowedSecondaryWeaponsList[0], _ => "" }; @@ -305,6 +318,8 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) player.GiveNamedItem(SecondaryWeapon); } } + + player.GiveNamedItem("weapon_knife"); if (ActiveMode.Utilities != null && ActiveMode.Utilities.Count() > 0) { foreach (var item in ActiveMode.Utilities) @@ -327,11 +342,11 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) if (AllowedPrimaryWeaponsList.Count != 0) { - player.GiveNamedItem(GetRandomWeaponFromList(AllowedPrimaryWeaponsList)); + player.GiveNamedItem(GetRandomWeaponFromList(AllowedPrimaryWeaponsList, false, player.Team)); } if (AllowedSecondaryWeaponsList.Count != 0) { - player.GiveNamedItem(GetRandomWeaponFromList(AllowedSecondaryWeaponsList)); + player.GiveNamedItem(GetRandomWeaponFromList(AllowedSecondaryWeaponsList, false, player.Team)); } }, TimerFlags.STOP_ON_MAPCHANGE); } diff --git a/source/Functions/Spawns.cs b/source/Functions/Spawns.cs index b728aeb..4bf476e 100644 --- a/source/Functions/Spawns.cs +++ b/source/Functions/Spawns.cs @@ -262,7 +262,7 @@ public void ShowAllSpawnPoints() } public static void RemoveMapDefaulSpawns() { - if (!g_bDefaultMapSpawnDisabled) + if (!DefaultMapSpawnDisabled) { if (IsCasualGamemode) { @@ -303,7 +303,7 @@ public static void RemoveMapDefaulSpawns() SendConsoleMessage($"[Deathmatch] Total {DMSpawns} default Spawns disabled!", ConsoleColor.Green); } - g_bDefaultMapSpawnDisabled = true; + DefaultMapSpawnDisabled = true; CreateCustomMapSpawns(); } } diff --git a/source/Functions/Weapons.cs b/source/Functions/Weapons.cs index ed86773..8ab0807 100644 --- a/source/Functions/Weapons.cs +++ b/source/Functions/Weapons.cs @@ -133,8 +133,16 @@ public int IsHaveWeaponFromSlot(CCSPlayerController player, int slot) return 3; } - private string GetRandomWeaponFromList(List weaponsList) + private string GetRandomWeaponFromList(List weaponsList, bool isVIP, CsTeam team) { + if (Config.Gameplay.RemoveRestrictedWeapons) + { + foreach (var weapon in weaponsList) + { + if (CheckIsWeaponRestricted(weapon, isVIP, team)) + weaponsList.Remove(weapon); + } + } Random rand = new Random(); int index = rand.Next(weaponsList.Count); return weaponsList[index];