Skip to content

Commit

Permalink
Add config to set number of maps in vote (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
abnerfs authored Jan 15, 2024
1 parent 07baa40 commit c8138a9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ namespace cs2_rockthevote
{
public class Config : IBasePluginConfig
{
public int Version { get; set; } = 2;
public int Version { get; set; } = 3;
public int RtvVotePercentage { get; set; } = 60;
public int RtvMinPlayers { get; set; } = 0;
public bool DisableVotesInWarmup { get; set; } = false;
public int MapsToShowInVote { get; set; } = 5;
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ Maps that will be used in RTV are located in addons/counterstrikesharp/configs/p
- Add minimum rounds to use commands.
- Add votemap.
- Translations support
- Add dont change option
- Nomination menu
13 changes: 8 additions & 5 deletions RockTheVote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace cs2_rockthevote
public class RockTheVote : BasePlugin, IPluginConfig<Config>
{
public override string ModuleName => "RockTheVote";
public override string ModuleVersion => "0.0.3";
public override string ModuleVersion => "0.0.4";
public override string ModuleAuthor => "abnerfs";
public override string ModuleDescription => "You know what it is, rtv";

Expand Down Expand Up @@ -162,7 +162,8 @@ public void OnRTV(CCSPlayerController? player, CommandInfo? command)
Server.PrintToChatAll("[RockTheVote] Number of votes reached, the vote for the next map will start");
var mapsScrambled = Shuffle(new Random(), Maps.Where(x => x != Server.MapName).ToList());
var maps = NominationManager.Votes().Concat(mapsScrambled).Distinct().ToList();
VoteManager manager = new(maps!, this, 30, ServerManager.ValidPlayerCount);
var mapsToShow = Config!.MapsToShowInVote == 0 ? 5 : Config!.MapsToShowInVote;
VoteManager manager = new(maps!, this, 30, ServerManager.ValidPlayerCount, mapsToShow);
manager.StartVote();
break;
}
Expand All @@ -172,23 +173,25 @@ public void OnRTV(CCSPlayerController? player, CommandInfo? command)
public HookResult OnChat(EventPlayerChat @event, GameEventInfo info)
{
var player = Utilities.GetPlayerFromUserid(@event.Userid);
if (!ValidateCommand(player))
return HookResult.Continue;

var text = @event.Text.Trim().ToLower();
if (@event.Text.Trim() == "rtv")
{
if (!ValidateCommand(player))
return HookResult.Continue;

OnRTV(player, null);
}
else if (text.StartsWith("nominate"))
{
if (!ValidateCommand(player))
return HookResult.Continue;

var split = text.Split("nominate");
var map = split.Length > 1 ? split[1].Trim() : "";
NominateHandler(player, map);
}


return HookResult.Continue;
}

Expand Down
15 changes: 9 additions & 6 deletions ServerManager.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using CounterStrikeSharp.API;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace cs2_rockthevote
{
public class ServerManager
{
public int ValidPlayerCount { get => Utilities.GetPlayers().Where(x => x.IsValid && !x.IsBot && !x.IsHLTV).Count(); }
public int ValidPlayerCount
{
get => Utilities.GetPlayers()
.Where(x => x.IsValid && !x.IsBot && !x.IsHLTV)
.Select(x => x.SteamID)
.Distinct()
.Count();
}
}
}
8 changes: 5 additions & 3 deletions VoteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ namespace cs2_rockthevote
{
public class VoteManager
{
public VoteManager(List<string> maps, RockTheVote plugin, int voteDuration, int canVoteCount)
public VoteManager(List<string> maps, RockTheVote plugin, int voteDuration, int canVoteCount, int mapstoShow)
{
Maps = maps;
Plugin = plugin;
Duration = voteDuration;
CanVoteCount = canVoteCount;
MapsToShow = mapstoShow;
}

private List<string> Maps { get; }
private RockTheVote Plugin { get; }
private int Duration { get; set; }
public int CanVoteCount { get; }
public int MapsToShow { get; }
private CounterStrikeSharp.API.Modules.Timers.Timer? Timer { get; set; }

Dictionary<string, int> Votes = new();
Expand Down Expand Up @@ -94,8 +96,8 @@ void EndVote()

public void StartVote()
{
ChatMenu menu = new("Vote for the next map:");
foreach(var map in Maps.Take(5))
ChatMenu menu = new($"Vote for the next map:");
foreach(var map in Maps.Take(MapsToShow))
{
Votes[map] = 0;
menu.AddMenuOption(map, (player, option) => MapVoted(player, map));
Expand Down

0 comments on commit c8138a9

Please sign in to comment.