diff --git a/Config.cs b/Config.cs index 002fb52..b98737d 100644 --- a/Config.cs +++ b/Config.cs @@ -21,16 +21,16 @@ public interface IEndOfMapConfig public int MapsToShow { get; set; } public bool ChangeMapImmediatly { get; set; } public int VoteDuration { get; set; } - public int VotePercentage { get; set; } + public bool HudMenu { get; set; } } - public class EndOfMapConfig : IVoteConfig, IEndOfMapConfig + public class EndOfMapConfig : IEndOfMapConfig { public bool Enabled { get; set; } = true; public int MapsToShow { get; set; } = 6; + public bool HudMenu { get; set; } = true; public bool ChangeMapImmediatly { get; set; } = false; public int VoteDuration { get; set; } = 30; - public int VotePercentage { get; set; } = 60; } public class RtvConfig : ICommandConfig, IVoteConfig, IEndOfMapConfig @@ -43,6 +43,7 @@ public class RtvConfig : ICommandConfig, IVoteConfig, IEndOfMapConfig public int MapsToShow { get; set; } = 6; public int VoteDuration { get; set; } = 30; public int VotePercentage { get; set; } = 60; + public bool HudMenu { get; set; } = true; } public class VotemapConfig : ICommandConfig, IVoteConfig @@ -58,7 +59,7 @@ public class VotemapConfig : ICommandConfig, IVoteConfig public class Config : IBasePluginConfig { - public int Version { get; set; } = 6; + public int Version { get; set; } = 7; public RtvConfig Rtv { get; set; } = new(); public VotemapConfig Votemap { get; set; } = new(); public EndOfMapConfig EndOfMapVote { get; set; } = new(); diff --git a/Core/ChangeMapManager.cs b/Core/ChangeMapManager.cs index 732f13a..9479115 100644 --- a/Core/ChangeMapManager.cs +++ b/Core/ChangeMapManager.cs @@ -1,7 +1,6 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Core; -using System.Numerics; namespace cs2_rockthevote { @@ -84,7 +83,10 @@ public void OnLoad(Plugin plugin) { if (_pluginState.MapChangeScheduled) { - ChangeNextMap(true); + _plugin.AddTimer(3.0F, () => + { + ChangeNextMap(true); + }); } return HookResult.Continue; }); diff --git a/Core/EndMapVoteManager.cs b/Core/EndMapVoteManager.cs index d88f4e9..7e5615b 100644 --- a/Core/EndMapVoteManager.cs +++ b/Core/EndMapVoteManager.cs @@ -27,6 +27,7 @@ namespace cs2_rockthevote public class EndMapVoteManager : IPluginDependency { + const int MAX_OPTIONS_HUD_MENU = 6; public EndMapVoteManager(MapLister mapLister, ChangeMapManager changeMapManager, NominationCommand nominationManager, StringLocalizer localizer, PluginState pluginState) { _mapLister = mapLister; @@ -105,10 +106,17 @@ public void VoteDisplayTick() int index = 1; StringBuilder stringBuilder = new(); stringBuilder.AppendFormat($"{_localizer.Localize("emv.hud.hud-timer", timeLeft)}"); - foreach (var kv in Votes.OrderByDescending(x => x.Value).Take(5)) - { - stringBuilder.AppendFormat($"
{index++} {kv.Key} ({kv.Value})"); - } + if(!_config!.HudMenu) + foreach (var kv in Votes.OrderByDescending(x => x.Value).Take(MAX_OPTIONS_HUD_MENU).Where(x => x.Value > 0)) + { + stringBuilder.AppendFormat($"
{kv.Key} ({kv.Value})"); + } + else + foreach (var kv in Votes.Take(MAX_OPTIONS_HUD_MENU)) + { + stringBuilder.AppendFormat($"
!{index++} {kv.Key} ({kv.Value})"); + } + foreach (CCSPlayerController player in ServerManager.ValidPlayers()) { player.PrintToCenterHtml(stringBuilder.ToString()); @@ -164,7 +172,10 @@ public void StartVote(IEndOfMapConfig config) Votes.Clear(); _pluginState.EofVoteHappening = true; _config = config; - var mapsToShow = _config!.MapsToShow == 0 ? 5 : _config!.MapsToShow; + int mapsToShow = _config!.MapsToShow == 0 ? MAX_OPTIONS_HUD_MENU : _config!.MapsToShow; + if (config.HudMenu) + mapsToShow = MAX_OPTIONS_HUD_MENU; + var mapsScrambled = Shuffle(new Random(), _mapLister.Maps!.Where(x => x != Server.MapName).ToList()); mapsEllected = _nominationManager.NominationWinners().Concat(mapsScrambled).Distinct().ToList(); @@ -173,7 +184,10 @@ public void StartVote(IEndOfMapConfig config) foreach (var map in mapsEllected.Take(mapsToShow)) { Votes[map] = 0; - menu.AddMenuOption(map, (player, option) => MapVoted(player, map)); + menu.AddMenuOption(map, (player, option) => { + MapVoted(player, map); + MenuManager.CloseActiveMenu(player); + }); } foreach (var player in ServerManager.ValidPlayers()) diff --git a/Plugin.cs b/Plugin.cs index fbc7015..a619e07 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -1,7 +1,6 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; -using CounterStrikeSharp.API.Core.Plugin; using Microsoft.Extensions.DependencyInjection; using static CounterStrikeSharp.API.Core.Listeners; @@ -21,7 +20,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) public partial class Plugin : BasePlugin, IPluginConfig { public override string ModuleName => "RockTheVote"; - public override string ModuleVersion => "1.3.0"; + public override string ModuleVersion => "1.4.0"; public override string ModuleAuthor => "abnerfs"; public override string ModuleDescription => "General purpose map voting plugin"; @@ -67,7 +66,7 @@ public HookResult OnChat(EventPlayerChat @event, GameEventInfo info) var player = Utilities.GetPlayerFromUserid(@event.Userid); var text = @event.Text.Trim().ToLower(); - if (@event.Text.Trim() == "rtv") + if (text == "rtv") { _rtvManager.CommandHandler(player); } @@ -93,7 +92,7 @@ public HookResult OnChat(EventPlayerChat @event, GameEventInfo info) public void OnConfigParsed(Config config) { Config = config; - if (Config.Version < 6) + if (Config.Version < 7) throw new Exception("Your config file is too old, please delete it from addons/counterstrikesharp/configs/plugins/RockTheVote and let the plugin recreate it on load"); _dependencyManager.OnConfigParsed(config); diff --git a/README.md b/README.md index 4c87109..99022bd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # CS2 Rock The Vote +![image](https://github.com/abnerfs/cs2-rockthevote/assets/14078661/a603d1b6-ba35-4d5a-b887-1b14058a8050) + General purpose map voting plugin, started as a simple RTV and now has more features ## RockTheVote @@ -43,18 +45,18 @@ Players can type `timeleft` to see how much time is left in the current map - Changes in the config file will require you to reload the plugin or restart the server (change the map won't work). ```json -// This configuration was automatically generated by CounterStrikeSharp for plugin 'RockTheVote', at 2024/02/15 10:33:07 { - "Version": 6, + "Version": 7, "Rtv": { "Enabled": true, "EnabledInWarmup": true, "MinPlayers": 0, "MinRounds": 0, - "ChangeMapImmediatly": false, + "ChangeMapImmediatly": true, "MapsToShow": 6, "VoteDuration": 30, - "VotePercentage": 60 + "VotePercentage": 60, + "HudMenu": true }, "Votemap": { "Enabled": true, @@ -65,11 +67,11 @@ Players can type `timeleft` to see how much time is left in the current map "MinRounds": 0 }, "EndOfMapVote": { - "Enabled": false, + "Enabled": true, "MapsToShow": 6, + "HudMenu": true, "ChangeMapImmediatly": false, - "VoteDuration": 30, - "VotePercentage": 60 + "VoteDuration": 30 } } ```