diff --git a/Config/Configs.cs b/Config/Configs.cs index c0b5f9e..6c3cffa 100644 --- a/Config/Configs.cs +++ b/Config/Configs.cs @@ -82,6 +82,8 @@ private static void SaveConfigData(ConfigData configData) public class ConfigData { + public int MinimumPlayersToEnableKnifePlugin { get; set; } + public bool CountBotsAsPlayers { get; set; } public bool EnableVoteTeamSideAfterWinning { get; set; } public bool FreezePlayersOnVoteStarted { get; set; } public bool BlockTeamChangeOnVotingAndKnifeRound { get; set; } @@ -116,6 +118,8 @@ public int GiveArmorOnKnifeRound public ConfigData() { + MinimumPlayersToEnableKnifePlugin = 6; + CountBotsAsPlayers = false; EnableVoteTeamSideAfterWinning = true; FreezePlayersOnVoteStarted = true; BlockTeamChangeOnVotingAndKnifeRound = true; diff --git a/Config/Globals.cs b/Config/Globals.cs index 65844a7..0649a19 100644 --- a/Config/Globals.cs +++ b/Config/Globals.cs @@ -8,7 +8,7 @@ public class Globals public static List VoteCountT = new(); public static Stopwatch Stopwatch = new Stopwatch(); - + public static bool DisableKnife = false; public static bool CTWINNER = false; public static bool TWINNER = false; public static float Timer = 0; diff --git a/Config/Helper.cs b/Config/Helper.cs index f68806b..9f85025 100644 --- a/Config/Helper.cs +++ b/Config/Helper.cs @@ -3,6 +3,7 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Utils; +using Knife_Round_GoldKingZ.Config; namespace Knife_Round_GoldKingZ; @@ -107,9 +108,20 @@ public static int GetTerroristCount() { return Utilities.GetPlayers().Count(p => p != null && p.IsValid && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected && p.TeamNum == (byte)CsTeam.Terrorist); } - public static int GetAllCount() + public static int GetPlayersCount(bool IncludeBots = false) { - return Utilities.GetPlayers().Count(p => p != null && p.IsValid && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected); + return Utilities.GetPlayers().Count(p => p != null && p.IsValid && p.Connected == PlayerConnectedState.PlayerConnected && (IncludeBots || (!p.IsBot && !p.IsHLTV))); + } + public static int GetPlayersNeeded() + { + if (Configs.GetConfigData().CountBotsAsPlayers) + { + return GetPlayersCount(true); + } + else + { + return GetPlayersCount(false); + } } public static void ClearVariables() { diff --git a/CounterStrikeSharp.API.dll b/CounterStrikeSharp.API.dll index 40fcecf..fbba57d 100644 Binary files a/CounterStrikeSharp.API.dll and b/CounterStrikeSharp.API.dll differ diff --git a/Knife-Round-GoldKingZ.cs b/Knife-Round-GoldKingZ.cs index 6a7aeeb..a6bc48d 100644 --- a/Knife-Round-GoldKingZ.cs +++ b/Knife-Round-GoldKingZ.cs @@ -16,7 +16,7 @@ namespace Knife_Round_GoldKingZ; public class KnifeRoundGoldKingZ : BasePlugin { public override string ModuleName => "Knife Round (Creates An Additional Round With Knifes After Warmup)"; - public override string ModuleVersion => "1.1.0"; + public override string ModuleVersion => "1.1.1"; public override string ModuleAuthor => "Gold KingZ"; public override string ModuleDescription => "https://github.com/oqyh"; internal static IStringLocalizer? Stringlocalizer; @@ -42,7 +42,7 @@ public override void Load(bool hotReload) public void OnTick() { - if(!Globals.PrepareKnifeRound) + if(!Globals.DisableKnife && !Globals.PrepareKnifeRound) { if(Globals.KnifeRoundStarted && Globals.KnifeModeStartMessage && !string.IsNullOrEmpty(Localizer["hud.message.kniferoundstarted"])) { @@ -141,7 +141,7 @@ public void OnTick() public HookResult OnEventRoundEnd(EventRoundEnd @event, GameEventInfo info) { - if(@event == null)return HookResult.Continue; + if(Globals.DisableKnife || @event == null)return HookResult.Continue; if(Globals.KnifeRoundStarted) { @@ -200,7 +200,7 @@ public HookResult OnEventRoundEnd(EventRoundEnd @event, GameEventInfo info) public HookResult OnEventPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) { - if(@event == null)return HookResult.Continue; + if(Globals.DisableKnife || @event == null)return HookResult.Continue; var player = @event.Userid; if (player == null || !player.IsValid)return HookResult.Continue; @@ -254,17 +254,39 @@ public HookResult OnEventPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info } public HookResult OnEventRoundPrestart(EventRoundPrestart @event, GameEventInfo info) { - if(@event == null)return HookResult.Continue; + if(Globals.DisableKnife ||@event == null)return HookResult.Continue; + if(Globals.PrepareKnifeRound) { + if(Configs.GetConfigData().CountBotsAsPlayers && Helper.GetPlayersCount(true) < Configs.GetConfigData().MinimumPlayersToEnableKnifePlugin || !Configs.GetConfigData().CountBotsAsPlayers && Helper.GetPlayersCount(false) < Configs.GetConfigData().MinimumPlayersToEnableKnifePlugin) + { + string roundtime = Globals.mp_roundtime.ToString().Replace(',', '.'); + string roundtimeDefuse = Globals.mp_roundtime_defuse.ToString().Replace(',', '.'); + string teamIntroTime = Globals.mp_team_intro_time.ToString().Replace(',', '.'); + Server.ExecuteCommand($"mp_team_intro_time {teamIntroTime}; sv_buy_status_override -1; mp_roundtime {roundtime}; mp_roundtime_defuse {roundtimeDefuse}; mp_give_player_c4 1"); + if (Configs.GetConfigData().AllowAllTalkOnKnifeRound) + { + Server.ExecuteCommand($"sv_alltalk {Globals.sv_alltalk}; sv_deadtalk {Globals.sv_deadtalk}; sv_full_alltalk {Globals.sv_full_alltalk}; sv_talk_enemy_dead {Globals.sv_talk_enemy_dead}; sv_talk_enemy_living {Globals.sv_talk_enemy_living}"); + } + + Server.ExecuteCommand($"mp_restartgame 3"); + if (!string.IsNullOrEmpty(Localizer["chat.message.knife.ignored"])) + { + Helper.AdvancedPrintToServer(Localizer["chat.message.knife.ignored"], Helper.GetPlayersNeeded(), Configs.GetConfigData().MinimumPlayersToEnableKnifePlugin); + } + + Globals.DisableKnife = true; + return HookResult.Continue; + } Globals.RemoveWeapons = true; } return HookResult.Continue; } + public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { - if(@event == null)return HookResult.Continue; + if(Globals.DisableKnife || @event == null)return HookResult.Continue; if(Globals.PrepareKnifeRound) { @@ -331,7 +353,7 @@ private HookResult OnCommandJoinTeam(CCSPlayerController? player, CommandInfo co public HookResult OnEventPlayerChat(EventPlayerChat @event, GameEventInfo info) { - if(!Configs.GetConfigData().EnableVoteTeamSideAfterWinning || @event == null)return HookResult.Continue; + if(Globals.DisableKnife || !Configs.GetConfigData().EnableVoteTeamSideAfterWinning || @event == null)return HookResult.Continue; var eventplayer = @event.Userid; var eventmessage = @event.Text; @@ -452,7 +474,7 @@ public void ResetValuesAndExecuteCommands() Server.ExecuteCommand($"mp_team_intro_time {teamIntroTime}; sv_buy_status_override -1; mp_roundtime {roundtime}; mp_roundtime_defuse {roundtimeDefuse}; mp_give_player_c4 1"); if (Configs.GetConfigData().AllowAllTalkOnKnifeRound) { - Server.ExecuteCommand($"sv_alltalk {Globals.sv_alltalk}; sv_deadtalk {Globals.sv_deadtalk}; sv_full_alltalk {Globals.sv_full_alltalk}; sv_talk_enemy_dead {Globals.sv_talk_enemy_dead}; sv_talk_enemy_living {Globals.sv_talk_enemy_living};"); + Server.ExecuteCommand($"sv_alltalk {Globals.sv_alltalk}; sv_deadtalk {Globals.sv_deadtalk}; sv_full_alltalk {Globals.sv_full_alltalk}; sv_talk_enemy_dead {Globals.sv_talk_enemy_dead}; sv_talk_enemy_living {Globals.sv_talk_enemy_living}"); } int x = Configs.GetConfigData().AfterWinningRestartXTimes; diff --git a/lang/en.json b/lang/en.json index 1d5b0f7..d09d852 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,10 +1,11 @@ { - "chat.message.knife.start": "{green}Gold KingZ | Knife Round! {nextline} {green}Gold KingZ | Knife Round! {nextline} {green}Gold KingZ | Knife Round!", + "chat.message.knife.ignored": "{green}Gold KingZ | {grey}Knife Round Ignored Less Players ( {yellow}{0} Current {grey}/ {yellow}{1} Needed {grey})", + "chat.message.knife.start": "{green}Gold KingZ | Knife Round! {nextline} {green}Gold KingZ | Knife Round! {nextline} {green}Gold KingZ | Knife Round!", "chat.message.match.start": "{green}Gold KingZ | LIVE! {nextline} {green}Gold KingZ | LIVE! {nextline} {green}Gold KingZ | LIVE!", - - + + "hud.message.kniferoundstarted": " Knife Round

Winner Will Choose Team Side ", - "hud.message.winnerteam": "Vote Which Side To Pick
= Time Left To Vote: {0} Secs =
!ct To Go CT Side Team
!t To Go T Side Team
Votes On [{1} / {3}]
Votes On [{2} / {3}] ", + "hud.message.winnerteam": "Vote Which Side To Pick
= Time Left To Vote: {0} Secs =
!ct To Go CT Side Team
!t To Go T Side Team
Votes On [{1} / {3}]
Votes On [{2} / {3}] ", "hud.message.loseteam.ct": "Waitng For T's To Vote ", "hud.message.loseteam.t": "Waitng For CT's To Vote " } \ No newline at end of file