Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to trigger a map vote externally #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Core/EndMapVoteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public EndMapVoteManager(MapLister mapLister, ChangeMapManager changeMapManager,
List<string> mapsEllected = new();

private IEndOfMapConfig? _config = null;
private IEndOfMapConfig? _configBackup = null;
private int _canVote = 0;
private Plugin? _plugin;

Expand All @@ -68,6 +69,13 @@ public void OnMapStart(string map)
timeLeft = 0;
mapsEllected.Clear();
KillTimer();

// Restore the config if it was changed by the server command
if (_configBackup is not null)
{
_config = _configBackup;
_configBackup = null;
}
}

public void MapVoted(CCSPlayerController player, string mapName)
Expand Down Expand Up @@ -179,6 +187,9 @@ public void StartVote(IEndOfMapConfig config)
Votes.Clear();
_voted.Clear();

// Backup the current config as if this is called via the server command, the config will be changed
_configBackup = _config;

_pluginState.EofVoteHappening = true;
_config = config;
int mapsToShow = _config!.MapsToShow == 0 ? MAX_OPTIONS_HUD_MENU : _config!.MapsToShow;
Expand Down
47 changes: 46 additions & 1 deletion Features/RockTheVoteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ public partial class Plugin
[ConsoleCommand("rtv", "Votes to rock the vote")]
public void OnRTV(CCSPlayerController? player, CommandInfo? command)
{
_rtvManager.CommandHandler(player!);
if (player is null) {
// Handle server command
_rtvManager.CommandServerHandler(player, command);
}
else
{
// Handle player command
_rtvManager.CommandHandler(player!);
}
}

[GameEventHandler(HookMode.Pre)]
Expand Down Expand Up @@ -46,6 +54,43 @@ public void OnMapStart(string map)
_voteManager!.OnMapStart(map);
}

public void CommandServerHandler(CCSPlayerController? player, CommandInfo command)
{
// Only handle command from server
if (player is not null)
return;

if (_pluginState.DisableCommands || !_config.Enabled)
{
Console.WriteLine(_localizer.LocalizeWithPrefix("general.validation.disabled"));
return;
}

int VoteDuration = _config.VoteDuration;
string args = command.ArgString.Trim();
if (!string.IsNullOrEmpty(args))
{
if (int.TryParse(args, out int duration))
{
VoteDuration = duration;
}
}

Console.WriteLine($"[RockTheVote] Starting vote with {VoteDuration} seconds duration");

RtvConfig config = new RtvConfig
{
Enabled = true,
EnabledInWarmup = true,
MinPlayers = 0,
MinRounds = 0,
ChangeMapImmediatly = true,
VoteDuration = VoteDuration,
VotePercentage = 1
};
_endmapVoteManager.StartVote(config);
}

public void CommandHandler(CCSPlayerController? player)
{
if (player is null)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ de_thera:3121217565
de_dust2
```

# Server commands

- rtv [seconds] - Trigger a map vote externally that will change the map immediately with an optional seconds parameter for voting duration (useful for gamemodes like GunGame)

# Limitations
- Plugins is still under development and a lot of functionality is still going to be added in the future.
- I usually test the new versions in an empty server with bots so it is hard to tell if everything is actually working, feel free to post any issues here or in the discord thread so I can fix them https://discord.com/channels/1160907911501991946/1176224458751627514